Subversion Repositories gelsvn

Rev

Rev 136 | 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
 
7
/** @file statistics.h
8
 * Compute mean and covariance of CGLA vectors - simple multivariate statistics.
9
 */
10
 
2 bj 11
#ifndef __CGLA_STATISTICS_H__
12
#define __CGLA_STATISTICS_H__
13
 
102 bj 14
#if (_MSC_VER >= 1200)
15
#pragma warning (disable: 4018 4244 4800)
16
#endif
17
 
2 bj 18
#include <vector>
19
 
20
namespace CGLA
21
{
136 jab 22
		template<class VT>
23
				VT mean(const std::vector<VT>& vec)
24
				{
25
						VT v(0);
26
						for(unsigned int i=0;i<vec.size();++i)
27
								v += vec[i];
28
						v /= vec.size();
2 bj 29
 
136 jab 30
						return v;
31
				}
2 bj 32
 
33
 
136 jab 34
		/** Function that computes the covariance of a set of points.
35
				This function returns the mean, and, upon completion, the
36
				final argument contains the covariance matrix.
2 bj 37
 
136 jab 38
				This template is instantiated for Vec3f, Vec2f, and Vec4f. */
2 bj 39
 
136 jab 40
		template<class VT, class MT>
41
				VT covariance(const std::vector<VT>& vec, MT& C_out);
2 bj 42
}
43
 
44
 
45
 
46
 
47
#endif