Added negate() to GaussianFactor, which computes the Anti-factor eqiuvalent, using implementation from the nonlinear Anti-factor
parent
947e5fe5ee
commit
b2e15eea4e
|
@ -115,6 +115,13 @@ namespace gtsam {
|
||||||
IndexFactor::permuteWithInverse(inversePermutation);
|
IndexFactor::permuteWithInverse(inversePermutation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct the corresponding anti-factor to negate information
|
||||||
|
* stored stored in this factor.
|
||||||
|
* @return a HessianFactor with negated Hessian matrices
|
||||||
|
*/
|
||||||
|
virtual GaussianFactor::shared_ptr negate() const = 0;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** Serialization function */
|
/** Serialization function */
|
||||||
friend class boost::serialization::access;
|
friend class boost::serialization::access;
|
||||||
|
|
|
@ -511,4 +511,24 @@ GaussianConditional::shared_ptr HessianFactor::splitEliminatedFactor(size_t nrFr
|
||||||
return conditional;
|
return conditional;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
GaussianFactor::shared_ptr HessianFactor::negate() const {
|
||||||
|
// Copy Hessian Blocks from Hessian factor and invert
|
||||||
|
std::vector<Index> js;
|
||||||
|
std::vector<Matrix> Gs;
|
||||||
|
std::vector<Vector> gs;
|
||||||
|
double f;
|
||||||
|
js.insert(js.end(), begin(), end());
|
||||||
|
for(size_t i = 0; i < js.size(); ++i){
|
||||||
|
for(size_t j = i; j < js.size(); ++j){
|
||||||
|
Gs.push_back( -info(begin()+i, begin()+j) );
|
||||||
|
}
|
||||||
|
gs.push_back( -linearTerm(begin()+i) );
|
||||||
|
}
|
||||||
|
f = -constantTerm();
|
||||||
|
|
||||||
|
// Create the Anti-Hessian Factor from the negated blocks
|
||||||
|
return HessianFactor::shared_ptr(new HessianFactor(js, Gs, gs, f));
|
||||||
|
}
|
||||||
|
|
||||||
} // gtsam
|
} // gtsam
|
||||||
|
|
|
@ -237,6 +237,13 @@ namespace gtsam {
|
||||||
/** Return the number of columns and rows of the Hessian matrix */
|
/** Return the number of columns and rows of the Hessian matrix */
|
||||||
size_t rows() const { return info_.rows(); }
|
size_t rows() const { return info_.rows(); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct the corresponding anti-factor to negate information
|
||||||
|
* stored stored in this factor.
|
||||||
|
* @return a HessianFactor with negated Hessian matrices
|
||||||
|
*/
|
||||||
|
virtual GaussianFactor::shared_ptr negate() const;
|
||||||
|
|
||||||
/** Return a view of the block at (j1,j2) of the <em>upper-triangular part</em> of the
|
/** Return a view of the block at (j1,j2) of the <em>upper-triangular part</em> of the
|
||||||
* information matrix \f$ H \f$, no data is copied. See HessianFactor class documentation
|
* information matrix \f$ H \f$, no data is copied. See HessianFactor class documentation
|
||||||
* above to explain that only the upper-triangular part of the information matrix is stored
|
* above to explain that only the upper-triangular part of the information matrix is stored
|
||||||
|
|
|
@ -385,6 +385,12 @@ namespace gtsam {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
GaussianFactor::shared_ptr JacobianFactor::negate() const {
|
||||||
|
HessianFactor hessian(*this);
|
||||||
|
return hessian.negate();
|
||||||
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
GaussianConditional::shared_ptr JacobianFactor::eliminateFirst() {
|
GaussianConditional::shared_ptr JacobianFactor::eliminateFirst() {
|
||||||
return this->eliminate(1);
|
return this->eliminate(1);
|
||||||
|
|
|
@ -169,6 +169,13 @@ namespace gtsam {
|
||||||
*/
|
*/
|
||||||
virtual Matrix computeInformation() const;
|
virtual Matrix computeInformation() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct the corresponding anti-factor to negate information
|
||||||
|
* stored stored in this factor.
|
||||||
|
* @return a HessianFactor with negated Hessian matrices
|
||||||
|
*/
|
||||||
|
virtual GaussianFactor::shared_ptr negate() const;
|
||||||
|
|
||||||
/** Check if the factor contains no information, i.e. zero rows. This does
|
/** Check if the factor contains no information, i.e. zero rows. This does
|
||||||
* not necessarily mean that the factor involves no variables (to check for
|
* not necessarily mean that the factor involves no variables (to check for
|
||||||
* involving no variables use keys().empty()).
|
* involving no variables use keys().empty()).
|
||||||
|
|
|
@ -99,30 +99,8 @@ namespace gtsam {
|
||||||
// Generate the linearized factor from the contained nonlinear factor
|
// Generate the linearized factor from the contained nonlinear factor
|
||||||
GaussianFactor::shared_ptr gaussianFactor = factor_->linearize(c, ordering);
|
GaussianFactor::shared_ptr gaussianFactor = factor_->linearize(c, ordering);
|
||||||
|
|
||||||
// Cast the GaussianFactor to a Hessian
|
// return the negated version of the factor
|
||||||
HessianFactor::shared_ptr hessianFactor = boost::dynamic_pointer_cast<HessianFactor>(gaussianFactor);
|
return gaussianFactor->negate();
|
||||||
|
|
||||||
// If the cast fails, convert it to a Hessian
|
|
||||||
if(!hessianFactor){
|
|
||||||
hessianFactor = HessianFactor::shared_ptr(new HessianFactor(*gaussianFactor));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Copy Hessian Blocks from Hessian factor and invert
|
|
||||||
std::vector<Index> js;
|
|
||||||
std::vector<Matrix> Gs;
|
|
||||||
std::vector<Vector> gs;
|
|
||||||
double f;
|
|
||||||
js.insert(js.end(), hessianFactor->begin(), hessianFactor->end());
|
|
||||||
for(size_t i = 0; i < js.size(); ++i){
|
|
||||||
for(size_t j = i; j < js.size(); ++j){
|
|
||||||
Gs.push_back( -hessianFactor->info(hessianFactor->begin()+i, hessianFactor->begin()+j) );
|
|
||||||
}
|
|
||||||
gs.push_back( -hessianFactor->linearTerm(hessianFactor->begin()+i) );
|
|
||||||
}
|
|
||||||
f = -hessianFactor->constantTerm();
|
|
||||||
|
|
||||||
// Create the Anti-Hessian Factor from the negated blocks
|
|
||||||
return HessianFactor::shared_ptr(new HessianFactor(js, Gs, gs, f));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue