Fix python tests (and expose HybridBayesNet.error)
							parent
							
								
									a5951d8d34
								
							
						
					
					
						commit
						8357fc7e02
					
				|  | @ -143,6 +143,7 @@ class HybridBayesNet { | ||||||
|   // Standard interface: |   // Standard interface: | ||||||
|   double logProbability(const gtsam::HybridValues& values) const; |   double logProbability(const gtsam::HybridValues& values) const; | ||||||
|   double evaluate(const gtsam::HybridValues& values) const; |   double evaluate(const gtsam::HybridValues& values) const; | ||||||
|  |   double error(const gtsam::HybridValues& values) const; | ||||||
| 
 | 
 | ||||||
|   gtsam::HybridGaussianFactorGraph toFactorGraph( |   gtsam::HybridGaussianFactorGraph toFactorGraph( | ||||||
|       const gtsam::VectorValues& measurements) const; |       const gtsam::VectorValues& measurements) const; | ||||||
|  |  | ||||||
|  | @ -211,14 +211,15 @@ class TestHybridGaussianFactorGraph(GtsamTestCase): | ||||||
| 
 | 
 | ||||||
|         # Convert to factor graph with given measurements. |         # Convert to factor graph with given measurements. | ||||||
|         fg = bayesNet.toFactorGraph(measurements) |         fg = bayesNet.toFactorGraph(measurements) | ||||||
|         self.assertEqual(fg.size(), 4) |         self.assertEqual(fg.size(), 3) | ||||||
| 
 | 
 | ||||||
|         # Check ratio between unnormalized posterior and factor graph is the same for all modes: |         # Check ratio between unnormalized posterior and factor graph is the same for all modes: | ||||||
|         for mode in [1, 0]: |         for mode in [1, 0]: | ||||||
|             values.insert_or_assign(M(0), mode) |             values.insert_or_assign(M(0), mode) | ||||||
|             self.assertAlmostEqual(bayesNet.evaluate(values) / |             self.assertAlmostEqual(bayesNet.evaluate(values) / | ||||||
|                                    fg.error(values), |                                    np.exp(-fg.error(values)), | ||||||
|                                    0.025178994744461187) |                                    0.6366197723675815) | ||||||
|  |             self.assertAlmostEqual(bayesNet.error(values), fg.error(values)) | ||||||
| 
 | 
 | ||||||
|         # Test elimination. |         # Test elimination. | ||||||
|         posterior = fg.eliminateSequential() |         posterior = fg.eliminateSequential() | ||||||
|  | @ -292,7 +293,7 @@ class TestHybridGaussianFactorGraph(GtsamTestCase): | ||||||
| 
 | 
 | ||||||
|         # Convert to factor graph using measurements. |         # Convert to factor graph using measurements. | ||||||
|         fg = bayesNet.toFactorGraph(measurements) |         fg = bayesNet.toFactorGraph(measurements) | ||||||
|         self.assertEqual(fg.size(), 6) |         self.assertEqual(fg.size(), 4) | ||||||
| 
 | 
 | ||||||
|         # Calculate ratio between Bayes net probability and the factor graph: |         # Calculate ratio between Bayes net probability and the factor graph: | ||||||
|         expected_ratio = self.calculate_ratio(bayesNet, fg, values) |         expected_ratio = self.calculate_ratio(bayesNet, fg, values) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue