22template <
int Dimensions,
class Element =
double>
80template <
int Dimensions,
class Element>
86template <
int Dimensions,
class Element>
88: m_coefficients(coefficients)
93template <
int Dimensions,
class Element>
96 return m_coefficients;
100template <
int Dimensions,
class Element>
103 m_coefficients = coefficients;
107template <
int Dimensions,
class Element>
118 m_coefficients.
SetSizes(coeffGridSize);
127 for (
int matrixRow = 0; matrixRow < count; ++matrixRow){
129 double measValue = double(destValues[matrixRow]);
134 double baseValue = GetBaseFunctionValue(argument, coeffIndex);
137 }
while (coeffIndex.
Increase(coeffGridSize));
143 if (!valueMatrix.
GetSolvedLSP(destValueVector, resultMatrix)){
148 m_coefficients.SetSizes(coeffGridSize);
154 }
while (coeffIndex.
Increase(coeffGridSize));
162template <
int Dimensions,
class Element>
171template <
int Dimensions,
class Element>
177 CumulateRecursiveValueAt(argument, Dimensions - 1, index, retVal);
186 double partArgument = argument[0];
187 int dimensionSize = m_coefficients.GetSize(0);
192 int& indexElement = index[0];
193 for (indexElement = dimensionSize - 1; indexElement >= 0; --indexElement){
194 result = result * partArgument + m_coefficients.
GetAt(index);
204 double partArgument1 = argument[0];
205 double partArgument2 = argument[1];
207 int dimensionSize1 = m_coefficients.GetSize(0);
208 int dimensionSize2 = m_coefficients.GetSize(1);
213 int& indexElement1 = index[0];
214 int& indexElement2 = index[1];
216 if (dimensionSize1 == 1){
218 for (indexElement2 = dimensionSize2 - 1; indexElement2 >= 0; --indexElement2){
219 result = result * partArgument2 + m_coefficients.
GetAt(index);
223 for (indexElement2 = dimensionSize2 - 1; indexElement2 >= 0; --indexElement2){
224 indexElement1 = dimensionSize1 - 1;
225 ResultType partResult = m_coefficients.GetAt(index);
227 for (indexElement1 = dimensionSize1 - 2; indexElement1 >= 0; --indexElement1){
228 partResult = partResult * partArgument1 + m_coefficients.GetAt(index);
231 result = result * partArgument2 + partResult;
242 double partArgument1 = argument[0];
243 double partArgument2 = argument[1];
244 double partArgument3 = argument[2];
246 int dimensionSize1 = m_coefficients.GetSize(0);
247 int dimensionSize2 = m_coefficients.GetSize(1);
248 int dimensionSize3 = m_coefficients.GetSize(2);
253 int& indexElement1 = index[0];
254 int& indexElement2 = index[1];
255 int& indexElement3 = index[2];
257 if (dimensionSize1 == 1){
260 for (indexElement3 = dimensionSize3 - 1; indexElement3 >= 0; --indexElement3){
262 for (indexElement2 = dimensionSize2 - 1; indexElement2 >= 0; --indexElement2){
263 partResult = partResult * partArgument2 + m_coefficients.
GetAt(index);
265 result = result * partArgument3 + partResult;
269 for (indexElement3 = dimensionSize3 - 1; indexElement3 >= 0; --indexElement3){
272 for (indexElement2 = dimensionSize2 - 1; indexElement2 >= 0; --indexElement2){
273 indexElement1 = dimensionSize1 - 1;
274 ResultType partResult = m_coefficients.GetAt(index);
276 for (indexElement1 = dimensionSize1 - 2; indexElement1 >= 0; --indexElement1){
277 partResult = partResult * partArgument1 + m_coefficients.GetAt(index);
280 partResult2 = partResult2 * partArgument2 + partResult;
282 result = result * partArgument3 + partResult2;
292template <
int Dimensions,
class Element>
306 retVal = retVal && archive.
BeginTag(dimensionsTag);
308 for (
int dimensionIndex = 0; dimensionIndex < Dimensions; ++dimensionIndex){
309 retVal = retVal && archive.
Process(gridSize[dimensionIndex]);
312 retVal = retVal && archive.
EndTag(dimensionsTag);
319 m_coefficients.SetSizes(gridSize);
322 retVal = retVal && archive.
BeginTag(coefficientsTag);
325 iter != m_coefficients.End();
327 Element& coeff = *iter;
329 retVal = retVal && archive.
Process(coeff);
332 retVal = retVal && archive.
EndTag(coefficientsTag);
340template <
int Dimensions,
class Element>
345 for (
int dimension = 0; dimension < Dimensions; ++dimension){
346 retVal *= std::pow(argument.GetElement(dimension), coeffIndex.
GetAt(dimension));
355template <
int Dimensions,
class Element>
362 Q_ASSERT(dimension < Dimensions);
363 Q_ASSERT(dimension >= 0);
365 int& indexElement = index[dimension];
366 int dimensionSize = m_coefficients.GetSize(dimension);
368 double partArgument = argument[dimension];
373 for (indexElement = dimensionSize - 1; indexElement >= 0; --indexElement){
374 result = result * partArgument + m_coefficients.
GetAt(index);
378 for (indexElement = dimensionSize - 1; indexElement >= 0; --indexElement){
381 CumulateRecursiveValueAt(argument, dimension - 1, index, partResult);
383 result = result * partArgument + partResult;
Implementation of variable-size mathematical matrix with double precision elements.
bool GetSolvedLSP(const CVarMatrix &vector, CVarMatrix &result, double minHhNorm=I_BIG_EPSILON) const
Solve 'Least Square Problem'.
Template interface for any mathematical function.
Multidimensional polynomial function.
static double GetBaseFunctionValue(const ArgumentType &argument, const istd::TIndex< Dimensions > &coeffIndex)
Get value of base function for single coefficient.
Coefficients::SizesType CoeffGridSize
void SetCoefficients(const Coefficients &coefficients)
istd::TArray< Element, Dimensions > Coefficients
imath::TIMathFunction< TVector< Dimensions >, Element > BaseClass
virtual bool Serialize(iser::IArchive &archive) override
Load or store state of this object as a archive stream.
virtual bool GetValueAt(const ArgumentType &argument, ResultType &result) const override
Get function value for specified argument value.
const Coefficients & GetCoefficients() const
void CumulateRecursiveValueAt(const ArgumentType &argument, int dimension, typename istd::TIndex< Dimensions > &index, ResultType &result) const
Cumulate interpolated value or derivative at specified recursion level.
bool ApproximateCoefficientsFromFulcrums(const CoeffGridSize &coeffGridSize, const ArgumentType *arguments, const ResultType *destValues, int count)
TMultidimensionalPolynomial()
Process tag used to group data in archive stream.
@ TT_GROUP
Normal tag used for grouping of tags or processed elements.
Represents an input/output persistence archive for object serialization.
virtual bool Process(bool &value)=0
Processes (reads or writes) a boolean value.
virtual bool EndTag(const CArchiveTag &tag)=0
Ends a tagged section in the archive.
virtual bool IsStoring() const =0
Checks if this archive is in storing (writing) or loading (reading) mode.
virtual bool BeginTag(const CArchiveTag &tag)=0
Begins a tagged section in the archive.
Common class for all classes which objects can be archived or restored from archive.
Help class which provides the automatic update mechanism of the model.
Index implementation for addressing elements in 2D-space.
Multidimensional array with fixed number of dimensions.
bool SetSizes(const SizesType &sizes)
Set list of all sizes.
const Element & GetAt(const IndexType &index) const
Get element stored at specified index.
void SetAt(const IndexType &index, const Element &value)
Set element at specified index.
const SizesType & GetSizes() const
Get list of all sizes.
Multidimensional index used to addressing fixed-size array.
int GetAt(int index) const
Get element stored at specified index.
bool Increase(const TIndex &boundaries)
Increase this index inside the boundaries.
Iterator Begin() const
Get begin value of element access iterator.
int GetProductVolume() const
Get total number of elements if this index is treated as size.
bool IsSizeEmpty() const
Check if this index interpreted as size is empty.
Package with mathematical functions and algebraical primitives.