"""Chosen NMF-shaped factors, not a fitted topic model; no packages or network."""
import json
W=[[2,0],[0,2],[1,1]]
H=[[1,1,0,0],[0,0,1,1]]
if __name__=="__main__":
    X=[[sum(W[i][k]*H[k][j] for k in range(2)) for j in range(4)] for i in range(3)]
    assert X==[[2,2,0,0],[0,0,2,2],[1,1,1,1]]
    assert all(v>=0 for a in W+H for v in a)
    # Permuting component order leaves reconstruction unchanged.
    W2=[r[::-1] for r in W];H2=H[::-1]
    assert [[sum(W2[i][k]*H2[k][j] for k in range(2)) for j in range(4)] for i in range(3)]==X
    print(json.dumps({"reconstruction":X,"mixed_document_weights":W[2],"permutation_changes_topic_ID_not_matrix":True},indent=2))
