mcmodels.models.voxel.VoxelConnectivityArray

class mcmodels.models.voxel.VoxelConnectivityArray(weights, nodes)[source]

Class for implicit construction of the voxel model.

VoxelConnectivityArray is used to perfom analysis on the large (~200,000 by 400,000 element) voxel-scale connectivity matrix on normal* machines (loading the entire matrix would take hundreds of GB of working memory). You can access elements of the VoxelConnectivityArray object just like a list or numpy array, where each call to __getitem__ will implicitly construct the given slice of the array. Additionally, several numpy.ndarray methods have been implemented.

See VoxelModel for weights/nodes descriptions.

Parameters:
weights : array-like, shape (n_voxels, n_exps)

Weights matrix from fitted VoxelModel.

nodes : array-like, shape (n_exps, n_voxels)

Nodes matrix from fitted VoxelModel.

Examples

>>> from mcmodels.core import VoxelModelCache
>>> cache = VoxelModelCache()
>>> voxel_array, source_mask, target_mask = cache.get_voxel_connectivity_array()
>>> # VoxelConnectivityArray has several numpy.ndarray like methods
>>> # get some arbitrary model weights
>>> voxel_array[20:22, 10123]
array([0.000145, 0.000098])
>>> voxel_array.shape
(226346, 448962)
>>> voxel_array.T
VoxelConnectivityArray(dtype=float32, shape=(448962, 226346))
Attributes:
T

Short for transpose()

dtype

numpy.dtype of full array

shape

numpy.shape of full array

size

numpy.size of full array

Methods

astype(self, dtype, \*\*kwargs) Consistent with numpy.ndarray.astype.
from_csv(weights_file, nodes_file, \*\*kwargs) Alternative constructor loading weights, nodes from .csv files.
from_fitted_voxel_model(voxel_model) Alternative constructor using fitted VoxelModel object.
from_npy(weights_file, nodes_file, \*\*kwargs) Alternative constructor loading weights, nodes from npy, npz files.
itercolumns(self) Generator for yielding columns of the voxel matrix.
itercolumns_blocked(self[, n_blocks]) Generator for yielding blocked columns of the voxel matrix.
iterrows(self) Generator for yielding rows of the voxel matrix.
iterrows_blocked(self, n_blocks) Generator for yielding blocked rows of the voxel matrix.
mean(self[, axis]) Consistent with numpy.ndarray.mean.
sum(self[, axis]) Consistent with numpy.ndarray.sum.
transpose(self) Returns transpose of full array.
__init__(self, weights, nodes)[source]

Methods

__init__(self, weights, nodes)
astype(self, dtype, \*\*kwargs) Consistent with numpy.ndarray.astype.
from_csv(weights_file, nodes_file, \*\*kwargs) Alternative constructor loading weights, nodes from .csv files.
from_fitted_voxel_model(voxel_model) Alternative constructor using fitted VoxelModel object.
from_npy(weights_file, nodes_file, \*\*kwargs) Alternative constructor loading weights, nodes from npy, npz files.
itercolumns(self) Generator for yielding columns of the voxel matrix.
itercolumns_blocked(self[, n_blocks]) Generator for yielding blocked columns of the voxel matrix.
iterrows(self) Generator for yielding rows of the voxel matrix.
iterrows_blocked(self, n_blocks) Generator for yielding blocked rows of the voxel matrix.
mean(self[, axis]) Consistent with numpy.ndarray.mean.
sum(self[, axis]) Consistent with numpy.ndarray.sum.
transpose(self) Returns transpose of full array.
T

Short for transpose()

astype(self, dtype, **kwargs)[source]

Consistent with numpy.ndarray.astype.

see numpy.ndarray.astype for more info.

Parameters:
dtype : string

Data type to convert array.

**kwargs :

Keyword arguments to numpy.ndarray.astype

Returns:
self :

VoxelArray with new dtype.

dtype

numpy.dtype of full array

classmethod from_csv(weights_file, nodes_file, **kwargs)[source]

Alternative constructor loading weights, nodes from .csv files.

Parameters:
weights_file : string or path

Path to the .csv file containing the model weights. This file can have .gz or .bz2 compression

nodes_file : string or path

Path to the .csv file containing the model nodes. This file can have .gz or .bz2 compression

**kwargs

Optional keyword arguments supplied to numpy.loadtxt

Returns:
An instantiated VoxelConnectivityArray object.
classmethod from_fitted_voxel_model(voxel_model)[source]

Alternative constructor using fitted VoxelModel object.

Parameters:
voxel_model : A fitted VoxelModel object.
Returns:
An instantiated VoxelConnectivityArray object.
classmethod from_npy(weights_file, nodes_file, **kwargs)[source]

Alternative constructor loading weights, nodes from npy, npz files.

Parameters:
weights_file : string or path

Path to the .npy or .npz file containing the model weights.

nodes_file : string or path

Path to the .npy or .npz file containing the model nodes.

**kwargs

Optional keyword arguments supplied to numpy.load

Returns:
An instantiated VoxelConnectivityArray object.
itercolumns(self)[source]

Generator for yielding columns of the voxel matrix.

Yields:
array : shape = (n_rows,)

Single column of the voxel-scale connectivity matrix.

itercolumns_blocked(self, n_blocks=0)[source]

Generator for yielding blocked columns of the voxel matrix.

Parameters:
n_blocks : int

The number of blocks of columns that is wished to be returned. Must be on the interval [1, n_columns].

Yields:
array : A block of columns of the full voxel-scale connectivity matrix.
iterrows(self)[source]

Generator for yielding rows of the voxel matrix.

Yields:
array : shape = (n_columns,)

Single row of the voxel-scale connectivity matrix.

iterrows_blocked(self, n_blocks)[source]

Generator for yielding blocked rows of the voxel matrix.

Parameters:
n_blocks : int

The number of blocks of rows that is wished to be returned. Must be on the interval [1, n_rows]

Yields:
array : A block of rows of the full voxel-scale connectivity matrix.
mean(self, axis=None)[source]

Consistent with numpy.ndarray.mean.

see numpy.ndarray.mean for more info.

Parameters:
axis - None, int, optional (default=None)

Axis over which to take mean.

Returns:
array

Mean along axis.

shape

numpy.shape of full array

size

numpy.size of full array

sum(self, axis=None)[source]

Consistent with numpy.ndarray.sum.

see numpy.ndarray.sum for more info.

Parameters:
axis - None, int, optional (default=None)

Axis over which to sum.

Returns:
array

Sum along axis.

transpose(self)[source]

Returns transpose of full array.