allowing for duplicate keys in a factor

Issue #130 wontfix
Michael Bosse created an issue

Is there a way to make it possible to have duplicate keys in a factor, such that when the factor gets linearized (or somewhere) that the Jacobians corresponding to the same key will get summed?

This would greatly simplify the bookkeeping required when constructing factors from parts where the same key may be referenced multiple times in the different parts.

As the code seems to be right now, an exceptions will be thrown in some places when inserting into VectorValues for the second (or third) reference to the same key. I would think that these operations could be made valid by summing the inserts to the same key. Somewhat like the way matlab sums the duplicate matrix coefficient references when constructing a sparse matrix from (row,col,value) triplets.

Comments (4)

  1. Chris Beall

    Yes, this is actually already possible by handling the combination of Jacobians entirely in your factor during linearization:

    Derive from NoiseModelFactor or NonlinearFactor directly, instead of NoiseModelFactorN. This will let you create factors with an arbitrary number of (duplicate) keys, and you can handle the reconciliation of multiple Jacobians for the same variable during linearization. Simply override the relevant virtual methods. (SmartProjectionFactor is an example of a factor that does a lot of different things during linearization.)

  2. Frank Dellaert

    Note, the new "twice as fast" reverse AD expression factor in feature/BAD already does this. By tomorrow, it should even support Ceres-style AD as basis expressions. Ask @ptf (though he's been AWOL on the thread :-))

  3. Paul Furgale

    I think we will move our curves library immediately to the BAD code. @dellaert, your results are literally unbelievable.

  4. Log in to comment