holopy.inference package
Submodules
holopy.inference.cmaes module
Stochastic fitting of models to data
- class CmaStrategy(npixels=None, popsize=None, resample_pixels=True, parent_fraction=0.25, weight_function=None, walker_initial_pos=None, tols={}, seed=None, parallel='auto')
Bases:
HoloPyObjectInference strategy defining a Covariance Matrix Adaptation Evolutionary Strategy using cma package
- Parameters:
npixels (int, optional) – Number of pixels in the image to fit. default fits all.
resample_pixels (Boolean, optional) – If true (default), new pixels are chosen for each call of posterior. Otherwise, a single pixel subset is used throughout calculation.
parent_fraction (float, optional) – Fraction of each generation to use to construct the next generation. Takes symbol mu in cma literature
weight_function (function, optional) – takes arguments (i, popsize), i in range(popsize); returns weight of i
tols (dict, optional) – tolerance values to overwrite the cma defaults
seed (int, optional) – random seed to use
parallel (optional) – number of threads to use or pool object or one of {None, ‘all’, ‘mpi’}. Default tries ‘mpi’ then ‘all’.
- fit(model, data)
- run_cma(obj_func, parameters, initial_population, weight_function, tols={}, seed=None, parallel='auto')
instantiate and run a CMAEvolutionStrategy object
- Parameters:
obj_func (Function) – function to be minimized (not maximized like posterior)
parameters (list of Prior objects) – parameters to fit
initial_population (array) – starting population with shape = (popsize, len(parameters))
weight_function (function) – takes arguments (i, popsize), i in range(popsize); returns weight of i
tols (dict, optional) – tolerance values to overwrite the cma defaults
seed (int, optional) – random seed to use
parallel (optional) – number of threads to use or pool object or one of {None, ‘all’, ‘mpi’}. Default tries ‘mpi’ then ‘all’.
holopy.inference.emcee module
Sample posterior probabilities given model and data
- class EmceeStrategy(nwalkers=100, nsamples=None, npixels=None, walker_initial_pos=None, parallel='auto', seed=None)
Bases:
HoloPyObject- sample(model, data)
- class TemperedStrategy(next_initial_dist=<function sample_one_sigma_gaussian>, nwalkers=100, nsamples=1000, min_pixels=None, npixels=1000, walker_initial_pos=None, parallel='auto', stages=3, stage_len=30, seed=None)
Bases:
EmceeStrategy- add_stage_strategy(nsamples, npixels)
- sample(model, data)
- emcee_lnprobs_DataArray(sampler)
- emcee_samples_DataArray(sampler, parameter_names)
- sample_emcee(model, data, nwalkers, nsamples, walker_initial_pos, parallel='auto', seed=None)
- sample_one_sigma_gaussian(result)
holopy.inference.interface module
- fit(data, model, parameters=None, strategy=None)
- make_default_model(base_scatterer, fitting_parameters=None)
- make_uniform(guesses, key)
- parameterize_scatterer(base_scatterer, fitting_parameters)
- replace_center(parameters, key)
- sample(data, model, strategy=None)
- validate_strategy(strategy, operation)
holopy.inference.model module
- class AlphaModel(scatterer, alpha=1, noise_sd=None, medium_index=None, illum_wavelen=None, illum_polarization=None, theory='auto', constraints=[])
Bases:
ModelModel of hologram image formation with scaling parameter alpha.
- property alpha
- class ExactModel(scatterer, calc_func=<function calc_holo>, noise_sd=None, medium_index=None, illum_wavelen=None, illum_polarization=None, theory='auto', constraints=[])
Bases:
ModelModel of arbitrary scattering function given by calc_func.
- class LimitOverlaps(fraction=0.1)
Bases:
HoloPyObjectConstraint prohibiting overlaps beyond a certain tolerance. fraction is the largest overlap allowed, in terms of sphere diameter.
- check(s)
- class Model(scatterer, noise_sd=None, medium_index=None, illum_wavelen=None, illum_polarization=None, theory='auto', constraints=[])
Bases:
HoloPyObjectModel probabilites of observing data
Compute probabilities that observed data could be explained by a set of scatterer and observation parameters.
- add_tie(parameters_to_tie, new_name=None)
Defines new ties between model parameters
- Parameters:
parameters_to_tie (listlike) – names of parameters to tie, as given by keys in model.parameters
new_name (string, optional) – the name for the new tied parameter
- ensure_parameters_are_listlike(pars)
- fit(data, strategy=None)
- forward(pars, detector)
- classmethod from_yaml(loader, node)
Convert a representation node to a Python object.
- generate_guess(n=1, scaling=1, seed=None)
- property illum_polarization
- property illum_wavelen
- property initial_guess
dictionary of initial guess values for each parameter
- property initial_guess_scatterer
- lnlike(pars, data)
Compute the log-likelihood for pars given data
- lnposterior(pars, data, pixels=None)
Compute the log-posterior probability of pars given data
- Parameters:
- Returns:
lnposterior
- Return type:
- lnprior(pars)
Compute the log-prior probability of pars
- property medium_index
- property noise_sd
- property parameters
dictionary of the model’s parameters
- sample(data, strategy=None)
- property scatterer
- scatterer_from_parameters(pars)
Creates a scatterer by setting values for model parameters
- theory_from_parameters(pars)
holopy.inference.nmpfit module
Interfaces to minimizers. Classes here provide a common interface to a variety of third party minimizers.
- class NmpfitStrategy(npixels=None, quiet=True, ftol=1e-10, xtol=1e-10, gtol=1e-10, damp=0, maxiter=100, seed=None)
Bases:
HoloPyObjectLevenberg-Marquardt minimizer, from Numpy/Python translation of Craig Markwardt’s mpfit.pro.
- Parameters:
npixels (None) – Fit only a randomly selected fraction of the data points in data
quiet (Boolean) – If False, print output on minimizer convergence. Default is True
ftol (float) – Convergence criterion for minimizer: converges if actual and predicted relative reductions in chi squared <= ftol
xtol (float) – Convergence criterion for minimizer: converges if relative error between two Levenberg-Marquardt iterations is <= xtol
gtol (float) – Convergence criterion for minimizer: converges if absolute value of cosine of angle between vector of cost function evaluated at current solution for minimized parameters and any column of the Jacobian is <= gtol
damp (float) – If nonzero, residuals larger than damp will be replaced by tanh. See nmpfit documentation.
maxiter (int) – Maximum number of Levenberg-Marquardt iterations to be performed.
Notes
See nmpfit documentation for further details. Not all functionalities of nmpfit are implemented here: in particular, we do not allow analytical derivatives of the residual function, which is impractical and/or impossible to calculate for holograms. If you want to weight the residuals, you need to supply a custom residual function.
- calc_residuals(par_vals)
- cleanup_from_fit()
- fit(model, data)
fit a model to some data
- Parameters:
model (
Modelobject) – A model describing the scattering system which leads to your data and the parameters to vary to fit it to the datadata (xarray.DataArray) – The data to fit
- Returns:
result – an object containing the best fit parameters and information about the fit
- Return type:
FitResult
- get_errors_from_minimizer(fitted_pars)
- initialize_fit(model, data)
- minimize(parameters, obj_func)
- unscale_pars_from_minimizer(values)
holopy.inference.result module
Results of sampling
- class FitResult(data, model, strategy, time, kwargs={})
Bases:
HoloPyObject- add_attr(kwargs)
- best_fit()
- forward(pars)
- property guess_hologram
- property guess_parameters
- property guess_scatterer
- property hologram
- property max_lnprob
- property parameters
- property scatterer
- class SamplingResult(data, model, strategy, time, kwargs={})
Bases:
FitResult- burn_in(sample_number)
- class TemperedSamplingResult(end_result, stage_results, strategy, time)
Bases:
SamplingResult
- class UncertainValue(guess, plus, minus=None, name=None)
Bases:
HoloPyObjectRepresent an uncertain value
holopy.inference.scipyfit module
- class LeastSquaresScipyStrategy(ftol=1e-10, xtol=1e-10, gtol=1e-10, max_nfev=None, npixels=None)
Bases:
HoloPyObject- fit(model, data)
fit a model to some data
- Parameters:
model (
Modelobject) – A model describing the scattering system which leads to your data and the parameters to vary to fit it to the datadata (xarray.DataArray) – The data to fit
- Returns:
result – Contains the best fit parameters and information about the fit
- Return type:
FitResult
- minimize(parameters, residuals_function)
- unscale_pars_from_minimizer(parameters, values)