Xmipp  v3.23.11-Nereus
Classes | Functions
Numerical Tools
Collaboration diagram for Numerical Tools:

Classes

class  GaussianInterpolator
 

Functions

void randomPermutation (int N, MultidimArray< int > &result)
 
void powellOptimizer (Matrix1D< double > &p, int i0, int n, double(*f)(double *, void *), void *prm, double ftol, double &fret, int &iter, const Matrix1D< double > &steps, bool show=false)
 
double solveNonNegative (const Matrix2D< double > &A, const Matrix1D< double > &b, Matrix1D< double > &result)
 
void solveViaCholesky (const Matrix2D< double > &A, const Matrix1D< double > &b, Matrix1D< double > &result)
 
void evaluateQuadratic (const Matrix1D< double > &x, const Matrix1D< double > &c, const Matrix2D< double > &H, double &val, Matrix1D< double > &grad)
 
void quadraticProgramming (const Matrix2D< double > &C, const Matrix1D< double > &d, const Matrix2D< double > &A, const Matrix1D< double > &b, const Matrix2D< double > &Aeq, const Matrix1D< double > &beq, Matrix1D< double > &bl, Matrix1D< double > &bu, Matrix1D< double > &x)
 
void leastSquare (const Matrix2D< double > &C, const Matrix1D< double > &d, const Matrix2D< double > &A, const Matrix1D< double > &b, const Matrix2D< double > &Aeq, const Matrix1D< double > &beq, Matrix1D< double > &bl, Matrix1D< double > &bu, Matrix1D< double > &x)
 
void regularizedLeastSquare (const Matrix2D< double > &A, const Matrix1D< double > &d, double lambda, const Matrix2D< double > &G, Matrix1D< double > &x)
 
template<typename T >
void solve (const Matrix2D< T > &A, const Matrix1D< T > &b, Matrix1D< T > &result)
 
template<typename T >
void solveBySVD (const Matrix2D< T > &A, const Matrix1D< T > &b, Matrix1D< double > &result, double tolerance)
 
template<typename T >
void solve (const Matrix2D< T > &A, const Matrix2D< T > &b, Matrix2D< T > &result)
 

Detailed Description

Function Documentation

◆ evaluateQuadratic()

void evaluateQuadratic ( const Matrix1D< double > &  x,
const Matrix1D< double > &  c,
const Matrix2D< double > &  H,
double &  val,
Matrix1D< double > &  grad 
)

Evaluate quadratic form

Given x, c and H this function returns the value of the quadratic form val=c^t*x+0.5*x^t*H^t*H*x and the gradient of the quadratic form at x grad=c+H*x.

Exceptions are thrown if the vectors and matrices do not have consistent dimensions.

Definition at line 126 of file numerical_tools.cpp.

128 {
129  if (x.size() != c.size())
130  REPORT_ERROR(ERR_MATRIX_SIZE, "Eval_quadratic: Not compatible sizes in x and c");
131  if (H.Xdim() != x.size())
132  REPORT_ERROR(ERR_MATRIX_SIZE, "Eval_quadratic: Not compatible sizes in x and H");
133 
134  // H*x, store in grad
135  grad.initZeros(x.size());
136  for (size_t i = 0; i < H.Ydim(); i++)
137  for (size_t j = 0; j < x.size(); j++)
138  grad(i) += H(i, j) * x(j);
139 
140  // Now, compute c^t*x+1/2*x^t*H*x
141  // Add c to the gradient
142  double quad = 0;
143  val = 0;
144  for (size_t j = 0; j < x.size(); j++)
145  {
146  quad += grad(j) * grad(j); // quad=x^t*H^t*H*x
147  val += c(j) * x(j); // val=c^t*x
148 
149  grad(j) += c(j); // grad+=c
150  }
151  val += 0.5 * quad;
152 }
size_t Xdim() const
Definition: matrix2d.h:575
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
size_t size() const
Definition: matrix1d.h:508
Problem with matrix size.
Definition: xmipp_error.h:152
doublereal * c
doublereal * grad
doublereal * x
#define i
size_t Ydim() const
Definition: matrix2d.h:584
void initZeros()
Definition: matrix1d.h:592
#define j

◆ leastSquare()

