def to_strictly_lower_triangular(cls, mat): """Make a matrix strictly lower triangular. Make a matrix stricly lower triangular by zeroing out upper and diagonal elements. Parameters ---------- mat : array-like, shape=[..., n, n] Matrix. Returns ------- tril : array-like, shape=[..., n, n] Lower triangular matrix. """ return gs.tril(mat, k=-1)
def to_lower_triangular(cls, mat): """Make a matrix lower triangular. Make a matrix lower triangular by zeroing out upper elements. Parameters ---------- mat : array-like, shape=[..., n, n] Matrix. Returns ------- tril : array-like, shape=[..., n, n] Lower triangular matrix. """ return gs.tril(mat)
def is_strictly_lower_triangular(cls, mat, atol=gs.atol): """Check if a matrix is strictly lower triangular. Parameters ---------- mat : array-like, shape=[..., n, n] Matrix. atol : float Absolute tolerance. Optional, default : backend atol. Returns ------- is_strictly_tril : array-like, shape=[...,] Boolean evaluating if the matrix is strictly lower triangular """ is_square = cls.is_square(mat) if not is_square: is_vectorized = gs.ndim(gs.array(mat)) == 3 return gs.array([False] * len(mat)) if is_vectorized else False return cls.equal(mat, gs.tril(mat, k=-1), atol)
def load_connectomes(as_vectors=False): """Load data from brain connectomes. Load the correlation data from the kaggle MSLP 2014 Schizophrenia Challenge. The original data came as flattened vectors, but if `raw=True` is passed, the correlation values are reshaped as symmetric matrices with ones on the diagonal. Parameters ---------- as_vectors : bool Whether to return raw data as vectors or as symmetric matrices. Optional, default: False Returns ------- mat : array-like, shape=[86, {[28, 28], 378} Connectomes. patient_id : array-like, shape=[86,] Patient unique identifiers target : array-like, shape=[86,] Labels, whether patients belong to the diseased class (1) or control (0). """ with open(CONNECTOMES_PATH) as csvfile: data_list = list(csv.reader(csvfile)) patient_id = gs.array([int(row[0]) for row in data_list[1:]]) data = gs.array([[float(value) for value in row[1:]] for row in data_list[1:]]) with open(CONNECTOMES_LABELS_PATH) as csvfile: labels = list(csv.reader(csvfile)) target = gs.array([int(row[1]) for row in labels[1:]]) if as_vectors: return data, patient_id, target mat = SkewSymmetricMatrices(28).matrix_representation(data) mat = gs.eye(28) - gs.transpose(gs.tril(mat), (0, 2, 1)) mat = 1.0 / 2.0 * (mat + gs.transpose(mat, (0, 2, 1))) return mat, patient_id, target