-
Notifications
You must be signed in to change notification settings - Fork 105
/
functionEncoder.h
191 lines (162 loc) · 5.02 KB
/
functionEncoder.h
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/*
* Copyright (C) 2010 RobotCub Consortium, European Commission FP6 Project IST-004370
* Author: Ugo Pattacini
* email: [email protected]
* website: www.robotcub.org
* 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.
*
* A copy of the license can be found at
* http://www.robotcub.org/icub/license/gpl.txt
*
* 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
*/
/**
* \defgroup functionEncoder Functions Encoding
*
* @ingroup ctrlLib
*
* Classes for encoding functions.
*
* \author Ugo Pattacini
*
*/
#ifndef __FUNCTIONENCODER_H__
#define __FUNCTIONENCODER_H__
#include <yarp/os/Property.h>
#include <yarp/sig/Vector.h>
namespace iCub
{
namespace ctrl
{
/**
* \ingroup functionEncoder
*
* Code.
*/
struct Code
{
/**
* The vector of coefficients encoding the function.
*/
yarp::sig::Vector coefficients;
};
/**
* \ingroup functionEncoder
*
* Abstract class to deal with function encoding.
*/
class FunctionEncoder
{
public:
/**
* Configure the encoder.
* @param options encoder's options in form of a Property object.
* @return true/false on success/fail.
*/
virtual bool setEncoderOptions(const yarp::os::Property &options) = 0;
/**
* Retrieve the encoder's configuration options.
* @return a Property object containing the encoder's options.
*/
virtual yarp::os::Property getEncoderOptions() = 0;
/**
* Encode the function.
* @param values is the vector containing the samples of function
* \b f to be encoded. The \e x coordinates of the
* points are intended to be normalized in [0,1], so
* that f(0)=values[0] and
* f(1)=values[values.length()-1].
* @return the code encoding the function \b f.
*/
virtual Code encode(const yarp::sig::Vector &values) = 0;
/**
* Compute the approximated value of function in \b x, given the
* code.
* @param code contains the function representation in the
* vector space.
* @param x is the point at which the result is computed. It
* shall be in [0,1].
* @return the decoded function value.
*/
virtual double decode(const Code &code, const double x) = 0;
/**
* Destructor.
*/
virtual ~FunctionEncoder() { }
};
/**
* \ingroup functionEncoder
*
* Encode any given function as a set of wavelet coefficients.
* The father wavelet used here is the \b db4.
*/
class WaveletEncoder : public FunctionEncoder
{
protected:
void *w;
void *F;
const yarp::sig::Vector *pVal;
unsigned int iCoeff;
double resolution;
double interpWavelet(const double x);
double interpFunction(const yarp::sig::Vector &values, const double x);
friend double waveletIntegrand(double, void*);
public:
/**
* Constructor.
*/
WaveletEncoder();
/**
* Configure the encoder.
* @param options lets user specify the resolution R to which the
* encoding is computed. Accepted options are of
* the form ("resolution" <double>).
* @return true/false on success/fail.
*
* @note It holds that N=floor(R)+1, where N is the number of
* coefficients of the vector space. Recap that floor(.) is
* the round function towards minus infinity.
*/
virtual bool setEncoderOptions(const yarp::os::Property &options);
/**
* Retrieve the encoder's configuration options.
* @return a Property object containing the encoder options.
*/
virtual yarp::os::Property getEncoderOptions();
/**
* Encode the function.
* @param values is the vector containing the samples of function
* \b f to be encoded. The \e x coordinates of the
* points are intended to be normalized in [0,1], so
* that f(0)=values[0] and
* f(1)=values[values.length()-1].
* @return the code containing the computed 1+N coefficients,
* with the first one being f(0) and the following N are
* the actual wavelet expansion coefficients.
*/
virtual Code encode(const yarp::sig::Vector &values);
/**
* Compute the approximated value of function in \b x, given the
* input set of wavelet coefficients.
* @param code contains wavelet coefficients vector along with
* the first initial value f(0).
* @param x is the point at which the result is computed. It
* shall be in [0,1].
* @return the decoded function value.
*
* @note It shall hold that coefficients.length()>=floor(R)+2.
*/
virtual double decode(const Code &code, const double x);
/**
* Destructor.
*/
virtual ~WaveletEncoder();
};
}
}
#endif