void leastSquare ( const Matrix2D< double > &  C,
const Matrix1D< double > &  d,
const Matrix2D< double > &  A,
const Matrix1D< double > &  b,
const Matrix2D< double > &  Aeq,
const Matrix1D< double > &  beq,
Matrix1D< double > &  bl,
Matrix1D< double > &  bu,
Matrix1D< double > &  x 
)

Solves the least square problem

min 0.5*(Norm(C*x-d)) subject to: A*x <= b
x Aeq*x=beq
bl<=x<=bu

Definition at line 322 of file numerical_tools.cpp.

327 {
328  // Convert d to Matrix2D for multiplication
330  P.fromVector(d);
331  P = -2.0 * (P.transpose() * C);
332  P = P.transpose();
333 
334  //Convert back to vector for passing it to quadraticProgramming
335  Matrix1D<double> newd;
336  P.toVector(newd);
337 
338  quadraticProgramming(C.transpose()*C, newd, A, b, Aeq, beq, bl, bu, x);
339 }
void fromVector(const Matrix1D< T > &op1)
Definition: matrix2d.cpp:803
double * bl
void toVector(Matrix1D< T > &op1) const
Definition: matrix2d.cpp:832
Matrix2D< T > transpose() const
Definition: matrix2d.cpp:1314
doublereal * x
double * bu
doublereal * b
void quadraticProgramming(const Matrix2D< double > &C, const Matrix1D< double > &d, const Matrix2D< double > &A, const Matrix1D< double > &b, const Matrix2D< double > &Aeq, const Matrix1D< double > &beq, Matrix1D< double > &bl, Matrix1D< double > &bu, Matrix1D< double > &x)

◆ powellOptimizer()

void powellOptimizer ( Matrix1D< double > &  p,
int  i0,
int  n,
double(*)(double *, void *)  f,
void *  prm,
double  ftol,
double &  fret,
int &  iter,
const Matrix1D< double > &  steps,
bool  show = false 
)

Optimize using Powell's method.

See Numerical Recipes Chapter 10.

Problem: Minimize f(x) starting at point p. n is the dimension of x. If changes are smaller than ftol then stop. The number of iterations is returned in iter, fret contains the function value at the minimum and p contains the minimum.

Watch out that the evaluating function f must consider that x starts at index 1, at least, and goes until n. i0 is used to allow optimization in large spaces where only one part is going to be optimized. Thus, if in a vector of dimension 20 you want to optimize the first 3 components then i0=1, n=3; if you want to optimize it all, i0=1, n=20; and if you want to optimize the last five components i0=15, n=5.

The steps define the allowed steps on each variable. When a variable has large ranges this step should be larger to allow bigger movements. The steps should have only the dimension of the optimized part (3,20 and 5 in the examples above).

The option show forces the routine to show the convergence path

If your function needs extra parameters you can pass them through the void pointer prm. If you don't need this feature set it to NULL.

Example of use:

double fitness;
int iter;
steps.initConstant(1);
powellOptimizer(x,1,8,&wrapperFitness,NULL,0.01,fitness,iter,steps,true);

◆ quadraticProgramming()

void quadraticProgramming ( const Matrix2D< double > &  C,
const Matrix1D< double > &  d,
const Matrix2D< double > &  A,
const Matrix1D< double > &  b,
const Matrix2D< double > &  Aeq,
const Matrix1D< double > &  beq,
Matrix1D< double > &  bl,
Matrix1D< double > &  bu,
Matrix1D< double > &  x 
)

Solves Quadratic programming subproblem

min 0.5*x'Cx + d'x subject to: A*x <= b
x Aeq*x=beq
bl<=x<=bu

Definition at line 222 of file numerical_tools.cpp.

227 {
228  CDAB prm;
229  prm.C = C;
230  prm.D.fromVector(d);
231  prm.A.initZeros(A.Ydim() + Aeq.Ydim(), A.Xdim());
232  prm.B.initZeros(prm.A.Ydim(), 1);
233 
234 
235  // Copy Inequalities
236  for (size_t i = 0; i < A.Ydim(); i++)
237  {
238  for (size_t j = 0; j < A.Xdim(); j++)
239  prm.A(i, j) = A(i, j);
240  prm.B(i, 0) = b(i);
241  }
242 
243  // Copy Equalities
244  for (size_t i = 0; i < Aeq.Ydim(); i++)
245  {
246  for (size_t j = 0; j < Aeq.Xdim(); j++)
247  prm.A(i + A.Ydim(), j) = Aeq(i, j);
248  prm.B(i + A.Ydim(), 0) = beq(i);
249  }
250 
251  double bigbnd = 1e30;
252  // Bounds
253  if (bl.size() == 0)
254  {
255  bl.resize(C.Xdim());
256  bl.initConstant(-bigbnd);
257  }
258  if (bu.size() == 0)
259  {
260  bu.resize(C.Xdim());
261  bu.initConstant(bigbnd);
262  }
263 
264  // Define intermediate variables
265  int mode = 100; // CFSQP mode
266  int iprint = 0; // Debugging
267  int miter = 1000; // Maximum number of iterations
268  double eps = 1e-4; // Epsilon
269  double epsneq = 1e-4; // Epsilon for equalities
270  double udelta = 0.e0; // Finite difference approximation
271  // of the gradients. Not used in this function
272  int nparam = C.Xdim(); // Number of variables
273  int nf = 1; // Number of objective functions
274  int neqn = Aeq.Ydim(); // Number of nonlinear equations
275  int nineqn = A.Ydim(); // Number of nonlinear inequations
276  int nineq = A.Ydim(); // Number of linear inequations
277  int neq = Aeq.Ydim(); // Number of linear equations
278  int inform;
279  int ncsrl = 0;
280  int ncsrn = 0;
281  int nfsr = 0;
282  int mesh_pts[] = {0};
283 
284  if (x.size() == 0)
285  x.initZeros(nparam);
286  Matrix1D<double> f(nf);
287  Matrix1D<double> g(nineq + neq);
288  Matrix1D<double> lambda(nineq + neq + nf + nparam);
289 
290  // Call the minimization routine
291  cfsqp(nparam, nf, nfsr, nineqn, nineq, neqn, neq, ncsrl, ncsrn, mesh_pts,
292  mode, iprint, miter, &inform, bigbnd, eps, epsneq, udelta,
294  MATRIX1D_ARRAY(x),
297  // quadprg_obj32,quadprog_cntr32,quadprog_grob32,quadprog_grcn32,
299  (void*)&prm);
300 
301 #ifdef DEBUG
302 
303  if (inform == 0)
304  std::cout << "SUCCESSFUL RETURN. \n";
305  if (inform == 1 || inform == 2)
306  std::cout << "\nINITIAL GUESS INFEASIBLE.\n";
307  if (inform == 3)
308  printf("\n MAXIMUM NUMBER OF ITERATIONS REACHED.\n");
309  if (inform > 3)
310  printf("\ninform=%d\n", inform);
311 #endif
312 }
size_t Xdim() const
Definition: matrix2d.h:575
void nineq
void grobfd()
size_t size() const
Definition: matrix1d.h:508
void fromVector(const Matrix1D< T > &op1)
Definition: matrix2d.cpp:803
doublereal * g
Matrix2D< double > A
void quadraticProgramming_cntr32(int nparam, int j, double *x, double *gj, void *cd)
static void nparam
double udelta
void nfsr
void * mesh_pts
Matrix2D< double > B
cmache_1 eps
integer * iprint
void nineqn
#define i
Matrix2D< double > C
void miter
doublereal * b
void nf
double bigbnd
void cfsqp(nparam, nf, nfsr, nineqn, nineq, neqn, neq, ncsrl, ncsrn, mesh_pts, mode, iprint, miter, inform, bigbnd, eps, epseqn, udelta, bl, bu, x, f, g, lambda, obj, constr, gradob, gradcn, cd) int nparam
double * lambda
double * f
void resize(size_t Xdim, bool copy=true)
Definition: matrix1d.h:410
void ncsrn
void neqn
size_t Ydim() const
Definition: matrix2d.h:584
Matrix2D< double > D
void ncsrl
void mode
void quadraticProgramming_obj32(int nparam, int j, double *x, double *fj, void *cd)
void initZeros()
Definition: matrix1d.h:592
#define j
#define MATRIX1D_ARRAY(v)
Definition: matrix1d.h:58
void neq
void initZeros()
Definition: matrix2d.h:626
void * inform
ProgClassifyCL2D * prm
void initConstant(T val)
Definition: matrix1d.cpp:83
void grcnfd()

◆ randomPermutation()

void randomPermutation ( int  N,
MultidimArray< int > &  result 
)

Generate random permutation

Generate a random permutation of the numbers between 0 and N-1

Definition at line 33 of file numerical_tools.cpp.

