File: Regression.h

package info (click to toggle)
mldemos 0.5.1-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 32,224 kB
  • ctags: 46,525
  • sloc: cpp: 306,887; ansic: 167,718; ml: 126; sh: 109; makefile: 2
file content (168 lines) | stat: -rw-r--r-- 5,978 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
 * Copyright (C) 2010 Learning Algorithms and Systems Laboratory, EPFL, Switzerland
 * Author: Eric Sauser
 * email:   eric.sauser@a3.epf.ch
 * website: lasa.epfl.ch
 *
 * Permission is granted to copy, distribute, and/or modify this program
 * under the terms of the GNU General Public License, version 2 or any
 * later version published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
 * Public License for more details
 */

#ifndef REGRESSION_H
#define REGRESSION_H
#include "MathLibCommon.h"


#include "Matrix4.h"
#include "Matrix.h"
#include "Vector.h"

#ifdef USE_MATHLIB_NAMESPACE
namespace MathLib {
#endif

/**
 * \class Regression
 * 
 * \ingroup MathLib
 * 
 * \brief A set of regression function
 * 
 */
class Regression
{
private:
	bool Create(int matrixSize, int covarianceMatricesCount);

public:
  /**
   * \brief Do a Hermitte spline fit
   * 
   * \param inData        The input data series
   * \param inTimeBase    The time base of the input data
   * \param outTimeBase   The desired time base for the output data
   * \param outData       The result
   * \return              outData
   */    
	static Vector& HermitteSplineFit(const Vector& inData, const Vector& inTimeBase, const Vector& outTimeBase, Vector& outData);

  /**
   * \brief Do a Hermitte spline fit (multidimensional data at once)
   * 
   * \param inData        The input data series
   * \param inTimeBase    The time base of the input data
   * \param outTimeBase   The desired time base for the output data
   * \param outData       The result
   * \return              outData
   */    
	static Matrix& HermitteSplineFit(const Matrix& inData, const Vector& inTimeBase, const Vector& outTimeBase, Matrix& outData);

  /**
   * \brief Do a Hermitte spline fit assuming constant time steps
   * 
   * \param inData        The input data series
   * \param nbSteps       The desired number of output steps
   * \param outData       The result
   * \return              outData
   */    
	static Vector& HermitteSplineFit(const Vector& inData, int nbSteps, Vector& outData);

  /**
   * \brief Do a Hermitte spline fit assuming constant time steps (multidimensional data at once)
   * 
   * \param inData        The input data series
   * \param nbSteps       The desired number of output steps
   * \param outData       The result
   * \return              outData
   */    
	static Matrix& HermitteSplineFit(const Matrix& inData, int nbSteps, Matrix& outData);
  


	static void SaveData(Matrix &data, const char fileName[]);
	static bool LoadData(const char fileName[], Matrix &result);

	Matrix *covarianceMatrices;
	int covarianceMatricesCount;

  Matrix  covMatInRow;

  Matrix  smoothCovMatrix;


	Regression() : covarianceMatrices(NULL) {}
	~Regression() {Release();}
	void Release();

  /**
   * \brief Do a locally weighted regression (LWR)
   * 
   * Note: the resulting covariance matrices are stored in the class member covarianceMatrices.
   * 
   * \param inData        The input data multidimensional data (a data point is set in a row)
   * \param outData       The output data (the result). The columns indexed by xIndices should be filled with appropriate data. 
   * \param xIndices      An array of indices denoting the columns of the data to be used for the regression  
   * \param xIndicesCount The size of xIndices  
   * \param yIndices      An array of indices denoting the columns of the data to be regressed (guessed...)  
   * \param yIndicesCount The size of yIndices  
   * \param spam          An array of sigmas          
   * \param covSquare     Keep if to false...
   */    
	bool LocallyWeightedRegression(Matrix &inData, Matrix &outData, int xIndices[], int yIndices[], int xIndicesCount, int yIndicesCount, const Matrix &spam, bool covSquare = false);
	
  /**
   * \brief Do a gaussian product of two gaussian sets produced by LocallyWeightedRegression()  
   * 
   * \param data0         The data of the first gaussian set
   * \param data1         The data of the second gaussian set
   * \param yIndices      An array of indices denoting the columns of the data to be regressed (guessed...)  
   * \param yIndicesCount The size of yIndices  
   * \param covarianceMatrices0 A pointer to the covariance matrices of the first gaussian set
   * \param covarianceMatricesCount0 The size of the corresponding array
   * \param covarianceMatrices1 A pointer to the covariance matrices of the second gaussian set
   * \param covarianceMatricesCount1 The size of the corresponding array
   * \param resultData    The result
   * \param resultC       Don't know. Just pass something...
   */    
  bool GaussProduct(
		Matrix &data0,
		Matrix &data1,
		const int yIndices[],
		int yIndicesCount,
		Matrix *covarianceMatrices0,
		int covarianceMatricesCount0,
		Matrix *covarianceMatrices1,
		int covarianceMatricesCount1,
		Matrix &resultData,
		Vector &resultC,
    bool keepAlignment = false, bool pdiff=false,
    Matrix * eigDiff = NULL); 
	void SaveCovarianceMatrices(const char fileName[]);
  
  void SmoothCovarianceMatrices(int window);
  void SetSmoothCovarianceMatrix();
  void SmoothCovarianceMatrix(REALTYPE alpha);

  /**
   * \brief Find the best plane passing through n points
   * 
   * \param inData        The input data series
   * \param nbSteps       The desired number of output steps
   * \param outData       The result
   * \return              outData
   */    
  static Matrix4& GetBestPlaneFromPoints(const Matrix &points, const Vector3& zero, const Vector3& firAxis, const Vector3& secAxis, Matrix4 &out);

};


#ifdef USE_MATHLIB_NAMESPACE
}
#endif
#endif