Subversion Repositories gelsvn

Rev

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

Rev 45 Rev 431
Line 1... Line 1...
1
#include "statistics.h"
1
#include "statistics.h"
2
 
2
 
3
#include "Mat2x2f.h"
3
#include "Mat2x2f.h"
4
#include "Mat3x3f.h"
4
#include "Mat3x3f.h"
5
#include "Mat4x4f.h"
5
#include "Mat4x4f.h"
-
 
6
#include "Mat2x2d.h"
-
 
7
#include "Mat3x3d.h"
-
 
8
#include "Mat4x4d.h"
6
 
9
 
7
using namespace std;
10
using namespace std;
8
 
11
 
9
namespace CGLA
12
namespace CGLA
10
{
13
{
11
		template<class VT, class MT>
14
	template<class VT, class MT>
12
		VT covariance(const vector<VT>& vec, MT& C_out)
15
	VT covariance(const vector<VT>& vec, MT& C_out)
-
 
16
	{
-
 
17
		VT m = mean(vec);
-
 
18
		unsigned int n = vec.size();
-
 
19
		
-
 
20
		MT C(0);
-
 
21
		for(unsigned int i=0;i<n;++i)
13
		{
22
		{
14
				VT m = mean(vec);
-
 
15
				unsigned int n = vec.size();
-
 
16
 
-
 
17
				MT C(0);
-
 
18
				for(unsigned int i=0;i<n;++i)
-
 
19
				{
-
 
20
						MT B;
23
			MT B;
21
						VT v = vec[i]-m;
24
			VT v = vec[i]-m;
22
						outer_product(v,v,B);
25
			outer_product(v,v,B);
23
 
-
 
24
						C += B;
-
 
25
				}
26
			
26
				C_out = C;
27
			C += B;
27
 
-
 
28
				return m;
-
 
29
		}
28
		}
-
 
29
		C_out = C;
-
 
30
		
-
 
31
		return m;
-
 
32
	}
30
 
33
	
31
		template 
34
	template
32
		Vec2f covariance<Vec2f,Mat2x2f>(const vector<Vec2f>& vec, Mat2x2f& C_out);
35
	Vec2f covariance<Vec2f,Mat2x2f>(const vector<Vec2f>& vec, Mat2x2f& C_out);
33
 
36
	
34
		template 
37
	template 
35
		Vec3f covariance<Vec3f,Mat3x3f>(const vector<Vec3f>& vec, Mat3x3f& C_out);
38
	Vec3f covariance<Vec3f,Mat3x3f>(const vector<Vec3f>& vec, Mat3x3f& C_out);
36
 
39
	
37
		template 
40
	template 
38
		Vec4f covariance<Vec4f,Mat4x4f>(const vector<Vec4f>& vec, Mat4x4f& C_out);
41
	Vec4f covariance<Vec4f,Mat4x4f>(const vector<Vec4f>& vec, Mat4x4f& C_out);
-
 
42
	
-
 
43
	template 
-
 
44
	Vec2d covariance<Vec2d,Mat2x2d>(const vector<Vec2d>& vec, Mat2x2d& C_out);
-
 
45
	
-
 
46
	template 
-
 
47
	Vec3d covariance<Vec3d,Mat3x3d>(const vector<Vec3d>& vec, Mat3x3d& C_out);
-
 
48
	
-
 
49
	template 
-
 
50
	Vec4d covariance<Vec4d,Mat4x4d>(const vector<Vec4d>& vec, Mat4x4d& C_out);
39
}
51
}