support pythonic print for gtsam objects.
parent
9a8f06b70d
commit
d802255eb3
|
@ -35,7 +35,7 @@ odometry = gtsam.Pose2(2.0, 0.0, 0.0)
|
|||
# Create odometry (Between) factors between consecutive poses
|
||||
graph.add(gtsam.BetweenFactorPose2(1, 2, odometry, ODOMETRY_NOISE))
|
||||
graph.add(gtsam.BetweenFactorPose2(2, 3, odometry, ODOMETRY_NOISE))
|
||||
graph.print_("\nFactor Graph:\n")
|
||||
print("\nFactor Graph:\n{}".format(graph))
|
||||
|
||||
# Create the data structure to hold the initialEstimate estimate to the solution
|
||||
# For illustrative purposes, these have been deliberately set to incorrect values
|
||||
|
@ -43,10 +43,10 @@ initial = gtsam.Values()
|
|||
initial.insert(1, gtsam.Pose2(0.5, 0.0, 0.2))
|
||||
initial.insert(2, gtsam.Pose2(2.3, 0.1, -0.2))
|
||||
initial.insert(3, gtsam.Pose2(4.1, 0.1, 0.1))
|
||||
initial.print_("\nInitial Estimate:\n")
|
||||
print("\nInitial Estimate:\n{}".format(initial))
|
||||
|
||||
# optimize using Levenberg-Marquardt optimization
|
||||
params = gtsam.LevenbergMarquardtParams()
|
||||
optimizer = gtsam.LevenbergMarquardtOptimizer(graph, initial, params)
|
||||
result = optimizer.optimize()
|
||||
result.print_("\nFinal Result:\n")
|
||||
print("\nFinal Result:\n{}".format(result))
|
||||
|
|
|
@ -50,7 +50,7 @@ graph.add(gtsam.BearingRangeFactor2D(
|
|||
X3, L2, gtsam.Rot2.fromDegrees(90), 2.0, MEASUREMENT_NOISE))
|
||||
|
||||
# Print graph
|
||||
graph.print_("Factor Graph:\n")
|
||||
print("Factor Graph:\n{}".format(graph))
|
||||
|
||||
# Create (deliberately inaccurate) initial estimate
|
||||
initial_estimate = gtsam.Values()
|
||||
|
@ -61,7 +61,7 @@ initial_estimate.insert(L1, gtsam.Point2(1.80, 2.10))
|
|||
initial_estimate.insert(L2, gtsam.Point2(4.10, 1.80))
|
||||
|
||||
# Print
|
||||
initial_estimate.print_("Initial Estimate:\n")
|
||||
print("Initial Estimate:\n{}".format(initial_estimate))
|
||||
|
||||
# Optimize using Levenberg-Marquardt optimization. The optimizer
|
||||
# accepts an optional set of configuration parameters, controlling
|
||||
|
@ -72,7 +72,7 @@ initial_estimate.print_("Initial Estimate:\n")
|
|||
params = gtsam.LevenbergMarquardtParams()
|
||||
optimizer = gtsam.LevenbergMarquardtOptimizer(graph, initial_estimate, params)
|
||||
result = optimizer.optimize()
|
||||
result.print_("\nFinal Result:\n")
|
||||
print("\nFinal Result:\n{}".format(result))
|
||||
|
||||
# Calculate and print marginal covariances for all variables
|
||||
marginals = gtsam.Marginals(graph, result)
|
||||
|
|
|
@ -52,7 +52,7 @@ graph.add(gtsam.BetweenFactorPose2(
|
|||
# techniques with camera images. We will use another Between Factor to enforce this constraint:
|
||||
graph.add(gtsam.BetweenFactorPose2(
|
||||
5, 2, gtsam.Pose2(2, 0, math.pi / 2), ODOMETRY_NOISE))
|
||||
graph.print_("\nFactor Graph:\n") # print
|
||||
print("\nFactor Graph:\n{}".format(graph)) # print
|
||||
|
||||
# 3. Create the data structure to hold the initial_estimate estimate to the
|
||||
# solution. For illustrative purposes, these have been deliberately set to incorrect values
|
||||
|
@ -62,7 +62,7 @@ initial_estimate.insert(2, gtsam.Pose2(2.3, 0.1, -0.2))
|
|||
initial_estimate.insert(3, gtsam.Pose2(4.1, 0.1, math.pi / 2))
|
||||
initial_estimate.insert(4, gtsam.Pose2(4.0, 2.0, math.pi))
|
||||
initial_estimate.insert(5, gtsam.Pose2(2.1, 2.1, -math.pi / 2))
|
||||
initial_estimate.print_("\nInitial Estimate:\n") # print
|
||||
print("\nInitial Estimate:\n{}".format(initial_estimate)) # print
|
||||
|
||||
# 4. Optimize the initial values using a Gauss-Newton nonlinear optimizer
|
||||
# The optimizer accepts an optional set of configuration parameters,
|
||||
|
@ -79,7 +79,7 @@ parameters.setMaxIterations(100)
|
|||
optimizer = gtsam.GaussNewtonOptimizer(graph, initial_estimate, parameters)
|
||||
# ... and optimize
|
||||
result = optimizer.optimize()
|
||||
result.print_("Final Result:\n")
|
||||
print("Final Result:\n{}".format(result))
|
||||
|
||||
# 5. Calculate and print marginal covariances for all variables
|
||||
marginals = gtsam.Marginals(graph, result)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
These examples are almost identical to the old handwritten python wrapper
|
||||
examples. However, there are just some slight name changes, for example .print
|
||||
becomes .print_, and noiseModel.Diagonal becomes noiseModel_Diagonal etc...
|
||||
examples. However, there are just some slight name changes, for example
|
||||
noiseModel.Diagonal becomes noiseModel_Diagonal etc...
|
||||
Also, annoyingly, instead of gtsam.Symbol('b',0) we now need to say gtsam.symbol(ord('b'), 0))
|
||||
|
|
|
@ -106,7 +106,7 @@ void Method::emit_cython_pyx_no_overload(FileWriter& file,
|
|||
|
||||
// leverage python's special treatment for print
|
||||
if (funcName == "print_") {
|
||||
file.oss << " def __str__(self):\n";
|
||||
file.oss << " def __repr__(self):\n";
|
||||
file.oss << " strBuf = RedirectCout()\n";
|
||||
file.oss << " self.print_('')\n";
|
||||
file.oss << " return strBuf.str()\n";
|
||||
|
|
Loading…
Reference in New Issue