Skip to content

Estimators

The base class of every algorithm, with its tags, fit history and (de)serialisation. See Estimators for a guided tour.

Estimator

Estimator(*, faithful=True, dtype=None, device=None, layout=None, **options)

Base class of optix estimators.

Subclasses define tags (which registers them), the paper and recommended presets, spell out their options as keyword-only parameters defaulting to None, and call self._resolve(faithful, locals()), which also routes a layout parameter to self.layout. They implement _fit and _apply; the public fit / apply run them under torch.no_grad().

Note

Subclasses receive a Labeled array in _fit / _apply whenever a layout is set, so that the io and stats helpers pick it up; _layout_of and _map_shape give the layout (default included) and the shape of the parameter maps.

Attributes:

Name Type Description
options dict

Resolved hyper-parameters.

is_faithful bool

Whether the resolved options equal the paper preset.

estimates dict of str to Estimate

Results of fit, e.g. {"sensor": ..., "shading": ...}. Parameter maps are shaped (*group, *spatial), spatial axes in layout order.

layout Layout or None

Layout used by the last fit (or given at construction); apply uses it for plain arrays.

history History

Set up the working backend and resolve the options.

Parameters:

Name Type Description Default
faithful bool

Selects the preset of defaults: paper when True, recommended when False. Explicit option values always win.

True
dtype optional

Working backend (default: configuration; the device follows a Tensor input when unset).

None
device optional

Working backend (default: configuration; the device follows a Tensor input when unset).

None
layout Layout

Axis roles of the data (see Layout); can also be given to fit, or carried by a labelled array. Default: (*samples, H, W).

None
**options object

Hyper-parameters (the base's view of the subclass's options).

{}

fit

fit(data, *, layout=None, init=None, callback=None, verbose=False)

Fit the model to data.

Parameters:

Name Type Description Default
data array - like or Labeled

Data; (*samples, H, W) without a layout.

required
layout Layout

Axis roles (default: that of a labelled data, else the one given at construction). Stored in self.layout.

None
init Estimate, sequence of Estimate, or Estimator

Initial values (cloned; the caller's objects are not modified).

None
callback callable

Called by iterative estimators after each iteration.

None
verbose bool
False

Returns:

Type Description
Estimator

self, with estimates and history filled. history is reset at the start of each call.

apply

apply(data, out=None)

Apply the fitted model (e.g. correct the data).

Parameters:

Name Type Description Default
data array - like or Labeled

Data, in the layout of the fit (unless labelled otherwise).

required
out writable array-like

Output (tensor, numpy, zarr, memmap...). Default: a new tensor on the device of data if it is a Tensor, else on the CPU.

None

Returns:

Type Description
writable array-like

out.

to

to(device=None, dtype=None)

Move estimates and any tensor state (in place).

state_dict

state_dict()

Everything needed to rebuild the fitted estimator.

load_state_dict

load_state_dict(state)

Restore a state_dict (in place).

save

save(path)

Save with torch.save (no pickled classes).

Tags dataclass

Tags(targets, streaming, modality=('any',), noise='none', many_frames=False, reference='')

Static description of an estimator.

Attributes:

Name Type Description
targets tuple of str

What it estimates, e.g. ("shading", "sensor").

streaming str

Data access pattern: "pointwise", "per-frame", "halo", "per-pixel-stats" or "whole-stack".

modality tuple of str

Imaging modalities it is meant for.

noise str

Noise model: "none", "gaussian", "poisson", "poisson-gaussian", ...

many_frames bool

Whether it needs many frames.

reference str

Citation or DOI.

History dataclass

History(objective=list(), extras=dict(), converged=False, reason='')

Objective trace of an iterative fit (objective is maximised).

Attributes:

Name Type Description
objective list of float
extras dict of str to list of float

Other per-iteration diagnostics.

converged bool
reason str

Why the fit stopped.

record

record(objective, **extras)

Append one iteration.

Takes Python floats: the caller does the single .item() per iteration.

gain

gain()

Relative change of the last step, (Lₜ − Lₜ₋₁) / |Lₜ|.

Returns inf with fewer than two records.

check

check(tol, *, monotone=False)

Whether |Lₜ − Lₜ₋₁| / |Lₜ| < tol; sets converged.

Parameters:

Name Type Description Default
tol float

Relative tolerance.

required
monotone bool

Warn (without stopping) when the objective decreases beyond round-off, which flags a bug in a VB / EM bound.

False

estimators

estimators()

Registered estimator classes (those defining tags), by name.

load

load(path)

Load an estimator or an estimate saved by optix.

Parameters:

Name Type Description Default
path str or PathLike
required

Returns:

Type Description
Estimator or Estimate

Dispatched on the saved class name (weights_only loading).