123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263 |
- #ifndef ALGORITHMS_H
- #define ALGORITHMS_H
- #include "core/vector/ippwrapper.h"
- #include "core/vector/VectorT.h"
- #include "core/vector/MatrixT.h"
- #include "core/vector/RowMatrixT.h"
- #include <cmath>
- namespace NICE {
-
- template<class T>
- inline T mean(const VectorT<T> &v);
-
- template<class T>
- inline T det(const MatrixT<T> &A);
- template<class T>
- void choleskyDecomp ( const MatrixT<T> & A, MatrixT<T> & G, bool resetUpperTriangle = true );
- template<class T>
- void choleskyInvert ( const MatrixT<T> & G, MatrixT<T> & Ainv );
- void choleskyDecompLargeScale ( const Matrix & A, Matrix & G, bool resetUpperTriangle = true );
- void choleskyInvertLargeScale ( const Matrix & G, Matrix & Ainv );
- template<class T>
- void choleskySolve ( const MatrixT<T> & G, const VectorT<T> & b, VectorT<T> & x );
- void choleskySolveLargeScale ( const Matrix & G, const Vector & b, Vector & x );
- void choleskySolveMatrixLargeScale ( const Matrix & G, Matrix & B );
- void triangleSolveMatrix ( const Matrix & G, Matrix & B, bool transposedMatrix = false );
- void triangleSolve ( const Matrix & G, const Vector & x, Vector & b, bool transposedMatrix = false );
- template<class T>
- double triangleMatrixDet ( const MatrixT<T> & G, bool ignoreZero = false );
- template<class T>
- double triangleMatrixLogDet ( const MatrixT<T> & G, bool ignoreZero = false );
-
- template<class T>
- inline T det(const RowMatrixT<T> &A);
-
- template<class T>
- inline void lnIP(VectorT<T> &v);
-
- template<class T>
- inline VectorT<T> *ln(const VectorT<T> &v, VectorT<T> *buffer=NULL);
-
- template<class T>
- inline VectorT<T> *createGaussFunc(float sigma, VectorT<T> *buffer=NULL);
-
- template<class T>
- inline void solveLinearEquationQR(const MatrixT<T> &A, const VectorT<T> &b, VectorT<T> &x);
-
- template<class T>
- inline void solveLinearEquationQR(const RowMatrixT<T> &A, const VectorT<T> &b, VectorT<T> &x);
-
- template<class T>
- inline void solveMDLgreedy(const MatrixT<T> &C, VectorT<T> &h);
- template<class T>
- MatrixT<T> invert(const MatrixT<T>& w);
- template<class T>
- void invert3x3UpperTriangle(MatrixT<T>& w);
- template<class T>
- void invert3x3LowerTriangle(MatrixT<T>& w);
- inline double angleBetweenVectors(
- const Vector& v1, const Vector& v2) {
- const double denominator = v1.normL2() * v2.normL2();
-
- if (isZero(denominator, 1e-16)) {
- return M_PI / 2.0;
- }
- const double arg = v1.scalarProduct(v2) / denominator;
-
- if (arg >= 1.0 && arg < 1.0 + 1e-10) {
- return 0.0;
- } else if (arg <= -1.0 && arg > -1.0 - 1e-10) {
- return -M_PI;
- } else {
- return acos(arg);
- }
- }
- inline double angleBetweenVectorsIgnoringDirection(
- const Vector& v1, const Vector& v2) {
- double a = fabs(v1.scalarProduct(v2) / (v1.normL2() * v2.normL2()));
- if (a > 1.0)
- a = 1.0;
- return acos(a);
- }
- inline double absoluteAngleBetweenVectorsIgnoringDirection(
- const Vector& v1, const Vector& v2) {
- return fabs(angleBetweenVectorsIgnoringDirection(v1, v2));
- }
- }
- #include <core/vector/Algorithms.tcc>
- #endif
|