-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also: - Fix immediate assignment of variable values
- Loading branch information
Showing
7 changed files
with
126 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
wave_optimization/include/wave/optimization/factor_graph/PerfectPrior.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/** | ||
* @file | ||
* @ingroup optimization | ||
*/ | ||
|
||
#ifndef WAVE_OPTIMIZATION_FACTOR_GRAPH_PERFECT_PRIOR_HPP | ||
#define WAVE_OPTIMIZATION_FACTOR_GRAPH_PERFECT_PRIOR_HPP | ||
|
||
#include "wave/optimization/factor_graph/FactorVariableBase.hpp" | ||
#include "wave/optimization/factor_graph/FactorBase.hpp" | ||
#include "wave/optimization/factor_graph/FactorMeasurement.hpp" | ||
|
||
|
||
namespace wave { | ||
/** @addtogroup optimization | ||
* @{ */ | ||
|
||
/** | ||
* A unary factor representing a noiseless prior | ||
* | ||
* A prior in a factor graph can be described as | ||
* | ||
* @f[ | ||
* Z = f(\theta) + \epsilon | ||
* @f] | ||
* | ||
* where @f$ f @$f is the measurement function, @f$ \theta @$f is a random | ||
* variable and @f$ \epsilon @$f is random noise. @f$ \epsilon @f cannot be | ||
* zero in general, as there may not be a solution for @f$ \Theta @$f. | ||
* | ||
* In libwave, noiseless priors are allowed in the case of a direct | ||
* measurement (i.e., @f$ f(\theta) = \theta @$f). These are called perfect | ||
* priors. Each FactorVariable may be connected to at most one perfect prior. | ||
* | ||
* @tparam VarType The type of factor variable we have prior information on | ||
*/ | ||
template <typename VarType> | ||
class PerfectPrior : public FactorBase { | ||
using FactorType = PerfectPrior<VarType>; | ||
using ViewType = typename VarType::ViewType; | ||
using MeasType = FactorMeasurement<ViewType, void>; | ||
|
||
public: | ||
constexpr static int NumVars = 1; | ||
constexpr static int ResidualSize = MeasType::Size; | ||
using ResidualType = Eigen::Matrix<double, ResidualSize, 1>; | ||
using VarArrayType = FactorBase::VarVectorType; | ||
using const_iterator = typename VarArrayType::const_iterator; | ||
|
||
/** Construct with the given measurement and variable. */ | ||
explicit PerfectPrior(MeasType measurement, | ||
std::shared_ptr<VarType> variable_ptr) | ||
: measurement{measurement}, variable_ptrs{variable_ptr} { | ||
// Assign to the variable | ||
variable_ptr->value = measurement.value; | ||
} | ||
|
||
int size() const override { | ||
return NumVars; | ||
} | ||
|
||
int residualSize() const override { | ||
return ResidualSize; | ||
} | ||
|
||
bool evaluateRaw(double const *const *, double *, double **) const | ||
noexcept override { | ||
return false; | ||
} | ||
|
||
/** Get a reference to the vector of variable pointers */ | ||
const VarVectorType &variables() const noexcept override { | ||
return this->variable_ptrs; | ||
} | ||
|
||
/** Return true if this factor is a zero-noise prior */ | ||
bool isPerfectPrior() const noexcept override { | ||
return true; | ||
} | ||
|
||
/** Print a representation for debugging. Used by operator<< */ | ||
void print(std::ostream &os) const override {} | ||
|
||
private: | ||
/** Storage of the measurement */ | ||
MeasType measurement; | ||
|
||
/** Pointers to the variables this factor is linked to */ | ||
VarArrayType variable_ptrs; | ||
}; | ||
|
||
/** @} group optimization */ | ||
} // namespace wave | ||
|
||
#endif // WAVE_OPTIMIZATION_FACTOR_GRAPH_PERFECT_PRIOR_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
wave_optimization/include/wave/optimization/factor_graph/impl/FactorGraph.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters