Subversion Repositories gelsvn

Rev

Rev 2 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 bj 1
#include "statistics.h"
2
 
3
#include "Mat2x2f.h"
4
#include "Mat3x3f.h"
5
#include "Mat4x4f.h"
6
 
7
using namespace std;
8
 
9
namespace CGLA
10
{
12 jab 11
  template<class VT, class MT>
12
  VT covariance(const vector<VT>& vec, MT& C_out)
13
  {
14
    VT m = mean(vec);
15
    int n = vec.size();
2 bj 16
 
12 jab 17
    MT C(0);
18
    for(int i=0;i<n;++i)
19
      {
20
	MT B;
21
	VT v = vec[i]-m;
22
	outer_product(v,v,B);
2 bj 23
 
12 jab 24
	C += B;
25
      }
26
    C_out = C;
2 bj 27
 
12 jab 28
    return m;
29
  }
2 bj 30
 
12 jab 31
  template 
32
  Vec2f covariance<Vec2f,Mat2x2f>(const vector<Vec2f>& vec, Mat2x2f& C_out);
2 bj 33
 
12 jab 34
  template 
35
  Vec3f covariance<Vec3f,Mat3x3f>(const vector<Vec3f>& vec, Mat3x3f& C_out);
2 bj 36
 
12 jab 37
  template 
38
  Vec4f covariance<Vec4f,Mat4x4f>(const vector<Vec4f>& vec, Mat4x4f& C_out);
2 bj 39
}