Subversion Repositories gelsvn

Rev

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

Rev 595 Rev 630
1
/* ----------------------------------------------------------------------- *
1
/* ----------------------------------------------------------------------- *
2
 * This file is part of GEL, http://www.imm.dtu.dk/GEL
2
 * This file is part of GEL, http://www.imm.dtu.dk/GEL
3
 * Copyright (C) the authors and DTU Informatics
3
 * Copyright (C) the authors and DTU Informatics
4
 * For license and list of authors, see ../../doc/intro.pdf
4
 * For license and list of authors, see ../../doc/intro.pdf
5
 * ----------------------------------------------------------------------- */
5
 * ----------------------------------------------------------------------- */
6
 
6
 
7
/** @file statistics.h
7
/** @file statistics.h
8
 * Compute mean and covariance of CGLA vectors - simple multivariate statistics.
8
 * Compute mean and covariance of CGLA vectors - simple multivariate statistics.
9
 */
9
 */
10
 
10
 
11
#ifndef __CGLA_STATISTICS_H__
11
#ifndef __CGLA_STATISTICS_H__
12
#define __CGLA_STATISTICS_H__
12
#define __CGLA_STATISTICS_H__
13
 
13
 
14
#if (_MSC_VER >= 1200)
14
#if (_MSC_VER >= 1200)
15
#pragma warning (disable: 4018 4244 4800)
15
#pragma warning (disable: 4018 4244 4800)
16
#endif
16
#endif
17
 
17
 
18
#include <vector>
18
#include <vector>
19
 
19
 
20
namespace CGLA
20
namespace CGLA
21
{
21
{
22
		template<class VT>
22
		template<class VT>
23
				VT mean(const std::vector<VT>& vec)
23
				VT mean(const std::vector<VT>& vec)
24
				{
24
				{
25
						VT v(0);
25
						VT v(0);
26
						for(unsigned int i=0;i<vec.size();++i)
26
						for(unsigned int i=0;i<vec.size();++i)
27
								v += vec[i];
27
								v += vec[i];
28
						v /= vec.size();
28
						v /= vec.size();
29
 
29
 
30
						return v;
30
						return v;
31
				}
31
				}
32
 
32
 
33
 
33
 
34
		/** Function that computes the covariance of a set of points.
34
		/** Function that computes the covariance of a set of points.
35
				This function returns the mean, and, upon completion, the
35
				This function returns the mean, and, upon completion, the
36
				final argument contains the covariance matrix.
36
				final argument contains the covariance matrix.
37
 
37
 
38
				This template is instantiated for Vec3f, Vec2f, and Vec4f. */
38
				This template is instantiated for Vec3f, Vec2f, and Vec4f. */
39
			
39
			
40
		template<class VT, class MT>
40
		template<class VT, class MT>
41
				VT covariance(const std::vector<VT>& vec, MT& C_out);
41
				VT covariance(const std::vector<VT>& vec, MT& C_out);
42
}
42
}
43
 
43
 
44
 
44
 
45
 
45
 
46
 
46
 
47
#endif
47
#endif
48
 
48