Weight Types¶
Each of these algorithms is parameterized over several different semirings. The weight_type argument is used to specify the semiring.
| Name | \(\oplus\) | \(\otimes\) | \(\bar{0}\) | \(\bar{1}\) | \(\mathbb{S}\)/dtype |
|---|---|---|---|---|---|
| LogViterbi | \(\max\) | \(+\) | \(-\infty\) | 0 | float32 |
| Viterbi | \(\max\) | \(*\) | 0 | 1 | float32 |
| Real | \(+\) | \(*\) | 0 | 1 | float32 |
| Log | logsum | \(+\) | \(-\infty\) | 0 | float32 |
| Boolean | or | and | false | true | uint8 |
| Counting | \(+\) | \(*\) | 0 | 1 | int32 |
| MinMax | \(\min\) | \(\max\) | \(-\infty\) | \(\infty\) | float32 |
Invariants¶
Check the semiring properties.
import pydecode.test.utils as test_utils
graph, weights, weight_type = test_utils.random_setup()
Check the additive and multiplicative identities.
assert (weight_type.Value.one() * weight_type.Value(weights[0])).value == weights[0]
assert (weight_type.Value.zero() + weight_type.Value(weights[0])).value == weights[0]