Subversion Repositories gelsvn

Rev

Rev 431 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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