fix python example

release/4.3a0
Frank Dellaert 2022-01-31 07:23:36 -05:00
parent 06fb94144b
commit cd94e7dda2
1 changed files with 3 additions and 4 deletions

View File

@ -8,7 +8,6 @@ See LICENSE for the license information
A structure-from-motion problem on a simulated dataset A structure-from-motion problem on a simulated dataset
""" """
from __future__ import print_function
import gtsam import gtsam
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
@ -89,7 +88,7 @@ def main():
point_noise = gtsam.noiseModel.Isotropic.Sigma(3, 0.1) point_noise = gtsam.noiseModel.Isotropic.Sigma(3, 0.1)
factor = PriorFactorPoint3(L(0), points[0], point_noise) factor = PriorFactorPoint3(L(0), points[0], point_noise)
graph.push_back(factor) graph.push_back(factor)
graph.print_('Factor Graph:\n') graph.print('Factor Graph:\n')
# Create the data structure to hold the initial estimate to the solution # Create the data structure to hold the initial estimate to the solution
# Intentionally initialize the variables off from the ground truth # Intentionally initialize the variables off from the ground truth
@ -100,7 +99,7 @@ def main():
for j, point in enumerate(points): for j, point in enumerate(points):
transformed_point = point + 0.1*np.random.randn(3) transformed_point = point + 0.1*np.random.randn(3)
initial_estimate.insert(L(j), transformed_point) initial_estimate.insert(L(j), transformed_point)
initial_estimate.print_('Initial Estimates:\n') initial_estimate.print('Initial Estimates:\n')
# Optimize the graph and print results # Optimize the graph and print results
params = gtsam.DoglegParams() params = gtsam.DoglegParams()
@ -108,7 +107,7 @@ def main():
optimizer = DoglegOptimizer(graph, initial_estimate, params) optimizer = DoglegOptimizer(graph, initial_estimate, params)
print('Optimizing:') print('Optimizing:')
result = optimizer.optimize() result = optimizer.optimize()
result.print_('Final results:\n') result.print('Final results:\n')
print('initial error = {}'.format(graph.error(initial_estimate))) print('initial error = {}'.format(graph.error(initial_estimate)))
print('final error = {}'.format(graph.error(result))) print('final error = {}'.format(graph.error(result)))