matrix_order#
- tangles.util.matrix_order.matrix_order(matrix: ndarray | spmatrix, feats: ndarray | spmatrix, shift: float = 0)#
A general order function defined by a quadratic matrix.
For a feature indicator vector \(f\) and a matrix \(M\) this function computes \(|f| = f^T M f\).
If all entries outside the main diagonal in \(M\) are smaller or equal to 0 and shift is 0, then the submodularity of the order function is guaranteed.
Parameters#
- matrixnp.ndarray or sparse.spmatrix
A quadratic matrix of shape (
seps.shape[0]
,seps.shape[0]
).- featsnp.ndarray or sparse.spmatrix
Matrix containing indicator vectors of features as columns.
- shiftfloat
This parameter changes the order function’s preference for balanced features (note: it might also have an effect on its sub- or supermodularity). Let \(c\) denote the value of shift. The order function computes the order by \(|f| = f^T (M + cJ) f\).
Returns#
- ordersnp.ndarray
1-dimensional np.ndarray of length
seps.shape[1]
containing the orders.