34 {
36  aux.resize(N);
37  aux.initRandom(0,1);
38 
39  aux.indexSort(result);
40  result-=1;
41 }
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
void initRandom(double op1, double op2, RandomMode mode=RND_UNIFORM)
void indexSort(MultidimArray< int > &indx) const

◆ regularizedLeastSquare()

void regularizedLeastSquare ( const Matrix2D< double > &  A,
const Matrix1D< double > &  d,
double  lambda,
const Matrix2D< double > &  G,
Matrix1D< double > &  x 
)

Solves the regularized least squares problem

min Norm(A*x-d) + lambda * norm (G*x)

Give an empty G matrix (NULL matrix) if G is the identity matrix If AtA is not a NULL matrix, then the product AtA is not computed.

Definition at line 342 of file numerical_tools.cpp.

345 {
346  int Nx=A.Xdim(); // Number of variables
347 
348  Matrix2D<double> X(Nx,Nx); // X=(A^t * A +lambda *G^t G)
349  // Compute A^t*A
351  // Compute the dot product of the i-th and j-th columns of A
352  for (size_t k=0; k<A.Ydim(); k++)
353  X(i,j) += A(k,i) * A(k,j);
354 
355  // Compute lambda*G^t*G
356  if (G.Xdim()==0)
357  for (int i=0; i<Nx; i++)
358  X(i,i)+=lambda;
359  else
361  // Compute the dot product of the i-th and j-th columns of G
362  for (size_t k=0; k<G.Ydim(); k++)
363  X(i,j) += G(k,i) * G(k,j);
364 
365  // Compute A^t*d
366  Matrix1D<double> Atd(Nx);
368  // Compute the dot product of the i-th column of A and d
369  for (size_t k=0; k<A.Ydim(); k++)
370  Atd(i) += A(k,i) * d(k);
371 
372  // Compute the inverse of X
373  Matrix2D<double> Xinv;
374  X.inv(Xinv);
375 
376  // Now multiply Xinv * A^t * d
377  matrixOperation_Ax(Xinv, Atd, x);
378 }
#define FOR_ALL_ELEMENTS_IN_MATRIX2D(m)
Definition: matrix2d.h:104
size_t Xdim() const
Definition: matrix2d.h:575
void inv(Matrix2D< T > &result) const
Definition: matrix2d.cpp:663
#define i
ql0001_ & k(htemp+1),(cvec+1),(atemp+1),(bj+1),(bl+1),(bu+1),(x+1),(clamda+1), &iout, infoqp, &zero,(w+1), &lenw,(iw+1), &leniw, &glob_grd.epsmac
doublereal * d
#define FOR_ALL_ELEMENTS_IN_MATRIX1D(v)
Definition: matrix1d.h:72
double * lambda
size_t Ydim() const
Definition: matrix2d.h:584
void matrixOperation_Ax(const Matrix2D< double > &A, const Matrix1D< double > &x, Matrix1D< double > &y)
Definition: matrix2d.cpp:424
#define j

◆ solve() [1/2]

template<typename T >
void solve ( const Matrix2D< T > &  A,
const Matrix1D< T > &  b,
Matrix1D< T > &  result 
)

Solves a linear equation system by LU decomposition.

Definition at line 215 of file numerical_tools.h.

216 {
217  if (MAT_XSIZE(A) == 0)
218  REPORT_ERROR(ERR_MATRIX_EMPTY, "Solve: Matrix is empty");
219 
220  if (MAT_XSIZE(A) != MAT_YSIZE(A))
221  REPORT_ERROR(ERR_MATRIX_SIZE, "Solve: Matrix is not squared");
222 
223  if (MAT_XSIZE(A) != b.size())
224  REPORT_ERROR(ERR_MATRIX_SIZE, "Solve: Different sizes of Matrix and Vector");
225 
226  if (b.isRow())
227  REPORT_ERROR(ERR_MATRIX_DIM, "Solve: Not correct vector shape");
228 
229  // Perform LU decomposition and then solve
230  Matrix1D< int > indx;
231  T d;
232  Matrix2D<T> LU;
233  ludcmp(A, LU, indx, d);
234  result = b;
235  lubksb(LU, indx, result);
236 }
#define MAT_YSIZE(m)
Definition: matrix2d.h:124
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
size_t size() const
Definition: matrix1d.h:508
Problem with matrix size.
Definition: xmipp_error.h:152
The matrix is empty.
Definition: xmipp_error.h:151
doublereal * d
Definition: mask.h:36
doublereal * b
void lubksb(const Matrix2D< T > &LU, Matrix1D< int > &indx, Matrix1D< T > &b)
Definition: matrix2d.cpp:596
int isRow() const
Definition: matrix1d.h:520
Problem with matrix dimensions.
Definition: xmipp_error.h:150
void ludcmp(const Matrix2D< T > &A, Matrix2D< T > &LU, Matrix1D< int > &indx, T &d)
Definition: matrix2d.cpp:586
#define MAT_XSIZE(m)
Definition: matrix2d.h:120

