neurotools.linalg.operators module
Functions for generating discrete representations of certain operators, either as matrices or in terms of their discrete Fourier coefficients.
- neurotools.linalg.operators.adjacency1D(L, circular=True)[source]
1D adjacency matrix.
- Parameters:
N (int) – Size of operator
- Returns:
L – Adjacency matrix.
- Return type:
NxN sparse array
- neurotools.linalg.operators.laplacian1D_circular(N)[source]
Laplacian operator on a closed, discrete, one-dimensional domain of length
N
, with circularly-wrapped boundary condition.- Parameters:
N (int) – Size of operator
- Returns:
L – Matrix representation of Laplacian operator on a finite, discrete domain of length N.
- Return type:
NxN array
- neurotools.linalg.operators.adjacency2D(L, H=None, circular=True)[source]
2D adjacency matrix in 3x3 neighborhood.
- Parameters:
L (int) – Size of operator, or width if
H
is providedH (int) – Height of operator, if different from width
circular (bool) – If true, operator will wrap around the edge in both directions
- Returns:
L – Adjacency matrix.
- Return type:
NxN sparse array
- neurotools.linalg.operators.laplacian2D(L, H=None, circular=True, mask=None, boundary='dirichlet')[source]
Build a discrete Laplacian operator.
This is uses an approximately radially-symmetric Laplacian in a 3×3 neighborhood.
If a
mask
is provided, this supports a'neumann'
boundary condition, which amounts to clamping the derivative to zero at the boundary, and a'dirichlet'
boundary condition, which amounts to clamping the values to zero at the boundary.- Parameters:
L (int) – Size of operator, or width if H is provided
H (int) – Height of operator, if different from width
circular (bool) – If true, operator will wrap around the edge in both directions
mask (LxL np.bool) – Which pixels are in the domain
boundary (str) – Can be ‘dirichlet’, which is a zero boundary, or ‘neumann’, which is a reflecting boundary.
- Return type:
scipy.sparse.csr_matrix
- neurotools.linalg.operators.adjacency2D_circular(N)[source]
Adjacency matric on a closed NxN domain with circularly-wrapped boundary.
- Parameters:
N (int) – Size of operator
- Returns:
L – Adjacency matrix. The diagonal is zero (no self edges)
- Return type:
N²xN² array
- neurotools.linalg.operators.adjacency2d_rotational(L)[source]
2D adjacency matrix with nonzero weights for corner neighbors to improve rotational symmetry.
- neurotools.linalg.operators.laplacian1D(N)[source]
Laplacian operator on a closed, discrete, one-dimensional domain of length
N
- Parameters:
N (int) – Size of operator
- Returns:
L – Matrix representation of Laplacian operator on a finite, discrete domain of length N.
- Return type:
NxN array
- neurotools.linalg.operators.laplacianFT1D(N)[source]
- Parameters:
N (int) – Size of the domain
- Returns:
x – Fourier transform of discrete Laplacian operator on a discrete one-dimensional domain of lenght
N
- Return type:
np.array
- neurotools.linalg.operators.wienerFT1D(N)[source]
Square-root covariance operator for standard 1D Wiener process
- Parameters:
N (size of operator)
- neurotools.linalg.operators.diffuseFT1D(N, sigma)[source]
Fourier transform of a Gaussian smoothing kernel
- Parameters:
N (int) – Size of the domain
- neurotools.linalg.operators.dirichlet_derivative_operator(N)[source]
Discrete derivative treating out-of-bounds edges as zero.
- Parameters:
N (int)
- Returns:
result
- Return type:
N×N np.float32
- neurotools.linalg.operators.neumann_derivative_operator(N, abba=True)[source]
Discrete derivative with reflected boundary condition.
- Parameters:
N (int)
abba (bool) – False: Reflect e.g. ab? as aba True: Reflect e.g. ab? as `abba
- Returns:
result
- Return type:
N×N np.float32
- neurotools.linalg.operators.circular_derivative_operator(N)[source]
Circular discrete derivative.
- Parameters:
N (int)
- Returns:
result – Discrete derivative on circular domain
- Return type:
N×N np.float32
- neurotools.linalg.operators.circular_derivative_fourier(N)[source]
Circular discrete derivative Fourier domain kernel.
- Parameters:
N (int)
- Returns:
result – Fourier transform of circular discrete derivative.
- Return type:
N np.complex64
- neurotools.linalg.operators.truncated_derivative_operator(N)[source]
Discrete derivative operator, projecting from N to N-1 dimensions (spatial domain).
- Parameters:
N (int) – Size of the domain
- Returns:
result – Matrix D such that Dx = Δx
- Return type:
(N-1)×N np.float32
- neurotools.linalg.operators.terminated_derivative_operator(N)[source]
Discrete derivative, using {-1,1} at endpoints and ½{-1,0,1} in the interior.
This operator will have two zero eigenvalues for
N
even and three zero eigenvalues forN
odd.- Parameters:
N (int) – Size of the domain
- Returns:
result – Matrix D such that Dx = Δx
- Return type:
N×N np.float32
- neurotools.linalg.operators.pad1up(N)[source]
Interpolation operator going from N to N+1 samples. Used to re-sample the discrete derivative to preserve dimension.
- Parameters:
N (int) – Size of the domain
- Returns:
result
- Return type:
N×(N-1) np.float32
- neurotools.linalg.operators.spaced_derivative_operator(N)[source]
Discrete derivative, upsampled via linear interpolation to preserve dimension.
This will have 1 zero eigenvalue for odd N and two zero eigenvalues for even N.
- Parameters:
N (int) – Size of the domain
- Returns:
result
- Return type:
N×N np.float32
- neurotools.linalg.operators.gaussian1DblurOperator(n, sigma, truncate=1e-05, normalize=True)[source]
Returns a 1D Gaussan blur operator of size n
- Parameters:
n (int) – Length of buffer to apply blur
sigma (positive number) – Standard deviation of blur kernel
truncate (positive number, defaults to 1e-5) – Entries in the operator smaller than this (relative to the largest value) will be rounded down to zero.
- neurotools.linalg.operators.circular1DblurOperator(n, sigma, truncate=1e-05)[source]
Returns a circular 1D Gaussan blur operator of size n
- Parameters:
n (int) – Length of circular buffer to apply blur
sigma (positive number) – Standard deviation of blur kernel
truncate (positive number, defaults to 1e-5) – Entries in the operator smaller than this (relative to the largest value) will be rounded down to zero.
- neurotools.linalg.operators.gaussian2DblurOperator(n, sigma, normalize='left')[source]
Returns a 2D Gaussan blur operator for a n × n domain. Constructed as a tensor product of two 1d blurs.
- neurotools.linalg.operators.cosine_kernel(x)[source]
raised cosine basis kernel, normalized such that it integrates to 1 centered at zero. Time is rescaled so that the kernel spans from -2 to 2
- neurotools.linalg.operators.log_cosine_basis(N=range(1, 6), t=array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99]), base=2, offset=1, normalize=True)[source]
Generate overlapping log-cosine basis elements
- Parameters:
N (array of wave quarter-phases)
t (time base)
base (exponent base)
offset (leave this set to 1 (default))
- Returns:
B
- Return type:
array, Basis with n_elements x n_times shape
- neurotools.linalg.operators.make_cosine_basis(N, L, min_interval)[source]
Build N logarightmically spaced cosine basis functions spanning L samples, with a peak resolution of min_interval
# Solve for a time basis with these constraints # t[0] = 0 # t[min_interval] = 1 # log(L)/log(b) = n_basis+1 # log(b) = log(L)/(n_basis+1) # b = exp(log(L)/(n_basis+1))
- Returns:
B
- Return type:
array, Basis with n_elements x n_times shape