MCPcopy Create free account
hub / github.com/bamler-lab/constriction / test_categorical2

Function test_categorical2

tests/python/test_docexamples.py:781–797  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

779
780
781def 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
800def test_custom_model1():

Callers

nothing calls this directly

Calls 3

encode_reverseMethod · 0.95
get_compressedMethod · 0.95
decodeMethod · 0.95

Tested by

no test coverage detected