◆ solve() [2/2]

template<typename T >
void solve ( const Matrix2D< T > &  A,
const Matrix2D< T > &  b,
Matrix2D< T > &  result 
)

Solves a linear equation system by Gaussian elimination.

Definition at line 2218 of file numerical_tools.cpp.

2219 {
2220  if (A.Xdim() == 0)
2221  REPORT_ERROR(ERR_MATRIX_EMPTY, "Solve: Matrix is empty");
2222 
2223  if (A.Xdim() != A.Ydim())
2224  REPORT_ERROR(ERR_MATRIX_SIZE, "Solve: Matrix is not squared");
2225 
2226  if (A.Ydim() != b.Ydim())
2227  REPORT_ERROR(ERR_MATRIX_SIZE, "Solve: Different sizes of A and b");
2228 
2229  // Solve
2230  result = b;
2231  Matrix2D<T> Aux = A;
2232  gaussj(Aux.adaptForNumericalRecipes2(), Aux.Ydim(),
2233  result.adaptForNumericalRecipes2(), b.Xdim());
2234 }
size_t Xdim() const
Definition: matrix2d.h:575
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
Problem with matrix size.
Definition: xmipp_error.h:152
The matrix is empty.
Definition: xmipp_error.h:151
T * adaptForNumericalRecipes2() const
Definition: matrix2d.h:875
void gaussj(T *a, int n, T *b, int m)
Definition: mask.h:36
doublereal * b
size_t Ydim() const
Definition: matrix2d.h:584

◆ solveBySVD()

template<typename T >
void solveBySVD ( const Matrix2D< T > &  A,
const Matrix1D< T > &  b,
Matrix1D< double > &  result,
double  tolerance 
)

Solves a linear equation system by SVD decomposition.

Definition at line 2179 of file numerical_tools.cpp.

2181 {
2182  if (A.Xdim() == 0)
2183  REPORT_ERROR(ERR_MATRIX_EMPTY, "Solve: Matrix is empty");
2184 
2185  if (A.Xdim() != A.Ydim())
2186  REPORT_ERROR(ERR_MATRIX_SIZE, "Solve: Matrix is not squared");
2187 
2188  if (A.Xdim() != b.size())
2189  REPORT_ERROR(ERR_MATRIX_SIZE, "Solve: Different sizes of Matrix and Vector");
2190 
2191  if (b.isRow())
2192  REPORT_ERROR(ERR_MATRIX_DIM, "Solve: Not correct vector shape");
2193 
2194  // First perform de single value decomposition
2195  // Xmipp interface that calls to svdcmp of numerical recipes
2199  svdcmp(A, u, w, v);
2200 
2201  // Here is checked if eigenvalues of the svd decomposition are acceptable
2202  // If a value is lower than tolerance, the it's zeroed, as this increases
2203  // the precision of the routine.
2204  for (int i = 0; i < w.size(); i++)
2205  if (w(i) < tolerance)
2206  w(i) = 0;
2207 
2208  // Set size of matrices
2209  result.resize(b.size());
2210 
2211  // Xmipp interface that calls to svdksb of numerical recipes
2212  Matrix1D< double > bd;
2213  typeCast(b, bd);
2214  svbksb(u, w, v, bd, result);
2215 }
size_t Xdim() const
Definition: matrix2d.h:575
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
size_t size() const
Definition: matrix1d.h:508
Problem with matrix size.
Definition: xmipp_error.h:152
The matrix is empty.
Definition: xmipp_error.h:151
doublereal * w
#define i
int isRow() const
Definition: matrix1d.h:520
Problem with matrix dimensions.
Definition: xmipp_error.h:150
void resize(size_t Xdim, bool copy=true)
Definition: matrix1d.h:410
size_t Ydim() const
Definition: matrix2d.h:584
void svdcmp(const Matrix2D< T > &a, Matrix2D< double > &u, Matrix1D< double > &w, Matrix2D< double > &v)
Definition: matrix2d.cpp:125
void typeCast(const Matrix1D< T1 > &v1, Matrix1D< T2 > &v2)
Definition: matrix1d.h:1227
doublereal * u
void svbksb(Matrix2D< double > &u, Matrix1D< double > &w, Matrix2D< double > &v, Matrix1D< double > &b, Matrix1D< double > &x)
Definition: matrix2d.cpp:174

