parsac.optimize package

Submodules

Module contents

class parsac.optimize.ComparisonPlotter(**kwargs: Any)

Bases: Plotter

POSTFIX = ':Comparisons'
class parsac.optimize.GaussianLikelihood(source: str, obs_vals: ArrayLike, sd: ArrayLike | None = None, logscale: bool = False, minimum: float | None = None, estimate_scale_factor: bool = False, min_scale_factor: float | None = None, max_scale_factor: float | None = None, scale_factor: float = 1.0, estimate_sd: bool | None = None)

Bases: Transform

Set up a Gaussian likelihood function This typically contributes to the objective function in an optimization experiment.

This function assumes that observations are normally distributed around modelled values, with a standard deviation that can be either provided or estimated from the model-observation differences.

It can also be used to represent observations that are log-normally distributed around modelled values by setting argument logscale to True. In that case both modelled and observed values are log-transformed.

Observations are provided upon initialization, and modelled values are provided when the likelihood is called.

Parameters:
  • source – The name of the output that will contain the model values.

  • obs_vals – The observed values.

  • sd – The standard deviation of the observed values. If not provided, it will be estimated from the differences betweeen modelled and observed values.

  • logscale – Whether to log-transform modelled and observed values before calculating the likelihood. This implies the distribution of observations around the modelled values is log-normal.

  • minimum – The minimum allowed value of the modelled and observed values. Lower values will be clipped to this value. This argument must be provided if logscale is True. It must then be greater than 0.0.

  • estimate_scale_factor – Whether to estimate the scale factor with which model values are multiplied before comparing to observations.

  • min_scale_factor – Lower bound of the estimated scale factor.

  • max_scale_factor – Upper bound of the estimated scale factor.

  • scale_factor – Fixed scale factor, active only if estimate_scale_factor is False.

  • estimate_sd – Whether to estimate the standard deviation of the observed values. If None (the default), the standard deviation is estimated if sd is not provided. If the observations do come with standard deviations, but you want to ignore these and estimate the standard deviation from model-observation differences instead, set this argument to True.

class parsac.optimize.HistogramPlotter(name: str, model_vals: ndarray, obs_vals: ndarray)

Bases: Plotter

Histogram of model-observation differences.

plot(ax: matplotlib.axes.Axes, logger: Logger) None
class parsac.optimize.ModelVsObservationPlotter(model_vals: ndarray, obs_vals: ndarray)

Bases: Plotter

Correlation plot showing model (y) versus observations (x).

plot(ax: matplotlib.axes.Axes, logger: Logger) None
class parsac.optimize.Optimization(**kwargs)

Bases: Experiment

An optimization experiment.

To configure the experiment, add parameters to calibrate by calling add_parameter(), and add contributions to the objective function (log likelihood) by calling add_target().

Parameters:

kwargs – Additional keyword arguments to passed to Experiment.

add_target(metric: Comparison, **kwargs: Any) None

Add a contribution to the fitness (log-likelihood) function.

Parameters:
  • metric – The metric to add to the fitness function. It is typically produced by a job from parsac.job.

  • kwargs – Additional keyword arguments to pass to the likelihood function GaussianLikelihood.

async get_lnls(values: ndarray[tuple[int, int], dtype[float64]]) ndarray

Calculate the log-likelihood of a parameter set.

run(**kwargs: Any) Mapping[str, float]

Run the optimization

Parameters:

kwargs – Additional keyword arguments to pass to desolver.solve().

async run_async(**kwargs) Mapping[str, float]
class parsac.optimize.TotalLikelihood(priors: list[Prior])

Bases: Transform

Sum of all likelihood contributions.

components: list[str]