Compute the effective sample size based on autocorrelation spectrum. This follows equation 16 from the L2HMC paper. Args: ac_spectrum: Autocorrelation spectrum Returns: The effective sample size
(ac_spectrum)
| 196 | |
| 197 | |
| 198 | def compute_ess(ac_spectrum): |
| 199 | """Compute the effective sample size based on autocorrelation spectrum. |
| 200 | |
| 201 | This follows equation 16 from the L2HMC paper. |
| 202 | |
| 203 | Args: |
| 204 | ac_spectrum: Autocorrelation spectrum |
| 205 | Returns: |
| 206 | The effective sample size |
| 207 | """ |
| 208 | # Cutoff from the first value less than 0.05 |
| 209 | cutoff = np.argmax(ac_spectrum[1:] < .05) |
| 210 | if cutoff == 0: |
| 211 | cutoff = len(ac_spectrum) |
| 212 | ess = 1. / (1. + 2. * np.sum(ac_spectrum[1:cutoff])) |
| 213 | return ess |
| 214 | |
| 215 | |
| 216 | if __name__ == "__main__": |