◆ solveNonNegative()

double solveNonNegative ( const Matrix2D< double > &  A,
const Matrix1D< double > &  b,
Matrix1D< double > &  result 
)

Solve equation system, nonnegative solution

The equation system is defined by Ax=b, it is solved for x. x is forced to be nonnegative. It is designed to cope with large equation systems. This function is borrowed from LAPACK nnls.

The norm of the vector Ax-b is returned.

Definition at line 82 of file numerical_tools.cpp.

84 {
85  if (C.Xdim() == 0)
86  REPORT_ERROR(ERR_MATRIX_EMPTY, "Solve_nonneg: Matrix is empty");
87  if (C.Ydim() != d.size())
88  REPORT_ERROR(ERR_MATRIX_SIZE, "Solve_nonneg: Different sizes of Matrix and Vector");
89  if (d.isRow())
90  REPORT_ERROR(ERR_MATRIX_DIM, "Solve_nonneg: Not correct vector shape");
91 
93  Ct=C.transpose();
94 
95  result.initZeros(Ct.Ydim());
96  double rnorm;
97 
98  // Watch out that matrix Ct is transformed.
99  int success = nnls(MATRIX2D_ARRAY(Ct), Ct.Xdim(), Ct.Ydim(),
100  MATRIX1D_ARRAY(d),
101  MATRIX1D_ARRAY(result),
102  &rnorm, nullptr, nullptr, nullptr);
103  if (success == 1)
104  std::cerr << "Warning, too many iterations in nnls\n";
105  else if (success == 2)
106  REPORT_ERROR(ERR_MEM_NOTENOUGH, "Solve_nonneg: Not enough memory");
107  return rnorm;
108 }
size_t Xdim() const
Definition: matrix2d.h:575
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
Problem with matrix size.
Definition: xmipp_error.h:152
There is not enough memory for allocation.
Definition: xmipp_error.h:166
The matrix is empty.
Definition: xmipp_error.h:151
Matrix2D< T > transpose() const
Definition: matrix2d.cpp:1314
doublereal * d
Problem with matrix dimensions.
Definition: xmipp_error.h:150
size_t Ydim() const
Definition: matrix2d.h:584
void initZeros()
Definition: matrix1d.h:592
#define MATRIX1D_ARRAY(v)
Definition: matrix1d.h:58
int nnls(double *a, int m, int n, double *b, double *x, double *rnorm, double *wp, double *zzp, int *indexp)
#define MATRIX2D_ARRAY(m)
Definition: matrix2d.h:89

◆ solveViaCholesky()

void solveViaCholesky ( const Matrix2D< double > &  A,
const Matrix1D< double > &  b,
Matrix1D< double > &  result 
)

Solve equation system, symmetric positive-definite matrix

The equation system is defined by Ax=b, it is solved for x. This method can only be applied if A is positive-definite matrix and symmetric. It applies a Cholesky factorization and backsubstitution (see Numerical Recipes).

Definition at line 111 of file numerical_tools.cpp.

113 {
114  Matrix2D<double> Ap = A;
115  Matrix1D<double> p(A.Xdim());
116  result.resize(A.Xdim());
118  p.adaptForNumericalRecipes());
120  p.adaptForNumericalRecipes(), b.adaptForNumericalRecipes(),
121  result.adaptForNumericalRecipes());
122 }
void cholsl(double *a, int n, double *p, double *b, double *x)
size_t Xdim() const
Definition: matrix2d.h:575
void choldc(double *a, int n, double *p)
T * adaptForNumericalRecipes2() const
Definition: matrix2d.h:875
void resize(size_t Xdim, bool copy=true)
Definition: matrix1d.h:410
T * adaptForNumericalRecipes() const
Definition: matrix1d.h:844