def samples(self): """Returns the samples in the chain as a FieldArray. If the sampling args are not the same as the model params, the returned samples will have both the sampling and the model params. The returned FieldArray has dimension [additional dimensions x] nwalkers x niterations. """ # chain is a [additional dimensions x] niterations x ndim array samples = self.chain sampling_params = self.sampling_params # convert to dictionary to apply boundary conditions samples = { param: samples[..., ii] for ii, param in enumerate(sampling_params) } samples = self.model.prior_distribution.apply_boundary_conditions( **samples) # now convert to field array samples = FieldArray.from_arrays( [samples[param] for param in sampling_params], names=sampling_params) # apply transforms to go to model params space if self.model.sampling_transforms is not None: samples = self.model.sampling_transforms.apply(samples, inverse=True) return samples
def prior_rvs(self, size=1, prior=None): """Returns random variates drawn from the prior. If the ``sampling_params`` are different from the ``variable_params``, the variates are transformed to the `sampling_params` parameter space before being returned. Parameters ---------- size : int, optional Number of random values to return for each parameter. Default is 1. prior : JointDistribution, optional Use the given prior to draw values rather than the saved prior. Returns ------- FieldArray A field array of the random values. """ # draw values from the prior if prior is None: prior = self.prior_distribution p0 = prior.rvs(size=size) # transform if necessary if self.sampling_transforms is not None: ptrans = self.sampling_transforms.apply(p0) # pull out the sampling args p0 = FieldArray.from_arrays( [ptrans[arg] for arg in self.sampling_params], names=self.sampling_params) return p0
def prior_rvs(self, size=1, prior=None): """Returns random variates drawn from the prior. If the ``sampling_args`` are different from the ``variable_args``, the variates are transformed to the `sampling_args` parameter space before being returned. Parameters ---------- size : int, optional Number of random values to return for each parameter. Default is 1. prior : JointDistribution, optional Use the given prior to draw values rather than the saved prior. Returns ------- FieldArray A field array of the random values. """ # draw values from the prior if prior is None: prior = self._prior p0 = prior.rvs(size=size) # transform if necessary if self._sampling_transforms is not None: ptrans = self.apply_sampling_transforms(p0) # pull out the sampling args p0 = FieldArray.from_arrays([ptrans[arg] for arg in self._sampling_args], names=self._sampling_args) return p0
def samples(self): """Returns the samples in the chain as a FieldArray. If the sampling args are not the same as the variable args, the returned samples will have both the sampling and the variable args. The returned FieldArray has dimension [additional dimensions x] nwalkers x niterations. """ # chain is a [additional dimensions x] niterations x ndim array samples = self.chain sampling_args = self.sampling_args # convert to dictionary to apply boundary conditions samples = { param: samples[..., ii] for ii, param in enumerate(sampling_args) } samples = self.likelihood_evaluator._prior.apply_boundary_conditions( **samples) # now convert to field array samples = FieldArray.from_arrays( [samples[param] for param in sampling_args], names=sampling_args) # apply transforms to go to variable args space return self.likelihood_evaluator.apply_sampling_transforms( samples, inverse=True)
def samples(self): """Returns the samples in the chain as a FieldArray. If the sampling args are not the same as the variable args, the returned samples will have both the sampling and the variable args. The returned FieldArray has dimension [additional dimensions x] nwalkers x niterations. """ # chain is a [additional dimensions x] niterations x ndim array samples = self.chain sampling_args = self.sampling_args # convert to dictionary to apply boundary conditions samples = {param: samples[...,ii] for ii,param in enumerate(sampling_args)} samples = self.likelihood_evaluator._prior.apply_boundary_conditions( **samples) # now convert to field array samples = FieldArray.from_arrays([samples[param] for param in sampling_args], names=sampling_args) # apply transforms to go to variable args space return self.likelihood_evaluator.apply_sampling_transforms(samples, inverse=True)