667 |
khor |
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 |
|
|
|
11 |
#ifndef __CGLA_STATISTICS_H__
|
|
|
12 |
#define __CGLA_STATISTICS_H__
|
|
|
13 |
|
|
|
14 |
#if (_MSC_VER >= 1200)
|
|
|
15 |
#pragma warning (disable: 4018 4244 4800)
|
|
|
16 |
#endif
|
|
|
17 |
|
|
|
18 |
#include <vector>
|
|
|
19 |
|
|
|
20 |
namespace CGLA
|
|
|
21 |
{
|
|
|
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();
|
|
|
29 |
|
|
|
30 |
return v;
|
|
|
31 |
}
|
|
|
32 |
|
|
|
33 |
|
|
|
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.
|
|
|
37 |
|
|
|
38 |
This template is instantiated for Vec3f, Vec2f, and Vec4f. */
|
|
|
39 |
|
|
|
40 |
template<class VT, class MT>
|
|
|
41 |
VT covariance(const std::vector<VT>& vec, MT& C_out);
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
|
|
|
45 |
|
|
|
46 |
|
|
|
47 |
#endif
|