Subversion Repositories gelsvn

Rev

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

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