Subversion Repositories gelsvn

Rev

Rev 431 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 431 Rev 595
-
 
1
/* ----------------------------------------------------------------------- *
-
 
2
 * This file is part of GEL, http://www.imm.dtu.dk/GEL
-
 
3
 * Copyright (C) the authors and DTU Informatics
-
 
4
 * For license and list of authors, see ../../doc/intro.pdf
-
 
5
 * ----------------------------------------------------------------------- */
-
 
6
 
1
#include "statistics.h"
7
#include "statistics.h"
2
 
8
 
3
#include "Mat2x2f.h"
9
#include "Mat2x2f.h"
4
#include "Mat3x3f.h"
10
#include "Mat3x3f.h"
5
#include "Mat4x4f.h"
11
#include "Mat4x4f.h"
6
#include "Mat2x2d.h"
12
#include "Mat2x2d.h"
7
#include "Mat3x3d.h"
13
#include "Mat3x3d.h"
8
#include "Mat4x4d.h"
14
#include "Mat4x4d.h"
9
 
15
 
10
using namespace std;
16
using namespace std;
11
 
17
 
12
namespace CGLA
18
namespace CGLA
13
{
19
{
14
	template<class VT, class MT>
20
	template<class VT, class MT>
15
	VT covariance(const vector<VT>& vec, MT& C_out)
21
	VT covariance(const vector<VT>& vec, MT& C_out)
16
	{
22
	{
17
		VT m = mean(vec);
23
		VT m = mean(vec);
18
		unsigned int n = vec.size();
24
		size_t n = vec.size();
19
		
25
		
20
		MT C(0);
26
		MT C(0);
21
		for(unsigned int i=0;i<n;++i)
27
		for(size_t i=0;i<n;++i)
22
		{
28
		{
23
			MT B;
29
			MT B;
24
			VT v = vec[i]-m;
30
			VT v = vec[i]-m;
25
			outer_product(v,v,B);
31
			outer_product(v,v,B);
26
			
32
			
27
			C += B;
33
			C += B;
28
		}
34
		}
29
		C_out = C;
35
		C_out = C;
30
		
36
		
31
		return m;
37
		return m;
32
	}
38
	}
33
	
39
	
34
	template
40
	template
35
	Vec2f covariance<Vec2f,Mat2x2f>(const vector<Vec2f>& vec, Mat2x2f& C_out);
41
	Vec2f covariance<Vec2f,Mat2x2f>(const vector<Vec2f>& vec, Mat2x2f& C_out);
36
	
42
	
37
	template 
43
	template 
38
	Vec3f covariance<Vec3f,Mat3x3f>(const vector<Vec3f>& vec, Mat3x3f& C_out);
44
	Vec3f covariance<Vec3f,Mat3x3f>(const vector<Vec3f>& vec, Mat3x3f& C_out);
39
	
45
	
40
	template 
46
	template 
41
	Vec4f covariance<Vec4f,Mat4x4f>(const vector<Vec4f>& vec, Mat4x4f& C_out);
47
	Vec4f covariance<Vec4f,Mat4x4f>(const vector<Vec4f>& vec, Mat4x4f& C_out);
42
	
48
	
43
	template 
49
	template 
44
	Vec2d covariance<Vec2d,Mat2x2d>(const vector<Vec2d>& vec, Mat2x2d& C_out);
50
	Vec2d covariance<Vec2d,Mat2x2d>(const vector<Vec2d>& vec, Mat2x2d& C_out);
45
	
51
	
46
	template 
52
	template 
47
	Vec3d covariance<Vec3d,Mat3x3d>(const vector<Vec3d>& vec, Mat3x3d& C_out);
53
	Vec3d covariance<Vec3d,Mat3x3d>(const vector<Vec3d>& vec, Mat3x3d& C_out);
48
	
54
	
49
	template 
55
	template 
50
	Vec4d covariance<Vec4d,Mat4x4d>(const vector<Vec4d>& vec, Mat4x4d& C_out);
56
	Vec4d covariance<Vec4d,Mat4x4d>(const vector<Vec4d>& vec, Mat4x4d& C_out);
51
}
57
}
52
 
58