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

Function test_model_mod2

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

Source from the content-addressed store, hash-verified

742
743
744def test_model_mod2():
745 model_family = constriction.stream.model.QuantizedGaussian(-100, 100)
746 # Note: we omitted the mean and standard deviation, but the quantization range
747 # {-100, ..., 100} must always be specified when constructing the model.
748
749 # Define arrays of model parameters (means and standard deviations):
750 symbols = np.array([12, 15, 4, -2, 18, 5], dtype=np.int32)
751 means = np.array([13.2, 17.9, 7.3, -4.2, 25.1, 3.2], dtype=np.float64)
752 stds = np.array([3.2, 4.7, 5.2, 3.1, 6.3, 2.9], dtype=np.float64)
753
754 # Encode and decode an example message:
755 coder = constriction.stream.stack.AnsCoder() # (RangeEncoder also works)
756 coder.encode_reverse(symbols, model_family, means, stds)
757 assert np.all(coder.get_compressed() == np.array(
758 [2051958011, 1549], dtype=np.uint32))
759
760 reconstructed = coder.decode(model_family, means, stds)
761 assert np.all(reconstructed == symbols) # (verify correctness)
762
763
764def test_categorical1():

Callers

nothing calls this directly

Calls 3

encode_reverseMethod · 0.95
get_compressedMethod · 0.95
decodeMethod · 0.95

Tested by

no test coverage detected