Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make mEstimator variable names consistent with math #188

Merged
merged 4 commits into from
Nov 30, 2021

Conversation

michaelbosse
Copy link
Contributor

@michaelbosse michaelbosse commented Dec 10, 2019

Rename mEstimator residual to loss so that it is not confused
with lsq residual vector Ax-b.
Rename distance to squaredDistance when appropriate.
Removed erroneous 0.5 factor from NoiseModelFactor::weight()
Fix bug in mEstimator::Null::loss()


This change is Reviewable

Rename mEstimator residual to loss so that it is not confused
with lsq residual vector Ax-b.
Rename distance to squaredDistance when appropriate.
Removed erroneous 0.5 factor from NoiseModelFactor::weight()
Fix bug in mEstimator::Null::loss()
@dellaert
Copy link
Member

 91/175 Test  #91: testNoiseModel .....................***Failed    0.03 sec
/Users/travis/build/borglab/gtsam/gtsam/linear/tests/testNoiseModel.cpp:680: Failure: "expected 0.5 but was: 1" 
There were 1 failures

Copy link
Contributor

@thduynguyen thduynguyen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@michaelbosse: The filename LossFunctions.* is very generic and obscure. Could we change it to MEstimators.*?

Reviewable status: 0 of 8 files reviewed, all discussions resolved

@varunagrawal varunagrawal added the enhancement Improvement to GTSAM label Feb 23, 2020
@varunagrawal varunagrawal self-requested a review March 10, 2020 11:18
gtsam/linear/NoiseModel.h Outdated Show resolved Hide resolved
@@ -106,7 +106,7 @@ double NoiseModelFactor::weight(const Values& c) const {
if (noiseModel_) {
const Vector b = unwhitenedError(c);
check(noiseModel_, b.size());
return 0.5 * noiseModel_->weight(b);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might cause regressions. 🙁

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, this is very significant, and seems fishy. Too bad this stuff did not get resolved when it was fresh in our minds, but now we have to re-argue this, and why it was not in @yetongumich PR.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. I believe the 0.5 should NOT be present, since if the noiseModel_ is not robust, the weight function should simply be 1 (which in NoiseModel.h it is). If the noise model is robust, then it should just return the weight value for that particular M-estimator given the residuals.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interestingly, there isn't any test for this 😢

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interestingly, there isn't any reasonable usages for this function either...

Also, I think the 0.5 factor should not be there. @dellaert

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only usage of this function is in gtsam_unstable/partition, so I suggest this function to be moved to unstable as a standalone function there.

Plus, this change is correct.

@dellaert
Copy link
Member

@varunagrawal, @mikebosse

@ProfFan and @yetongumich are currently examining/fixing all issues wrpt to Robust errors. We will get to this branch in due time but for now let's keep it dormant.

yetongumich added a commit that referenced this pull request Apr 2, 2020
yetongumich added a commit that referenced this pull request Apr 2, 2020
akshay-krishnan pushed a commit that referenced this pull request May 3, 2020
akshay-krishnan pushed a commit that referenced this pull request May 3, 2020
@varunagrawal varunagrawal added this to the GTSAM 4.1 milestone Jul 13, 2020
@dellaert
Copy link
Member

@mikebosse you probably have given up on this, but we merged a very similar PR yesterday based on this PR (and a lot of conversation about robust models). If you have a minute please merge in develop and see what still remains? You might have to fix some conflicts, please resolve in favor of "distance".

@dellaert dellaert modified the milestones: GTSAM 4.1, GTSAM 4.1.1 Jul 14, 2020
@yetongumich
Copy link
Contributor

Hi @mikebosse , In PR #269 , we have incorporated your changes by renaming residual to loss. In addition, we have also deprecated the "distance" function, and create mahalanobisDistance and squaredMahalanobisDistance, so that the code can better agree with math.

@dellaert
Copy link
Member

@yetongumich Please create a branch off of this branch and resolve conflicts with develop, then close this Pr and submit other branch? I would like to see what was in this PR that we have not yet done in your PR, inspired by this one. Probably nothing, but let’s be sure and clean this up.

@yetongumich
Copy link
Contributor

@yetongumich Please create a branch off of this branch and resolve conflicts with develop, then close this Pr and submit other branch? I would like to see what was in this PR that we have not yet done in your PR, inspired by this one. Probably nothing, but let’s be sure and clean this up.

@dellaert I think this PR merges directly into develop. May I know if we still need to create a new branch off this one?

As I went through "Files Changed" of this PR, the changes include

  • rename "residual" to "loss" (already incorporated in our PR)
  • rename "distance" to "squaredDistance" (in our PR, it's renamed as squaredMahalanobisDistance)
  • remove "distance_non_whitened" in robust noise model (this function is never called, and is also removed in the current develop branch)
  • resolve the issue that the "error" function in noisemodelfactor missed a 0.5 multiplier (which is already incorporated in our PR)
  • also add the 0.5 multiplier to the "weight" function in noisemodelfactor so that the robust noise model can perform similar to normal noise model when the error is small (this is already incorporated in our PR as well)

All the changes should be already incorporated in the current develop branch.

@dellaert
Copy link
Member

@yetongumich it too more energy to reply above than it takes to create the PR :-)
We need a branch and PR because we cannot sync a fork. And while I believe you, I'd like to see a PR were develop has been merged in so we are sure everything is included before we merge.

@varunagrawal
Copy link
Collaborator

I went ahead and synced the fork so we can easily check what is left. Moreover, I also uncommented and fixed some tests which should work given the updates to the robust losses.

@varunagrawal
Copy link
Collaborator

@dellaert @yetongumich looks like you guys got everything! 🎉

Can I get a review so we can (finally) merge this in?

Copy link
Member

@dellaert dellaert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll have to update me on this one...

@varunagrawal
Copy link
Collaborator

I just merged in the latest develop into my local branch, as you asked in a previous comment. I resolved conflicts by picking squaredMahalanobisDistance instead of squaredDistance and distance instead of error.
Finally I updated the failing tests.

@michaelbosse's PR pretty much covered exactly the changes you, @yetongumich and @ProfFan had made previously. I saw that the changes were minimal so I pushed them up to this PR.

@@ -101,6 +101,82 @@ TEST( NonlinearFactor, NonlinearFactor )
DOUBLES_EQUAL(expected,actual,0.00000001);
}

/* ************************************************************************* */
TEST(NonlinearFactor, Weight) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yetongumich and @ProfFan
You guys did the deep dive into robust models. Can you please weigh in?

@dellaert
Copy link
Member

@ProfFan @yetongumich "I see no problem" will not cut it :-) You guys did a deep dive into this a while ago, and should be able to decisively argue whether the 0.5 factor should be there, or not there. In either case, it will need a justification.

@varunagrawal
Copy link
Collaborator

Can we get this merged in soon please? 🙂

@varunagrawal varunagrawal mentioned this pull request Jul 25, 2021
14 tasks
@varunagrawal
Copy link
Collaborator

@ProfFan @yetongumich let's get this one in?

@varunagrawal varunagrawal self-assigned this Sep 18, 2021
@ProfFan
Copy link
Collaborator

ProfFan commented Oct 7, 2021

@yetongumich Could you take a look at this? We need this one for 4.1 release.

@yetongumich
Copy link
Contributor

@yetongumich Could you take a look at this? We need this one for 4.1 release.

Sorry for the late response. I went through this PR again, and we should be good with merging.

@varunagrawal
Copy link
Collaborator

@ProfFan @yetongumich "I see no problem" will not cut it :-) You guys did a deep dive into this a while ago, and should be able to decisively argue whether the 0.5 factor should be there, or not there. In either case, it will need a justification.

We still need a justification. 🙂

@dellaert
Copy link
Member

dellaert commented Oct 8, 2021

Whatever the outcome is, it should be documented somewhere so we don’t have to go through this again

Copy link
Collaborator

@ProfFan ProfFan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The weight function is not used anywhere other than gtsam_unstable, is untested, so I suggest it either be removed or moved to unstable as a standalone function. We can also merge this PR as-is. @dellaert

@ProfFan ProfFan closed this Nov 21, 2021
@ProfFan ProfFan reopened this Nov 21, 2021
@ProfFan
Copy link
Collaborator

ProfFan commented Nov 21, 2021

@dellaert @yetongumich @varunagrawal I am merging this if there are no objections. The weight in NoiseModelFactor should be the same as the one in the robust noise model.

@varunagrawal
Copy link
Collaborator

Yeah go for it. I don't know why @yetongumich isn't responding but we can't have him delay progress.

Copy link
Collaborator

@varunagrawal varunagrawal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ProfFan
Copy link
Collaborator

ProfFan commented Nov 22, 2021

We need @dellaert to approve

@dellaert
Copy link
Member

We need @dellaert to approve

@yetongumich needs to look at this. Please talk to him on slack/chat/whatever.

@@ -101,6 +101,82 @@ TEST( NonlinearFactor, NonlinearFactor )
DOUBLES_EQUAL(expected,actual,0.00000001);
}

/* ************************************************************************* */
TEST(NonlinearFactor, Weight) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@varunagrawal
Copy link
Collaborator

LGTM

@yetongumich you need to provide the answers for the above questions that Frank posed. This PR is basically waiting on you. 🙂

@dellaert
Copy link
Member

LGTM

@yetongumich you need to provide the answers for the above questions that Frank posed. This PR is basically waiting on you. 🙂

Agreed!

@yetongumich
Copy link
Contributor

Justification for why we should remove the 0.5:

The behavior of "weight" function in NoiseModelFactor should be the same as the "weight" function in NoiseModels. In robust NoiseModel, weights will change by values throughout iterations, while for gaussian NoiseModel, weight shall just stay 1. Therefore, the "weight" function should return the weight of the noisemodel, and should not have the 0.5 multiplier. Another justification is that when there's no noisemodel, the weight is 1, which is the same weight as Gaussian noise.

I don't know why there is a multiplier of 0.5 in the old code, maybe because of copy-paste from the error function, but I think we should have the 0.5 removed in the updated patch.

@ProfFan
Copy link
Collaborator

ProfFan commented Nov 30, 2021

@dellaert I agree with @yetongumich 's answer

@ProfFan
Copy link
Collaborator

ProfFan commented Nov 30, 2021

@dellaert We need your approval to merge.

Copy link
Member

@dellaert dellaert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Phew, this took a while (Yetong!) but let's finally land.

@dellaert dellaert merged commit 613b161 into borglab:develop Nov 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvement to GTSAM
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants