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, DiscreteValues,
21 GaussianConditional, HybridBayesNet,
22 HybridGaussianConditional, HybridValues, VectorValues,
27 """Unit tests for HybridValues."""
30 """Test evaluate for a hybrid Bayes net P(X0|X1) P(X1|Asia) P(Asia)."""
36 conditional = GaussianConditional.FromMeanAndStddev(
37 X(0), 2 * I_1x1,
X(1), [-4], 5.0)
40 model0 = noiseModel.Diagonal.Sigmas([2.0])
41 model1 = noiseModel.Diagonal.Sigmas([3.0])
49 bayesNet.push_back(conditional)
57 continuous.insert(
X(0), [-6])
58 continuous.insert(
X(1), [1])
59 values.insert(continuous)
62 values.insert(discrete)
64 conditionalProbability = conditional.evaluate(values.continuous())
65 mixtureProbability = conditional0.evaluate(values.continuous())
66 self.assertAlmostEqual(conditionalProbability * mixtureProbability *
68 bayesNet.evaluate(values),
72 self.assertAlmostEqual(bayesNet.logProbability(values),
73 math.log(bayesNet.evaluate(values)))
87 """Check invariance for given conditional."""
88 probability = conditional.evaluate(values)
89 self.assertTrue(probability >= 0.0)
90 logProb = conditional.logProbability(values)
91 self.assertAlmostEqual(probability, np.exp(logProb))
92 expected = -(conditional.negLogConstant() + conditional.error(values))
93 self.assertAlmostEqual(logProb, expected)
96 if __name__ ==
"__main__":