algorithms.statistics.utils¶
Module: algorithms.statistics.utils
¶
Functions¶
-
nipy.algorithms.statistics.utils.
check_cast_bin8
(arr)[source]¶ Return binary array arr as uint8 type, or raise if not binary.
- Parameters
arr : array-like
- Returns
bin8_arr : uint8 array
bin8_arr has same shape as arr, is of dtype
np.uint8
, with values 0 and 1 only.- Raises
ValueError
When the array is not binary. Speficically, raise if, for any element
e
,e != (e != 0)
.
-
nipy.algorithms.statistics.utils.
complex
(maximal=[(0, 3, 2, 7), (0, 6, 2, 7), (0, 7, 5, 4), (0, 7, 5, 1), (0, 7, 4, 6), (0, 3, 1, 7)])[source]¶ Faces from simplices
Take a list of maximal simplices (by default a triangulation of a cube into 6 tetrahedra) and computes all faces
- Parameters
maximal : sequence of sequences, optional
Default is triangulation of cube into tetrahedra
- Returns
faces : dict
-
nipy.algorithms.statistics.utils.
cube_with_strides_center
(center=[0, 0, 0], strides=[4, 2, 1])[source]¶ Cube in an array of voxels with a given center and strides.
This triangulates a cube with vertices [center[i] + 1].
The dimension of the cube is determined by len(center) which should agree with len(center).
The allowable dimensions are [1,2,3].
- Parameters
center : (d,) sequence of int, optional
Default is [0, 0, 0]
strides : (d,) sequence of int, optional
Default is [4, 2, 1]. These are the strides given by
np.ones((2,2,2), np.bool).strides
- Returns
complex : dict
A dictionary with integer keys representing a simplicial complex. The vertices of the simplicial complex are the indices of the corners of the cube in a ‘flattened’ array with specified strides.
-
nipy.algorithms.statistics.utils.
decompose2d
(shape, dim=3)[source]¶ Return all (dim-1)-dimensional simplices in a triangulation of a square of a given shape. The vertices in the triangulation are indices in a ‘flattened’ array of the specified shape.
-
nipy.algorithms.statistics.utils.
decompose3d
(shape, dim=4)[source]¶ Return all (dim-1)-dimensional simplices in a triangulation of a cube of a given shape. The vertices in the triangulation are indices in a ‘flattened’ array of the specified shape.
-
nipy.algorithms.statistics.utils.
join_complexes
(*complexes)[source]¶ Join a sequence of simplicial complexes.
Returns the union of all the particular faces.
-
nipy.algorithms.statistics.utils.
multiple_fast_inv
(a)[source]¶ Compute the inverse of a set of arrays in-place
- Parameters
a: array_like of shape (n_samples, M, M)
Set of square matrices to be inverted. a is changed in place.
- Returns
a: ndarray shape (n_samples, M, M)
The input array a, overwritten with the inverses of the original 2D arrays in
a[0], a[1], ...
. Thusa[0]
replaced withinv(a[0])
etc.- Raises
LinAlgError :
If a is singular.
ValueError :
If a is not square, or not 2-dimensional.
Notes
This function is copied from scipy.linalg.inv, but with some customizations for speed-up from operating on multiple arrays. It also has some conditionals to work with different scipy versions.
-
nipy.algorithms.statistics.utils.
multiple_mahalanobis
(effect, covariance)[source]¶ Returns the squared Mahalanobis distance for a given set of samples
- Parameters
effect: array of shape (n_features, n_samples),
Each column represents a vector to be evaluated
covariance: array of shape (n_features, n_features, n_samples),
Corresponding covariance models stacked along the last axis
- Returns
sqd: array of shape (n_samples,)
the squared distances (one per sample)