Subversion Repositories gelsvn

Rev

Rev 2 | Rev 431 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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