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

Add GNC threshold parameter #1901

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

doggydoggy0101
Copy link

This PR adds the ability to change $\bar{c}$ in the TLS/GM function.

$$ \rho_\text{TLS}(r, \bar{c})=\min(r^2, \bar{c}^2)\ ;\ \ \rho_\text{GM}(r, \bar{c})=\frac{\bar{c}^2r^2}{\bar{c}^2+r^2} $$


Originally, in gtsam/nonlinear/GncOptimizer.h, $\bar{c}$ is always set to 1.

void setInlierCostThresholdsAtProbability(const double alpha) {
  barcSq_  = Vector::Ones(nfg_.size()); // initialize <- THIS LINE
  for (size_t k = 0; k < nfg_.size(); k++) {
    if (nfg_[k]) {
      barcSq_[k] = 0.5 * Chi2inv(alpha, nfg_[k]->dim()); // 0.5 derives from the error definition in gtsam
    }
  }
}

We add a barc parameter to gtsam/nonlinear/GncParams.h, thereby we can set barcSq with respect to barc

void setInlierCostThresholdsAtProbability(const double alpha) {
  barcSq_  = (params_.barc * params_.barc) * Vector::Ones(nfg_.size()); // initialize threshold to $bar{c}^2$
  for (size_t k = 0; k < nfg_.size(); k++) {
    if (nfg_[k]) {
      barcSq_[k] = 0.5 * Chi2inv(alpha, nfg_[k]->dim()); // 0.5 derives from the error definition in gtsam
    }
  }
}

We also tested it in examples/GNCExample.cpp

// Set GNC-specific options
GncParams<LevenbergMarquardtParams> gncParams(lmParams);
gncParams.setLossType(GncLossType::TLS);  // Truncated Least Squares or Geman-McClure 
gncParams.setBarc(1.0);                   // Parameter $c$ in Truncated Least Squares or Geman-McClure

In addition, there are other ways to set barcSq in gtsam/nonlinear/GncOptimizer.h

void setInlierCostThresholds(const double inth) {
  barcSq_ = inth * Vector::Ones(nfg_.size());
}

void setInlierCostThresholds(const Vector& inthVec) {
  barcSq_ = inthVec;
}

These two functions are not used in the origin GNC implementation, thus I am not sure what inth is. It seems like inth is $\bar{c}^2$ in gtsam/test/testGncOptimizer.cpp and is meant to set to $\bar{c}^2$ directly if known, so I left it unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant