Skip to content

Commit

Permalink
update python tests
Browse files Browse the repository at this point in the history
  • Loading branch information
varunagrawal committed Sep 17, 2024
1 parent dbd0ae1 commit c1ebdb2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
16 changes: 6 additions & 10 deletions python/gtsam/tests/test_HybridFactorGraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from gtsam import (DiscreteConditional, DiscreteKeys, GaussianConditional,
HybridBayesNet, HybridGaussianConditional,
HybridGaussianFactor, HybridGaussianFactorGraph,
HybridValues, JacobianFactor, Ordering, noiseModel)
HybridValues, JacobianFactor, noiseModel)

DEBUG_MARGINALS = False

Expand All @@ -31,13 +31,11 @@ class TestHybridGaussianFactorGraph(GtsamTestCase):
def test_create(self):
"""Test construction of hybrid factor graph."""
model = noiseModel.Unit.Create(3)
dk = DiscreteKeys()
dk.push_back((C(0), 2))

jf1 = JacobianFactor(X(0), np.eye(3), np.zeros((3, 1)), model)
jf2 = JacobianFactor(X(0), np.eye(3), np.ones((3, 1)), model)

gmf = HybridGaussianFactor([X(0)], dk, [(jf1, 0), (jf2, 0)])
gmf = HybridGaussianFactor([X(0)], (C(0), 2), [(jf1, 0), (jf2, 0)])

hfg = HybridGaussianFactorGraph()
hfg.push_back(jf1)
Expand All @@ -58,13 +56,11 @@ def test_create(self):
def test_optimize(self):
"""Test construction of hybrid factor graph."""
model = noiseModel.Unit.Create(3)
dk = DiscreteKeys()
dk.push_back((C(0), 2))

jf1 = JacobianFactor(X(0), np.eye(3), np.zeros((3, 1)), model)
jf2 = JacobianFactor(X(0), np.eye(3), np.ones((3, 1)), model)

gmf = HybridGaussianFactor([X(0)], dk, [(jf1, 0), (jf2, 0)])
gmf = HybridGaussianFactor([X(0)], (C(0), 2), [(jf1, 0), (jf2, 0)])

hfg = HybridGaussianFactorGraph()
hfg.push_back(jf1)
Expand Down Expand Up @@ -96,8 +92,6 @@ def tiny(num_measurements: int = 1,

# Create Gaussian mixture Z(0) = X(0) + noise for each measurement.
I_1x1 = np.eye(1)
keys = DiscreteKeys()
keys.push_back(mode)
for i in range(num_measurements):
conditional0 = GaussianConditional.FromMeanAndStddev(Z(i),
I_1x1,
Expand All @@ -107,8 +101,10 @@ def tiny(num_measurements: int = 1,
I_1x1,
X(0), [0],
sigma=3)
discreteParents = DiscreteKeys()
discreteParents.push_back(mode)
bayesNet.push_back(
HybridGaussianConditional([Z(i)], [X(0)], keys,
HybridGaussianConditional([Z(i)], [X(0)], discreteParents,
[conditional0, conditional1]))

# Create prior on X(0).
Expand Down
4 changes: 1 addition & 3 deletions python/gtsam/tests/test_HybridNonlinearFactorGraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ class TestHybridGaussianFactorGraph(GtsamTestCase):

def test_nonlinear_hybrid(self):
nlfg = gtsam.HybridNonlinearFactorGraph()
dk = gtsam.DiscreteKeys()
dk.push_back((10, 2))
nlfg.push_back(
BetweenFactorPoint3(1, 2, Point3(1, 2, 3),
noiseModel.Diagonal.Variances([1, 1, 1])))
Expand All @@ -40,7 +38,7 @@ def test_nonlinear_hybrid(self):
noiseModel.Unit.Create(3)), 0.0),
(PriorFactorPoint3(1, Point3(1, 2, 1),
noiseModel.Unit.Create(3)), 0.0)]
nlfg.push_back(gtsam.HybridNonlinearFactor([1], dk, factors))
nlfg.push_back(gtsam.HybridNonlinearFactor([1], (10, 2), factors))
nlfg.push_back(gtsam.DecisionTreeFactor((10, 2), "1 3"))
values = gtsam.Values()
values.insert_point3(1, Point3(0, 0, 0))
Expand Down

0 comments on commit c1ebdb2

Please sign in to comment.