def compute_acls(cls, fp, start_index=None, end_index=None): """Computes the autocorrleation length for all variable args for all walkers for all temps in the given file. If the returned acl is inf, will default to the number of requested iterations. Parameters ----------- fp : InferenceFile An open file handler to read the samples from. start_index : {None, int} The start index to compute the acl from. If None, will try to use the number of burn-in iterations in the file; otherwise, will start at the first sample. end_index : {None, int} The end index to compute the acl to. If None, will go to the end of the current iteration. Returns ------- WaveformArray An ntemps x nwalkers `WaveformArray` containing the acl for each walker and temp for each variable argument, with the variable arguments as fields. """ acls = {} if end_index is None: end_index = fp.niterations tidx = numpy.arange(fp.ntemps) widx = numpy.arange(fp.nwalkers) for param in fp.variable_args: these_acls = numpy.zeros((fp.ntemps, fp.nwalkers), dtype=int) for tk in tidx: for wi in widx: samples = cls.read_samples(fp, param, thin_start=start_index, thin_interval=1, thin_end=end_index, walkers=wi, temps=tk)[param] acl = autocorrelation.calculate_acl(samples) these_acls[tk, wi] = int(min(acl, samples.size)) acls[param] = these_acls return WaveformArray.from_kwargs(**acls)
def compute_acls(cls, fp, start_index=None, end_index=None): """Computes the autocorrleation length for all variable args for all walkers for all temps in the given file. If the returned acl is inf, will default to the number of requested iterations. Parameters ----------- fp : InferenceFile An open file handler to read the samples from. start_index : {None, int} The start index to compute the acl from. If None, will try to use the number of burn-in iterations in the file; otherwise, will start at the first sample. end_index : {None, int} The end index to compute the acl to. If None, will go to the end of the current iteration. Returns ------- WaveformArray An ntemps x nwalkers `WaveformArray` containing the acl for each walker and temp for each variable argument, with the variable arguments as fields. """ acls = {} if end_index is None: end_index = fp.niterations tidx = numpy.arange(fp.ntemps) widx = numpy.arange(fp.nwalkers) for param in fp.variable_args: these_acls = numpy.zeros((fp.ntemps, fp.nwalkers), dtype=int) for tk in tidx: for wi in widx: samples = cls.read_samples( fp, param, thin_start=start_index, thin_interval=1, thin_end=end_index, walkers=wi, temps=tk)[param] acl = autocorrelation.calculate_acl(samples) these_acls[tk, wi] = int(min(acl, samples.size)) acls[param] = these_acls return WaveformArray.from_kwargs(**acls)
def read_acls(fp): """Reads the acls of all the walker chains saved in the given file. Parameters ---------- fp : InferenceFile An open file handler to read the acls from. Returns ------- WaveformArray An nwalkers-long `WaveformArray` containing the acl for each walker and each variable argument, with the variable arguments as fields. """ group = fp.samples_group + '/{param}/walker{wi}' widx = numpy.arange(fp.nwalkers) arrays = {} for param in fp.variable_args: arrays[param] = numpy.array([ fp[group.format(param=param, wi=wi)].attrs['acl'] for wi in widx]) return WaveformArray.from_kwargs(**arrays)