24 template <
typename Real>
27 public ApprQuery<Real, ApprPolynomialSpecial2<Real>, std::array<Real, 2>>
39 bool Fit(std::vector<std::array<Real, 2>>
const& observations,
40 std::vector<int>
const&
indices);
45 Real
Error(std::array<Real, 2>
const& observation)
const;
57 void Transform(std::vector<std::array<Real, 2>>
const& observations,
58 std::vector<int>
const& indices,
59 std::vector<std::array<Real, 2>>& transformed);
62 bool DoLeastSquares(std::vector<std::array<Real, 2>>& transformed);
81 template <
typename Real>
83 std::vector<int>
const& degrees)
88 #if !defined(GTE_NO_LOGGER) 93 LogAssert(degree > lastDegree,
"Degrees must be increasing.");
98 mXDomain[0] = std::numeric_limits<Real>::max();
100 mWDomain[0] = std::numeric_limits<Real>::max();
111 mXPowers.resize(2 * mDegrees.back() + 1);
115 template <
typename Real>
121 template <
typename Real>
123 std::vector<std::array<Real, 2>>
const& observations,
124 std::vector<int>
const&
indices)
126 if (indices.size() > 0)
129 std::vector<std::array<Real, 2>> transformed;
130 Transform(observations, indices, transformed);
140 template <
typename Real>
142 std::array<Real, 2>
const& observation)
const 145 Real error =
std::abs(w - observation[1]);
149 template <
typename Real>
155 template <
typename Real>
161 template <
typename Real>
169 for (
int j = 1; j <= jmax; ++j)
175 int isup =
static_cast<int>(
mDegrees.size());
176 for (
int i = 0; i < isup; ++i)
187 template <
typename Real>
189 std::vector<std::array<Real, 2>>
const& observations,
190 std::vector<int>
const&
indices,
191 std::vector<std::array<Real, 2>>& transformed)
193 int numSamples =
static_cast<int>(indices.size());
194 transformed.resize(numSamples);
196 std::array<Real, 2> omin = observations[indices[0]];
197 std::array<Real, 2> omax = omin;
198 std::array<Real, 2> obs;
200 for (s = 1; s < numSamples; ++
s)
202 obs = observations[indices[
s]];
203 for (i = 0; i < 2; ++i)
205 if (obs[i] < omin[i])
209 else if (obs[i] > omax[i])
220 for (i = 0; i < 2; ++i)
222 mScale[i] = ((Real)1) / (omax[i] - omin[i]);
225 for (s = 0; s < numSamples; ++
s)
227 obs = observations[indices[
s]];
228 for (i = 0; i < 2; ++i)
230 transformed[
s][i] = (Real)-1 + ((Real)2) *
mScale[i] *
237 template <
typename Real>
239 std::vector<std::array<Real, 2>>& transformed)
249 int numSamples =
static_cast<int>(transformed.size());
250 int twoMaxXDegree = 2 *
mDegrees.back();
252 for (
int i = 0; i < numSamples; ++i)
255 Real
x = transformed[i][0];
256 Real
w = transformed[i][1];
257 for (
int j = 0; j <= twoMaxXDegree; ++j)
262 for (row = 0; row <
size; ++
row)
265 for (col = row; col <
size; ++col)
277 for (row = 0; row <
size; ++
row)
279 for (col = 0; col <
row; ++col)
281 A(row, col) = A(col, row);
286 Real invNumSamples = ((Real)1) / (Real)numSamples;
292 bool hasNonzero =
false;
293 for (
int i = 0; i <
size; ++i)
296 if (coefficients[i] != (Real)0)
std::array< Real, 2 > mScale
std::vector< Real > const & GetParameters() const
bool DoLeastSquares(std::vector< std::array< Real, 2 >> &transformed)
gte::BSNumber< UIntegerType > abs(gte::BSNumber< UIntegerType > const &number)
#define LogAssert(condition, message)
int GetMinimumRequired() const
void Transform(std::vector< std::array< Real, 2 >> const &observations, std::vector< int > const &indices, std::vector< std::array< Real, 2 >> &transformed)
bool Fit(std::vector< std::array< Real, 2 >> const &observations, std::vector< int > const &indices)
GLubyte GLubyte GLubyte GLubyte w
std::array< Real, 2 > mXDomain
GLenum GLenum GLsizei void * row
GLsizei GLenum const void * indices
std::vector< int > mDegrees
ApprPolynomialSpecial2(std::vector< int > const °rees)
std::array< Real, 2 > const & GetXDomain() const
std::array< Real, 2 > mWDomain
std::vector< Real > mXPowers
Quaternion< Real > Inverse(Quaternion< Real > const &d)
Real Evaluate(Real x) const
Real Error(std::array< Real, 2 > const &observation) const
std::vector< Real > mParameters