2009-12-28 17:56:58 +08:00
|
|
|
/*
|
|
|
|
|
* iterative.cpp
|
|
|
|
|
* @brief Iterative methods, implementation
|
|
|
|
|
* @author Frank Dellaert
|
|
|
|
|
* Created on: Dec 28, 2009
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "GaussianFactorGraph.h"
|
2009-12-29 00:26:16 +08:00
|
|
|
#include "iterative-inl.h"
|
2009-12-28 17:56:58 +08:00
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
namespace gtsam {
|
|
|
|
|
|
|
|
|
|
/* ************************************************************************* */
|
2009-12-28 20:37:34 +08:00
|
|
|
|
|
|
|
|
/** gradient of objective function 0.5*|Ax-b|^2 at x = A'*(Ax-b) */
|
|
|
|
|
Vector gradient(const System& Ab, const Vector& x) {
|
|
|
|
|
const Matrix& A = Ab.first;
|
|
|
|
|
const Vector& b = Ab.second;
|
|
|
|
|
return A ^ (A * x - b);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Apply operator A */
|
|
|
|
|
Vector operator*(const System& Ab, const Vector& x) {
|
|
|
|
|
const Matrix& A = Ab.first;
|
|
|
|
|
return A * x;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Apply operator A^T */
|
|
|
|
|
Vector operator^(const System& Ab, const Vector& x) {
|
|
|
|
|
const Matrix& A = Ab.first;
|
|
|
|
|
return A ^ x;
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-29 00:15:26 +08:00
|
|
|
Vector steepestDescent(const System& Ab, const Vector& x, bool verbose,
|
|
|
|
|
double epsilon, size_t maxIterations) {
|
|
|
|
|
return conjugateGradients<System, Vector, Vector> (Ab, x, verbose, epsilon,
|
2009-12-28 20:37:34 +08:00
|
|
|
maxIterations, true);
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-28 17:56:58 +08:00
|
|
|
Vector conjugateGradientDescent(const System& Ab, const Vector& x,
|
2009-12-29 00:15:26 +08:00
|
|
|
bool verbose, double epsilon, size_t maxIterations) {
|
|
|
|
|
return conjugateGradients<System, Vector, Vector> (Ab, x, verbose, epsilon,
|
2009-12-28 20:37:34 +08:00
|
|
|
maxIterations);
|
2009-12-28 17:56:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ************************************************************************* */
|
2009-12-28 20:37:34 +08:00
|
|
|
Vector steepestDescent(const Matrix& A, const Vector& b, const Vector& x,
|
2009-12-29 00:15:26 +08:00
|
|
|
bool verbose, double epsilon, size_t maxIterations) {
|
2009-12-28 20:37:34 +08:00
|
|
|
System Ab = make_pair(A, b);
|
2009-12-29 00:15:26 +08:00
|
|
|
return conjugateGradients<System, Vector, Vector> (Ab, x, verbose, epsilon,
|
2009-12-28 20:37:34 +08:00
|
|
|
maxIterations, true);
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-28 17:56:58 +08:00
|
|
|
Vector conjugateGradientDescent(const Matrix& A, const Vector& b,
|
2009-12-29 00:15:26 +08:00
|
|
|
const Vector& x, bool verbose, double epsilon, size_t maxIterations) {
|
2009-12-28 17:56:58 +08:00
|
|
|
System Ab = make_pair(A, b);
|
2009-12-29 00:15:26 +08:00
|
|
|
return conjugateGradients<System, Vector, Vector> (Ab, x, verbose, epsilon,
|
2009-12-28 20:37:34 +08:00
|
|
|
maxIterations);
|
2009-12-28 17:56:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ************************************************************************* */
|
|
|
|
|
VectorConfig gradient(const GaussianFactorGraph& fg, const VectorConfig& x) {
|
|
|
|
|
return fg.gradient(x);
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-28 20:37:34 +08:00
|
|
|
VectorConfig steepestDescent(const GaussianFactorGraph& fg,
|
2009-12-29 00:15:26 +08:00
|
|
|
const VectorConfig& x, bool verbose, double epsilon, size_t maxIterations) {
|
2009-12-28 20:37:34 +08:00
|
|
|
return conjugateGradients<GaussianFactorGraph, VectorConfig, Errors> (fg,
|
2009-12-29 00:15:26 +08:00
|
|
|
x, verbose, epsilon, maxIterations, true);
|
2009-12-28 20:37:34 +08:00
|
|
|
}
|
|
|
|
|
|
2009-12-28 17:56:58 +08:00
|
|
|
VectorConfig conjugateGradientDescent(const GaussianFactorGraph& fg,
|
2009-12-29 00:15:26 +08:00
|
|
|
const VectorConfig& x, bool verbose, double epsilon, size_t maxIterations) {
|
2009-12-28 20:37:34 +08:00
|
|
|
return conjugateGradients<GaussianFactorGraph, VectorConfig, Errors> (fg,
|
2009-12-29 00:15:26 +08:00
|
|
|
x, verbose, epsilon, maxIterations);
|
2009-12-28 17:56:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ************************************************************************* */
|
|
|
|
|
|
|
|
|
|
} // namespace gtsam
|