Xmipp  v3.23.11-Nereus
Static Public Member Functions | List of all members
EquationSystemSolver Class Reference

#include <eq_system_solver.h>

Static Public Member Functions

template<typename T >
static void solve (Matrix1D< T > &bXt, Matrix1D< T > &bYt, Matrix2D< T > &At, Matrix1D< T > &shiftXt, Matrix1D< T > &shiftYt, int verbosity, int iterations)
 

Detailed Description

Definition at line 34 of file eq_system_solver.h.

Member Function Documentation

◆ solve()

template<typename T >
void EquationSystemSolver::solve ( Matrix1D< T > &  bXt,
Matrix1D< T > &  bYt,
Matrix2D< T > &  At,
Matrix1D< T > &  shiftXt,
Matrix1D< T > &  shiftYt,
int  verbosity,
int  iterations 
)
static

Method computes absolute shifts from relative shifts

Parameters
bXrelative shifts in X dim
bYrelative shifts in Y dim
Asystem matrix to be used
shiftXabsolute shifts in X dim
shiftYabsolute shifts in Y dim
verbositylevel
iterationsof the solver

Definition at line 36 of file eq_system_solver.cpp.

38  {
42  helper.bs.resize(2);
43  std::vector<Matrix1D<double>> shifts(2);
47  Matrix1D<double> &shiftX = shifts[0];
48  Matrix1D<double> &shiftY = shifts[1];
49 
50  typeCast(bXt, bX);
51  typeCast(bYt, bY);
52  typeCast(shiftXt, shiftX);
53  typeCast(shiftYt, shiftY);
54 
55  helper.w.resizeNoCopy(VEC_XSIZE(bX));
56  helper.w.initConstant(1);
57 
58  int it = 0;
59  double mean;
60  double varbX;
61  double varbY;
62  bX.computeMeanAndStddev(mean, varbX);
63  varbX *= varbX;
64  bY.computeMeanAndStddev(mean, varbY);
65  varbY *= varbY;
66  if (verbosity > 1)
67  std::cout << "Solving equation system ...\n";
68  do {
69  // Solve the equation system
70  helper.bs[0] = bX;
71  helper.bs[1] = bY;
72  typeCast(At, helper.A);
73  weightedLeastSquares(helper, shifts); // we have updated A, is that OK?
74 
75  // Compute residuals
76  ex = bX - helper.A * shiftX;
77  ey = bY - helper.A * shiftY;
78 
79  // Compute R2
80  double stddeveX;
81  ex.computeMeanAndStddev(mean, stddeveX);
82  double stddeveY;
83  ey.computeMeanAndStddev(mean, stddeveY);
84  double R2x = 1 - (stddeveX * stddeveX) / varbX;
85  double R2y = 1 - (stddeveY * stddeveY) / varbY;
86  if (verbosity > 1)
87  std::cout << "Iteration " << it << " R2x=" << R2x << " R2y=" << R2y
88  << std::endl;
89 
90  // Identify outliers
91  double oldWeightSum = helper.w.sum();
93  if (fabs(VEC_ELEM(ex, i)) > 3 * stddeveX
94  || fabs(VEC_ELEM(ey, i)) > 3 * stddeveY)
95  VEC_ELEM(helper.w, i) = 0.0;
96  }
97  double newWeightSum = helper.w.sum();
98  if ((newWeightSum == oldWeightSum) && (verbosity > 1)){
99  std::cout << "No outlier found\n\n";
100  break;
101  } else if (verbosity > 1)
102  std::cout << "Found " << (int) (oldWeightSum - newWeightSum)
103  << " outliers\n\n";
104 
105  it++;
106  } while (it < iterations);
107 
108  typeCast(shiftX, shiftXt);
109  typeCast(shiftY, shiftYt);
110 }
#define VEC_ELEM(v, i)
Definition: matrix1d.h:245
#define VEC_XSIZE(m)
Definition: matrix1d.h:77
std::vector< Matrix1D< double > > bs
#define i
#define FOR_ALL_ELEMENTS_IN_MATRIX1D(v)
Definition: matrix1d.h:72
double sum(bool average=false) const
Definition: matrix1d.cpp:652
void typeCast(const Matrix1D< T1 > &v1, Matrix1D< T2 > &v2)
Definition: matrix1d.h:1227
void resizeNoCopy(int Xdim)
Definition: matrix1d.h:458
void computeMeanAndStddev(double &mean, double &stddev) const
Definition: matrix1d.cpp:588
void weightedLeastSquares(WeightedLeastSquaresHelper &h, Matrix1D< double > &result)
void initConstant(T val)
Definition: matrix1d.cpp:83

The documentation for this class was generated from the following files: