ezmsg.sigproc.math.anscombe#

Apply the Anscombe variance-stabilizing transform to the data, 2 * sqrt(c + 3/8), or invert it.

This is a variance-stabilizing transform for Poisson-distributed data such as spike or photon counts: the output has approximately unit variance regardless of the underlying rate, which lets downstream steps that assume homoscedastic Gaussian noise be applied to count data.

Inputs below -3/8 produce NaN, so this expects non-negative counts.

Note

This module supports the Array API standard, enabling use with NumPy, CuPy, PyTorch, and other compatible array libraries.

Classes

class Anscombe(*args, settings=None, **kwargs)[source]#

Bases: BaseTransformerUnit[AnscombeSettings, AxisArray, AxisArray, AnscombeTransformer]

Parameters:

settings (Settings | None)

SETTINGS#

alias of AnscombeSettings

class AnscombeSettings[source]#

Bases: Settings

The forward transform takes no parameters.

This empty class exists because a Unit cannot express “no settings”: SETTINGS = None is rejected by ezmsg’s Unit metaclass, and omitting SETTINGS makes the metaclass substitute a bare ez.Settings, which the transformer then rejects.

__init__()#
Return type:

None

class AnscombeTransformer(*args, settings=None, **kwargs)[source]#

Bases: BaseTransformer[AnscombeSettings, AxisArray, AxisArray]

Parameters:

settings (SettingsType)

class InverseAnscombe(*args, settings=None, **kwargs)[source]#

Bases: BaseTransformerUnit[InverseAnscombeSettings, AxisArray, AxisArray, InverseAnscombeTransformer]

Parameters:

settings (Settings | None)

SETTINGS#

alias of InverseAnscombeSettings

class InverseAnscombeSettings(method: str | InverseMethod = <InverseMethod.EXACT: 'exact'>)[source]#

Bases: Settings

Parameters:

method (str | InverseMethod)

__init__(method=InverseMethod.EXACT)#
Parameters:

method (str | InverseMethod)

Return type:

None

method: str | InverseMethod = 'exact'#

Which inverse to apply. See InverseMethod. Default is EXACT.

class InverseAnscombeTransformer(*args, settings=None, **kwargs)[source]#

Bases: BaseTransformer[InverseAnscombeSettings, AxisArray, AxisArray]

Parameters:

settings (SettingsType)

class InverseMethod(*values)[source]#

Bases: OptionsEnum

How to map stabilized values back to counts.

Every inverse here maps a denoised stabilized value back to a rate – that is, they invert rate -> E[anscombe(counts)]. Applying one to still-noisy data returns noisy counts, but the mean of that output is not the mean of the input.

EXACT = 'exact'#

Closed-form approximation of the exact unbiased inverse (Makitalo & Foi, 2011). Unbiased down to very low rates, at the cost of a few extra elementwise ops.

ASYMPTOTIC = 'asymptotic'#

(y/2)**2 - 1/8. Unbiased as the rate grows, noticeably biased below ~5 counts.

ALGEBRAIC = 'algebraic'#

(y/2)**2 - 3/8. The strict functional inverse of the forward transform, so it round-trips exactly, but it underestimates the mean of noisy data at low rates.