Is there a way to set a node as "fixed", as in g2o?

48 views
Skip to first unread message

Federica Di Lauro

unread,
Apr 14, 2025, 10:23:31 AMApr 14
to gtsam users
Hi everyone,
I am trying to switch from g2o to gtsam.
In g2o you can use the method "setFixed()" to basically exclude a node from the optimization process.
I have not found an equivalent method in gtsam, can someone tell me if I am wrong, or if there is a workaround to exclude a node from the optimization process?

Thank you

Abhishek Goudar

unread,
Apr 14, 2025, 10:35:46 AMApr 14
to Federica Di Lauro, gtsam users
Depending on your use case, NonlineEqualityConstraint might work.  Below is a snippet that forces the variable associated with `prior_id` to be set to  (1.0, 1.0):


//
noiseModel::Constrained::shared_ptr constraint =
noiseModel::Constrained::All(traits<Point2>::dimension);
//
NonlinearEquality1<Point2> constraint_factor(Point2(1.0, 1.0), prior_id);
factor_graph_.add(constraint_factor);
//

--
You received this message because you are subscribed to the Google Groups "gtsam users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gtsam-users...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/gtsam-users/cee5e40f-f411-48ea-a603-0756a4843c67n%40googlegroups.com.

Dellaert, Frank

unread,
Apr 14, 2025, 12:02:40 PMApr 14
to Abhishek Goudar, Federica Di Lauro, gtsam users

Hi Abishek, Thanks Federica,

 

It’s a common question. So, two easy answers:

  • Federica’s advice, the NonlineEqualityConstraint, should work.
  • You can also try just setting the noise model to zero for certain factors – it will trigger treating the linearized factors as linear constraints. Your mileage may vary, as it is sort of a “poor man SQP”, and SQP can be tricky to make work.

 

Both, though, have the disadvantage that they keep these variables as things to optimize over, and that also means optimal variable orderings etc. might be prevented. So, especially if the “constrained mode” is going to be the more common case (say, after you have done a calibration run), there are two better options:

  • Make or use factor variants where the fixed variable is given as a parameter. Many factors have variants with and without calibration unknowns.
  • Use expressions. Then it is very easy to switch between an expression which is fixed or unknown. E.g,, for a body-camera extrinsic parameter:
      Expression<Pose3> bTc(known_bTc); // fixed !
      Expression<Pose3> bTc(bTc_key): // variable !

    Upside: reverse automatic differentiation for new factors
    Downside: only available in C++. A bit of a learning curve.

 

Best!

FD

 

 

From: gtsam...@googlegroups.com <gtsam...@googlegroups.com> on behalf of Abhishek Goudar <abhi.sh...@gmail.com>
Date: Monday, April 14, 2025 at 10:35
AM
To: Federica Di Lauro <federicad...@gmail.com>
Cc: gtsam users <gtsam...@googlegroups.com>
Subject: Re: [GTSAM] Is there a way to set a node as "fixed", as in g2o?

You don't often get email from abhi.sh...@gmail.com. Learn why this is important

Reply all
Reply to author
Forward
0 new messages