edgespace
Functions:
-
sq2flat–Transform square (symmetric/triu) array(s) into cannonical 1d edge array(s).
-
flat2sq–Transform flat array of edge values to a square/symmetric "adjacency" representation
-
binary_feature_edge_cliques–returns a generator over the rows of X, projecting node->edgespace
sq2flat
sq2flat(
A: Shaped[COO | sparray | ndarray, "*batch n n"]
) -> Shaped[COO | sparray | ndarray, "*batch e"]
Transform square (symmetric/triu) array(s) into cannonical 1d edge array(s).
Preserves sparsity using triangular number identities (each m,n pair has a unique linear index).
Currently dispatches for numpy.ndarray, scipy sparse, and pydata's sparse.COO.
Parameters:
-
A(Shaped[COO | sparray | ndarray, '*batch n n']) –Square array to unroll
Returns:
-
Shaped[COO | sparray | ndarray, '*batch e']–flattened array of upper-triangle values
Source code in src/affinis/edgespace.py
flat2sq
Transform flat array of edge values to a square/symmetric "adjacency" representation
Preserves sparsity using triangular number identities (each edge index corresponds to a unique (m,n) pair of indices).
Parameters:
-
e–flat array (triangular-number-sized)
Returns:
-
Shaped[COO | sparray | ndarray, 'n n']–Square, symmetric array
Source code in src/affinis/edgespace.py
binary_feature_edge_cliques
binary_feature_edge_cliques(X: FeatMat)
returns a generator over the rows of X, projecting node->edgespace
Using the standard edgespace projection from [[affinis.edgespace.sq2flat]], we can interpret each observation of X as a clique (all pairwise interactions of the nodes in X are also active).
This turns every row of X into a 2D adjacency matrix, and then unrolls each slice's upper triangle to a (longer) 1D array.
Source code in src/affinis/edgespace.py
sq_e_ij
Closed-form expression to map edge-to-node-pair indices.
Get a row-column location in the upper-triangle of a symmetric matrix, given the linear index of it's unrolled vector representation.
Parameters:
-
n(int) –dimension of square/symmetric matrix
-
e(Idx) –index of edge(s) from vector-representation
Returns:
-
tuple[Idx, Idx]–pair of row(s),column(s) indices in corresponding matrix.
Source code in src/affinis/edgespace.py
sq_ij_e
Closed-form expression to map edge-to-node-pair indices.
Get an edge index from a row-column index pai upper-triangle of a symmetric matrix.
Parameters:
-
n(int) –dimension of square/symmetric matrix
-
ij(tuple[Idx, Idx]) –pair of row(s),column(s) indices in corresponding matrix.
Returns:
-
Idx–index of edge(s) from vector-representation
Source code in src/affinis/edgespace.py
csr_rows_idx
Return column indices for data in matrix, per row (empty array if none)