()
| 779 | |
| 780 | |
| 781 | def test_categorical2(): |
| 782 | # Define 3 categorical distributions, each over the alphabet {0,1,2,3,4}: |
| 783 | model_family = constriction.stream.model.Categorical(perfect=False) |
| 784 | probabilities = np.array( |
| 785 | [[0.3, 0.1, 0.1, 0.3, 0.2], # (for symbols[0]) |
| 786 | [0.1, 0.4, 0.2, 0.1, 0.2], # (for symbols[1]) |
| 787 | [0.4, 0.2, 0.1, 0.2, 0.1]], # (for symbols[2]) |
| 788 | dtype=np.float64) |
| 789 | |
| 790 | symbols = np.array([0, 4, 1], dtype=np.int32) |
| 791 | coder = constriction.stream.stack.AnsCoder() # (RangeEncoder also works) |
| 792 | coder.encode_reverse(symbols, model_family, probabilities) |
| 793 | assert np.all(coder.get_compressed() == np.array( |
| 794 | [104018741], dtype=np.uint32)) |
| 795 | |
| 796 | reconstructed = coder.decode(model_family, probabilities) |
| 797 | assert np.all(reconstructed == symbols) # (verify correctness) |
| 798 | |
| 799 | |
| 800 | def test_custom_model1(): |
nothing calls this directly
no test coverage detected