error_vector
parent
abc268a13d
commit
f91a1f0192
|
@ -126,14 +126,19 @@ bool GaussianFactor::equals(const Factor<VectorConfig>& f, double tol) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
// we might have multiple As, so iterate and subtract from b
|
Vector GaussianFactor::error_vector(const VectorConfig& c) const {
|
||||||
double GaussianFactor::error(const VectorConfig& c) const {
|
Vector e = -b_;
|
||||||
if (empty()) return 0;
|
if (empty()) return e;
|
||||||
Vector e = b_;
|
|
||||||
string j; Matrix Aj;
|
string j; Matrix Aj;
|
||||||
FOREACH_PAIR(j, Aj, As_)
|
FOREACH_PAIR(j, Aj, As_)
|
||||||
e -= Vector(Aj * c[j]);
|
e += Vector(Aj * c[j]);
|
||||||
Vector weighted = ediv(e,sigmas_);
|
return ediv(e,sigmas_);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
double GaussianFactor::error(const VectorConfig& c) const {
|
||||||
|
if (empty()) return 0;
|
||||||
|
Vector weighted = error_vector(c);
|
||||||
return 0.5 * inner_prod(weighted,weighted);
|
return 0.5 * inner_prod(weighted,weighted);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -361,17 +366,14 @@ GaussianFactor::eliminate(const string& key) const
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void GaussianFactor::addGradientContribution(const VectorConfig& x, VectorConfig& g) const {
|
void GaussianFactor::addGradientContribution(const VectorConfig& x, VectorConfig& g) const {
|
||||||
// calculate the value of the factor
|
// calculate the value of the factor
|
||||||
Vector e = -b_;
|
Vector e = GaussianFactor::error_vector(x);
|
||||||
string j; Matrix Aj;
|
Vector et = trans(e); // transpose
|
||||||
FOREACH_PAIR(j, Aj, As_) e += Aj * x[j];
|
|
||||||
|
|
||||||
// transpose
|
|
||||||
Vector et = trans(e);
|
|
||||||
|
|
||||||
// contribute to gradient for each connected variable
|
// contribute to gradient for each connected variable
|
||||||
|
string j; Matrix Aj;
|
||||||
FOREACH_PAIR(j, Aj, As_) {
|
FOREACH_PAIR(j, Aj, As_) {
|
||||||
Vector dj = trans(et*Aj); // this factor's contribution to gradient on j
|
Vector dj = trans(et*Aj); // this factor's contribution to gradient on j
|
||||||
Vector wdj = ediv(dj,emul(sigmas_,sigmas_)); // properly weight by sigmas
|
Vector wdj = ediv(dj,sigmas_); // properly weight by sigmas
|
||||||
g.add(j,wdj);
|
g.add(j,wdj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,6 +117,7 @@ public:
|
||||||
|
|
||||||
// Implementing Factor virtual functions
|
// Implementing Factor virtual functions
|
||||||
|
|
||||||
|
Vector error_vector(const VectorConfig& c) const; /** (A*x-b)/sigma */
|
||||||
double error(const VectorConfig& c) const; /** 0.5*(A*x-b)'*D*(A*x-b) */
|
double error(const VectorConfig& c) const; /** 0.5*(A*x-b)'*D*(A*x-b) */
|
||||||
std::size_t size() const { return As_.size();}
|
std::size_t size() const { return As_.size();}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue