def test_zmatrix(): assignments = [ [2, 345, 2, 2], [3, 345, 2, 2], [3, 9, 1, 1], ] zmat = query.zmatrix(assignments) assert_true(query._is_square_ndarray(zmat))
def test_zmatrix_heuristic_block_reordering(): assignments = [ [2, 345, 2, 2], [3, 345, 2, 2], [3, 9, 1, 1], ] zmat = query.zmatrix(assignments) order = query.zmatrix_heuristic_block_ordering(zmat) assert_true(query._is_permutation(order, zmat.shape[0]))
def test_zmatrix_reorder(): assignments = [ [2, 345, 2, 2], [3, 345, 2, 2], [3, 9, 1, 1], ] zmat = query.zmatrix(assignments) reordered = query.zmatrix_reorder(zmat, np.arange(zmat.shape[0])) assert_almost_equals(np.abs(zmat - reordered).max(), 0.)
def zmatrix(latents): """Compute a z-matrix (cluster co-assignment matrix). The ij-th entry of a z-matrix is a real value scalar between [0, 1] indicating the frequency of how often entities i and j appear in the same cluster. Parameters ---------- latents : list of mixturemodel latent objects The latents should all be points in the state space of the same structural model. The implementation currently does not check for this. Returns ------- zmat : (N, N) ndarray Notes ----- Currently does not support a sparse zmatrix representation, so only use this for small N. """ return query.zmatrix([latent.assignments() for latent in latents])