Subversion Repositories gelsvn

Rev

Rev 45 | 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"
431 jab 6
#include "Mat2x2d.h"
7
#include "Mat3x3d.h"
8
#include "Mat4x4d.h"
2 bj 9
 
10
using namespace std;
11
 
12
namespace CGLA
13
{
431 jab 14
	template<class VT, class MT>
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)
45 jab 22
		{
431 jab 23
			MT B;
24
			VT v = vec[i]-m;
25
			outer_product(v,v,B);
26
 
27
			C += B;
45 jab 28
		}
431 jab 29
		C_out = C;
30
 
31
		return m;
32
	}
33
 
34
	template
35
	Vec2f covariance<Vec2f,Mat2x2f>(const vector<Vec2f>& vec, Mat2x2f& C_out);
36
 
37
	template 
38
	Vec3f covariance<Vec3f,Mat3x3f>(const vector<Vec3f>& vec, Mat3x3f& C_out);
39
 
40
	template 
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);
2 bj 51
}