@@ -221,8 +221,9 @@ double prob_m_z(double mu0, double mu1, double sigma0, double sigma1,
221
221
return 1 / (1 + e);
222
222
};
223
223
224
- static HybridBayesNet GetGaussianMixtureModel (double mu0, double mu1,
225
- double sigma0, double sigma1) {
224
+ static HybridBayesNet GetHybridGaussianConditionalModel (double mu0, double mu1,
225
+ double sigma0,
226
+ double sigma1) {
226
227
DiscreteKey m (M (0 ), 2 );
227
228
Key z = Z (0 );
228
229
@@ -254,7 +255,7 @@ static HybridBayesNet GetGaussianMixtureModel(double mu0, double mu1,
254
255
* The resulting factor graph should eliminate to a Bayes net
255
256
* which represents a sigmoid function.
256
257
*/
257
- TEST (HybridGaussianFactor, GaussianMixtureModel ) {
258
+ TEST (HybridGaussianFactor, HybridGaussianConditionalModel ) {
258
259
using namespace test_gmm ;
259
260
260
261
double mu0 = 1.0 , mu1 = 3.0 ;
@@ -263,7 +264,7 @@ TEST(HybridGaussianFactor, GaussianMixtureModel) {
263
264
DiscreteKey m (M (0 ), 2 );
264
265
Key z = Z (0 );
265
266
266
- auto hbn = GetGaussianMixtureModel (mu0, mu1, sigma, sigma);
267
+ auto hbn = GetHybridGaussianConditionalModel (mu0, mu1, sigma, sigma);
267
268
268
269
// The result should be a sigmoid.
269
270
// So should be P(m=1|z) = 0.5 at z=3.0 - 1.0=2.0
@@ -326,7 +327,7 @@ TEST(HybridGaussianFactor, GaussianMixtureModel) {
326
327
* which represents a Gaussian-like function
327
328
* where m1>m0 close to 3.1333.
328
329
*/
329
- TEST (HybridGaussianFactor, GaussianMixtureModel2 ) {
330
+ TEST (HybridGaussianFactor, HybridGaussianConditionalModel2 ) {
330
331
using namespace test_gmm ;
331
332
332
333
double mu0 = 1.0 , mu1 = 3.0 ;
@@ -335,7 +336,7 @@ TEST(HybridGaussianFactor, GaussianMixtureModel2) {
335
336
DiscreteKey m (M (0 ), 2 );
336
337
Key z = Z (0 );
337
338
338
- auto hbn = GetGaussianMixtureModel (mu0, mu1, sigma0, sigma1);
339
+ auto hbn = GetHybridGaussianConditionalModel (mu0, mu1, sigma0, sigma1);
339
340
340
341
double m1_high = 3.133 , lambda = 4 ;
341
342
{
@@ -393,7 +394,7 @@ namespace test_two_state_estimation {
393
394
394
395
DiscreteKey m1 (M(1 ), 2);
395
396
396
- void addMeasurement (HybridBayesNet& hbn, Key z_key, Key x_key, double sigma) {
397
+ void addMeasurement (HybridBayesNet & hbn, Key z_key, Key x_key, double sigma) {
397
398
auto measurement_model = noiseModel::Isotropic::Sigma (1 , sigma);
398
399
hbn.emplace_shared <GaussianConditional>(z_key, Vector1 (0.0 ), I_1x1, x_key,
399
400
-I_1x1, measurement_model);
@@ -414,7 +415,7 @@ static HybridGaussianConditional::shared_ptr CreateHybridMotionModel(
414
415
415
416
// / Create two state Bayes network with 1 or two measurement models
416
417
HybridBayesNet CreateBayesNet (
417
- const HybridGaussianConditional::shared_ptr& hybridMotionModel,
418
+ const HybridGaussianConditional::shared_ptr & hybridMotionModel,
418
419
bool add_second_measurement = false ) {
419
420
HybridBayesNet hbn;
420
421
@@ -437,9 +438,9 @@ HybridBayesNet CreateBayesNet(
437
438
438
439
// / Approximate the discrete marginal P(m1) using importance sampling
439
440
std::pair<double , double > approximateDiscreteMarginal (
440
- const HybridBayesNet& hbn,
441
- const HybridGaussianConditional::shared_ptr& hybridMotionModel,
442
- const VectorValues& given, size_t N = 100000 ) {
441
+ const HybridBayesNet & hbn,
442
+ const HybridGaussianConditional::shared_ptr & hybridMotionModel,
443
+ const VectorValues & given, size_t N = 100000 ) {
443
444
// / Create importance sampling network q(x0,x1,m) = p(x1|x0,m1) q(x0) P(m1),
444
445
// / using q(x0) = N(z0, sigmaQ) to sample x0.
445
446
HybridBayesNet q;
@@ -758,7 +759,7 @@ static HybridGaussianFactorGraph GetFactorGraphFromBayesNet(
758
759
auto model1 = noiseModel::Isotropic::Sigma (1 , sigmas[1 ]);
759
760
auto prior_noise = noiseModel::Isotropic::Sigma (1 , 1e-3 );
760
761
761
- // GaussianMixtureFactor component factors
762
+ // HybridGaussianFactor component factors
762
763
auto f0 =
763
764
std::make_shared<BetweenFactor<double >>(X (0 ), X (1 ), means[0 ], model0);
764
765
auto f1 =
@@ -783,8 +784,8 @@ static HybridGaussianFactorGraph GetFactorGraphFromBayesNet(
783
784
std::make_shared<GaussianConditional>(terms0, 1 , -d0, model0),
784
785
std::make_shared<GaussianConditional>(terms1, 1 , -d1, model1)};
785
786
gtsam::HybridBayesNet bn;
786
- bn.emplace_shared <GaussianMixture>(KeyVector{ Z ( 1 )}, KeyVector{ X ( 0 ), X ( 1 )},
787
- DiscreteKeys{m1}, conditionals);
787
+ bn.emplace_shared <HybridGaussianConditional>(
788
+ KeyVector{ Z ( 1 )}, KeyVector{ X ( 0 ), X ( 1 )}, DiscreteKeys{m1}, conditionals);
788
789
789
790
// Create FG via toFactorGraph
790
791
gtsam::VectorValues measurements;
@@ -812,7 +813,7 @@ static HybridGaussianFactorGraph GetFactorGraphFromBayesNet(
812
813
* P(Z1 | X1, X2, M1) has 2 conditionals each for the binary
813
814
* mode m1.
814
815
*/
815
- TEST (GaussianMixtureFactor , FactorGraphFromBayesNet) {
816
+ TEST (HybridGaussianFactor , FactorGraphFromBayesNet) {
816
817
DiscreteKey m1 (M (1 ), 2 );
817
818
818
819
Values values;
@@ -889,8 +890,8 @@ namespace test_direct_factor_graph {
889
890
* then perform linearization.
890
891
*
891
892
* @param values Initial values to linearize around.
892
- * @param means The means of the GaussianMixtureFactor components.
893
- * @param sigmas The covariances of the GaussianMixtureFactor components.
893
+ * @param means The means of the HybridGaussianFactor components.
894
+ * @param sigmas The covariances of the HybridGaussianFactor components.
894
895
* @param m1 The discrete key.
895
896
* @return HybridGaussianFactorGraph
896
897
*/
@@ -908,13 +909,10 @@ static HybridGaussianFactorGraph CreateFactorGraph(
908
909
std::make_shared<BetweenFactor<double >>(X (0 ), X (1 ), means[1 ], model1)
909
910
->linearize (values);
910
911
911
- // Create GaussianMixtureFactor
912
- std::vector<GaussianFactor::shared_ptr> factors{f0, f1};
913
- AlgebraicDecisionTree<Key> logNormalizers (
914
- {m1}, std::vector<double >{ComputeLogNormalizer (model0),
915
- ComputeLogNormalizer (model1)});
916
- GaussianMixtureFactor mixtureFactor ({X (0 ), X (1 )}, {m1}, factors,
917
- logNormalizers);
912
+ // Create HybridGaussianFactor
913
+ std::vector<GaussianFactorValuePair> factors{
914
+ {f0, ComputeLogNormalizer (model0)}, {f1, ComputeLogNormalizer (model1)}};
915
+ HybridGaussianFactor mixtureFactor ({X (0 ), X (1 )}, {m1}, factors);
918
916
919
917
HybridGaussianFactorGraph hfg;
920
918
hfg.push_back (mixtureFactor);
@@ -934,7 +932,7 @@ static HybridGaussianFactorGraph CreateFactorGraph(
934
932
* |
935
933
* M1
936
934
*/
937
- TEST (GaussianMixtureFactor , DifferentMeansFG) {
935
+ TEST (HybridGaussianFactor , DifferentMeansFG) {
938
936
using namespace test_direct_factor_graph ;
939
937
940
938
DiscreteKey m1 (M (1 ), 2 );
@@ -1009,7 +1007,7 @@ TEST(GaussianMixtureFactor, DifferentMeansFG) {
1009
1007
* |
1010
1008
* M1
1011
1009
*/
1012
- TEST (GaussianMixtureFactor , DifferentCovariancesFG) {
1010
+ TEST (HybridGaussianFactor , DifferentCovariancesFG) {
1013
1011
using namespace test_direct_factor_graph ;
1014
1012
1015
1013
DiscreteKey m1 (M (1 ), 2 );
@@ -1021,7 +1019,7 @@ TEST(GaussianMixtureFactor, DifferentCovariancesFG) {
1021
1019
1022
1020
std::vector<double > means = {0.0 , 0.0 }, sigmas = {1e2 , 1e-2 };
1023
1021
1024
- // Create FG with GaussianMixtureFactor and prior on X1
1022
+ // Create FG with HybridGaussianFactor and prior on X1
1025
1023
HybridGaussianFactorGraph mixture_fg =
1026
1024
CreateFactorGraph (values, means, sigmas, m1);
1027
1025
0 commit comments