Creating a Custom Expression Factor

568 views
Skip to first unread message

magicb...@gmail.com

unread,
Jul 8, 2021, 3:58:55 PM7/8/21
to gtsam users
Greetings,

I would like to create a custom expression factor in order to take advantage of the automatic differentiation that is provided. Specifically, I am implementing a range rate factor (as opposed to the existing RangeFactor). I have already successfully implemented my custom factor as a NoiseModelFactor4, but have been having difficulties with grasping expressions.

For the constructor of my existing range rate factor, I take in 4 keys representing the positions of vehicles A and B at times `t-1` and `t+1`. The range rate measurement comes from time `t`. I also include inputs for all three times for the future when we may do some special operations to get a good estimate on the range rate. Finally, as with all other factors, I also take the shared noise model as a final input to the constructor.

My questions are:
  1. Should I just create an Expression object for my measurement function h and add that to the ExpressionFactorGraph as shown in the examples here: https://bitbucket.org/gtborg/gtsam/wiki/GTSAM_Expressions? Or, should I go about creating an entire class which inherits ExpressionFactorN? The only example for the latter I have been able to find thus far is in the TestNaryFactor class here: https://github.com/borglab/gtsam/blob/develop/tests/testExpressionFactor.cpp
  2. If I do take the route of creating a class based off of ExpressionFactorN, it looks like I will need to implement a few functions as opposed to just defining evaluateError found in the non-expression factors. While no implementation of those functions seem trivial to me, I am especially confused by `serialize`. This could just be due to my rusty C++ abilities, but any resources or discussion on this function would be much appreciated.
  3. Other than the few examples in the examples directory, the writeup on the bitbucket wiki linked above, and the doxygen documentation, are there any other resources that I can study to improve my understanding of Expressions within GTSAM?
  4. Am I missing anything else either in terms of what I should be asking or in the information I have provided? If so, please let me know and I will do my best to help you help me.
Thank you very much for your help and I look forward to learning more about GTSAM!
Reply all
Reply to author
Forward
0 new messages