Example #1
0
    def test_lm_simple_printing(self):
        """Make sure we are properly terminating LM"""
        def hook(_, error):
            print(error)

        gtsam_optimize(self.lmoptimizer, self.lmparams, hook)

        actual = self.lmoptimizer.values()
        self.gtsamAssertEquals(actual.atRot3(KEY), self.expected, tol=1e-6)
Example #2
0
    def test_simple_printing(self):
        """Test with a simple hook."""

        # Provide a hook that just prints
        def hook(_, error):
            print(error)

        # Only thing we require from optimizer is an iterate method
        gtsam_optimize(self.optimizer, self.params, hook)

        # Check that optimizing yields the identity.
        actual = self.optimizer.values()
        self.gtsamAssertEquals(actual.atRot3(KEY), self.expected, tol=1e-6)
Example #3
0
    def test_comet(self):
        """Test with a comet hook."""
        from comet_ml import Experiment
        comet = Experiment(project_name="Testing",
                           auto_output_logging="native")
        comet.log_dataset_info(name="Karcher", path="shonan")
        comet.add_tag("GaussNewton")
        comet.log_parameter("method", "GaussNewton")
        time = datetime.now()
        comet.set_name("GaussNewton-" + str(time.month) + "/" + str(time.day) +
                       " " + str(time.hour) + ":" + str(time.minute) + ":" +
                       str(time.second))

        # I want to do some comet thing here
        def hook(optimizer, error):
            comet.log_metric("Karcher error", error, optimizer.iterations())

        gtsam_optimize(self.optimizer, self.params, hook)
        comet.end()

        actual = self.optimizer.values()
        self.gtsamAssertEquals(actual.atRot3(KEY), self.expected)
Example #4
0
    def test_lm_simple_printing(self):
        """Make sure we are properly terminating LM"""
        def hook(_, error):
            print(error)

        params = gtsam.LevenbergMarquardtParams()
        actual = optimize_using(gtsam.LevenbergMarquardtOptimizer, hook,
                                self.graph, self.initial)
        self.check(actual)
        actual = optimize_using(gtsam.LevenbergMarquardtOptimizer, hook,
                                self.graph, self.initial, params)
        self.check(actual)
        actual = gtsam_optimize(
            gtsam.LevenbergMarquardtOptimizer(self.graph, self.initial,
                                              params), params, hook)
Example #5
0
    def test_simple_printing(self):
        """Test with a simple hook."""

        # Provide a hook that just prints
        def hook(_, error):
            print(error)

        # Wrapper function sets the hook and calls optimizer.optimize() for us.
        params = gtsam.GaussNewtonParams()
        actual = optimize_using(gtsam.GaussNewtonOptimizer, hook, self.graph,
                                self.initial)
        self.check(actual)
        actual = optimize_using(gtsam.GaussNewtonOptimizer, hook, self.graph,
                                self.initial, params)
        self.check(actual)
        actual = gtsam_optimize(
            gtsam.GaussNewtonOptimizer(self.graph, self.initial, params),
            params, hook)
        self.check(actual)
Example #6
0
import os

dsname = os.path.splitext(os.path.basename(g2oFile))[0]

print("Logging to: " + args.logdir + "/" + args.prefix + "_" + dsname)
writer = SummaryWriter(args.logdir + "/" + args.prefix + "_" + dsname)


def hook(optimizer, error: float):
    writer.add_scalar("optimizer/loss", error, optimizer.iterations())
    writer.add_scalar("optimizer/lambda", optimizer.lambda_(),
                      optimizer.iterations())
    writer.flush()


gtsam_optimize(optimizer, params, hook)

result = optimizer.values()

print("Optimization complete")

print("initial error = ", graph.error(initial))
print("final error = ", graph.error(result))

if args.output is None:
    print("Final Result:\n{}".format(result))
else:
    outputFile = args.output
    print("Writing results to file: ", outputFile)
    # graphNoKernel, _ = gtsam.readG2o(g2oFile, is3D)
    gtsam.writeG2o(graph, result, outputFile)