'RankedBlockState' object has no attribute 'get_matrix'

I would like to obtain the matrix of edge counts between groups in a partition arising from a RankedBlockState. However, the existing get_matrix() method doesn’t work on the RankedBlockState object. Is there a straightforward way to do this?

MWE:

g = gt.collection.ns["faculty_hiring/computer_science"].copy()
state = gt.RankedBlockState(g)
for i in range(100):
    state.multiflip_mcmc_sweep(beta=np.inf, niter=10)
state.get_matrix()

Maybe the most convenient way is to create a BlockState:

state.get_block_state().get_matrix()

That doesn’t behave how I expect: this seems to always return a 1x1 matrix.

e.g:

g = gt.collection.data["polbooks"]
state = gt.minimize_blockmodel_dl(g)
state.get_block_state().get_matrix()

returns

<Compressed Sparse Row sparse matrix of dtype ‘float64’ with 1 stored elements and shape (1, 1)>

whereas

g = gt.collection.data["polbooks"]
state = gt.minimize_blockmodel_dl(g)
state.get_matrix()

returns

<Compressed Sparse Row sparse matrix of dtype ‘float64’
with 32 stored elements and shape (105, 105)>

which is what I want.

The first code does not even use a ranked model, but that’s beside the point.

In any case, to get what you want just do:

BlockState(state.g, b=state.b).get_matrix()

Thank you, that’s what I wanted. I did originally have the first example using a ranked model, but simplified it when I realized it didn’t matter.