2 GTSAM Copyright 2010-2022, Georgia Tech Research Corporation, 3 Atlanta, Georgia 30332-0415 6 See LICENSE for the license information 8 Unit tests for Hybrid Values. 20 from gtsam
import (DiscreteConditional, DiscreteKeys, DiscreteValues,
21 GaussianConditional, GaussianMixture, HybridBayesNet,
22 HybridValues, VectorValues, noiseModel)
26 """Unit tests for HybridValues.""" 29 """Test evaluate for a hybrid Bayes net P(X0|X1) P(X1|Asia) P(Asia).""" 35 conditional = GaussianConditional.FromMeanAndStddev(
36 X(0), 2 * I_1x1,
X(1), [-4], 5.0)
39 model0 = noiseModel.Diagonal.Sigmas([2.0])
40 model1 = noiseModel.Diagonal.Sigmas([3.0])
45 discrete_keys = DiscreteKeys()
46 discrete_keys.push_back(Asia)
49 bayesNet = HybridBayesNet()
50 bayesNet.push_back(conditional)
52 GaussianMixture([
X(1)], [], discrete_keys,
53 [conditional0, conditional1]))
54 bayesNet.push_back(DiscreteConditional(Asia,
"99/1"))
59 continuous.insert(
X(0), [-6])
60 continuous.insert(
X(1), [1])
61 values.insert(continuous)
64 values.insert(discrete)
66 conditionalProbability = conditional.evaluate(values.continuous())
67 mixtureProbability = conditional0.evaluate(values.continuous())
68 self.assertAlmostEqual(conditionalProbability * mixtureProbability *
70 bayesNet.evaluate(values),
74 self.assertAlmostEqual(bayesNet.logProbability(values),
75 math.log(bayesNet.evaluate(values)))
89 """Check invariance for given conditional.""" 90 probability = conditional.evaluate(values)
91 self.assertTrue(probability >= 0.0)
92 logProb = conditional.logProbability(values)
93 self.assertAlmostEqual(probability, np.exp(logProb))
94 expected = conditional.logNormalizationConstant() - \
95 conditional.error(values)
96 self.assertAlmostEqual(logProb, expected)
99 if __name__ ==
"__main__":
def check_invariance(self, conditional, values)