Subversion Repositories gelsvn

Rev

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

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