lib5c.algorithms.variance.local module

lib5c.algorithms.variance.local.local_variance(matrix, model='lognorm', w=1, min_finite=3, min_disp=1e-08)[source]

Estimates pixel-wise variance by treating nearby matrix entries as replicates.

Parameters
  • matrix (np.ndarray) – Square, symmetric matrix of count values.

  • model ({'lognorm', 'nbinom'}) – Statistical model to use.

  • w (int or np.ndarray) – Size of footprint to use. Footprint will be np.eye(2*w+1). To use a different footprint, pass it as an np.ndarray.

  • min_finite (int) – Points with fewer than this many finite entries inside their footprint will have their variance estimate set to nan.

  • min_disp (float) – Force a minimum value of the dispersion parameter.

Returns

The first three elements are the mean parameter estimate, dispersion estimate, and variance estimate, respectively, for each pixel. The fourth element is a boolean matrix showing which pixels are considered to be overdispersed.

Return type

tuple of np.ndarray

Examples

>>> import numpy as np
>>> from lib5c.algorithms.variance.local import local_variance
>>> local_variance(np.array([[1, 4, 1],
...                          [4, 1, 1],
...                          [1, 1, 1]]), model='norm', min_finite=2)
(array([[1. , 2.5, 1. ],
        [2.5, 1. , 2.5],
        [1. , 2.5, 1. ]]),
 array([[1.0e-08, 4.5e+00,     nan],
        [4.5e+00, 1.0e-08, 4.5e+00],
        [    nan, 4.5e+00, 1.0e-08]]),
 array([[1.0e-08, 4.5e+00,     nan],
        [4.5e+00, 1.0e-08, 4.5e+00],
        [    nan, 4.5e+00, 1.0e-08]]),
 array([[False,  True, False],
        [ True, False,  True],
        [False,  True, False]]))