tfConstrainedGauss package

Subpackages

Submodules

tfConstrainedGauss.helpers module

tfConstrainedGauss.helpers.array_safe_eq(a, b) bool

Check if a and b are equal, even if they are numpy arrays. Needed for checking equality with @dataclass(eq=False) decorator

tfConstrainedGauss.helpers.check_non_zero_idx_pairs(n: int, non_zero_idx_pairs: List[Tuple[int, int]])

Check list of non-zero index pairs is valid, i.e. lower triangular and that all diagonal elements are given

Args:

n (int): Size of matrix non_zero_idx_pairs (List[Tuple[int,int]]): List of non-zero index pairs in the matrix

Raises:

ValueError: If not all diagonal elements are specified ValueError: If some indices are not lower-triangular

tfConstrainedGauss.helpers.check_symmetric(a, rtol=1e-05, atol=1e-08) bool

Check a matrix is symmetric

Args:

a ([type]): Matrix rtol ([type], optional): Tol. Defaults to 1e-05. atol ([type], optional): Tol. Defaults to 1e-08.

Returns:

bool: True if symmetric

tfConstrainedGauss.helpers.convert_mat_non_zero_to_inv_mat(n: int, non_zero_idx_pairs: List[Tuple[int, int]], mat_non_zero: numpy.array) numpy.array

Convert list of matrice’s non-zero elements into the matrice’s inverse

Args:

n (int): Size of matrix non_zero_idx_pairs (List[Tuple[int,int]]): List of non-zero index pairs in the matrix mat_non_zero (np.array): Corresponding non-zero matrix elements

Returns:

np.array: Inverse of the nxn matrix

tfConstrainedGauss.helpers.convert_mat_non_zero_to_inv_mat_non_zero(n: int, non_zero_idx_pairs: List[Tuple[int, int]], mat_non_zero: numpy.array) numpy.array

Convert list of matrice’s non-zero elements into the matrice’s inverse’s list of elements

Args:

n (int): Size of matrix non_zero_idx_pairs (List[Tuple[int,int]]): List of non-zero index pairs in the matrix mat_non_zero (np.array): Corresponding non-zero matrix elements

Returns:

np.array: List of elements corresponding to indices non_zero_idx_pairs in the inverse of the matrix which has non-zero elements given by mat_non_zero

tfConstrainedGauss.helpers.convert_mat_non_zero_to_mat(n: int, non_zero_idx_pairs: List[Tuple[int, int]], mat_non_zero: numpy.array) numpy.array

Convert list of matrice’s non-zero elements into the matrix

Args:

n (int): Size of matrix non_zero_idx_pairs (List[Tuple[int,int]]): List of non-zero index pairs in the matrix mat_non_zero (np.array): Corresponding non-zero matrix elements

Returns:

np.array: nxn matrix with specified non-zero elements

tfConstrainedGauss.helpers.convert_mat_to_mat_non_zero(n: int, non_zero_idx_pairs: List[Tuple[int, int]], mat: numpy.array) numpy.array

Convert a matrix to it’s list of non-zero elements for specified non-zero indices

Args:

n (int): Size of matrix non_zero_idx_pairs (List[Tuple[int,int]]): List of non-zero index pairs in the matrix mat_non_zero (np.array): nxn matrix

Returns:

np.array: List of elements specified by non_zero_idx_pairs

tfConstrainedGauss.helpers.convert_np_to_pd(arr_with_times: numpy.array, nv: int, nh: int) pandas.core.frame.DataFrame

Convert a numpy array of wt, b, sig2, muh, varh_diag to a pandas dataframe with named columns

Args:
arr_with_times (np.array): Array of size TxN where T is the number of timepoints and

N is the size of (wt,b,sig2,muh,varh_diag) = (nv*nh, nv, 1, nh, nh) = nv*nh + nv + 1 + 2*nh

nv (int): No. visible species nh (int): No. hidden species

Returns:

pd.DataFrame: Pandas data frame

tfConstrainedGauss.helpers.dc_eq(dc1, dc2) bool

checks if two dataclasses which hold numpy arrays are equal. Needed for checking equality with @dataclass(eq=False) decorator

tfConstrainedGauss.helpers.normalize(vec: numpy.array) numpy.array

Normalize 1D np arr

Args:

vec (np.array): 1D vec to normalize

Returns:

np.array: normalized

tfConstrainedGauss.helpers.random_cov_mat(n: int, unit_diag: bool, diag_scale_std_dev: float = 0.1) numpy.array

Generate a random realistic covariance matrix following Madar 2015 Stat Probab Lett. 2015 August 1; 103: 142–147. doi:10.1016/j.spl.2015.03.014.

Args:

n (int): Size of matrix unit_diag (bool): Whether the diagonal should be all 1 (True), otherwise the diagonal is scaled as

described by diag_scale_std_dev

diag_scale_std_dev (float): If unit_diag is False, a scaling matrix is constructed as

A = diag(randomNormal(mean=1, std_dev=diag_scale_std_dev)). The covariance matrix is transformed as A.cov.Transpose[A] corresponding to scaling the data matrix Z by A.Z. Default = 0.1.

Returns:

np.array: Covariance matrix

tfConstrainedGauss.helpers.random_non_zero_idx_pairs(n: int) List[Tuple[int, int]]

Generate a random list of non-zero index pairs. The number of index pairs is less than n choose 2 (max). The indices are lower triangular.

Args:

n (int): Size of the matrix

Returns:

List[Tuple[int,int]]: List of index pairs in the lower triangular matrix.

tfConstrainedGauss.net_common module

tfConstrainedGauss.net_common.unit_mat(n: int, i: int, j: int)
Construct the non-symmetric unit matrix of size nxn

1 at (i,j) ONLY 0 elsewhere

Args:

n (int): Size of square matrix i (int): First idx j (int): Second idx

Returns:

tf.Constant: Matrix that is 1 at (i,j) ONLY and 0 everywhere else

tfConstrainedGauss.net_common.unit_mat_sym(n: int, i: int, j: int)
Construct the symmetric unit matrix of size nxn

1 at (i,j) AND (j,i) 0 elsewhere

Args:

n (int): Size of square matrix i (int): First idx j (int): Second idx

Returns:

tf.Constant: Matrix that is 1 at (i,j) AND (j,i) and 0 everywhere else

Module contents