IGLib  1.7.2
The IGLib base library EXTENDED - with other lilbraries and applications.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
IG.Num.ApproximatorWlsLinearBase Class Reference

Calculates weighted least squares approximations. More...

Public Member Functions

 ApproximatorWlsLinearBase (int spaceDimension, bool copyData=true, VectorFunctionBaseComponentWise basisFunctions=null)
 Constructs a WLS calculation object with the specified space dimention. More...
 
 ApproximatorWlsLinearBase (int spaceDimension, VectorFunctionBaseComponentWise basisFunctions)
 Constructs a WLS calculation object with the specified basis and with copy mode set to true. More...
 
override string ToString ()
 Creates and returns a human readable string representation of the current object. More...
 
void ClearData ()
 Called by destructor! Clears all the data used by the current object. More...
 
virtual void ClearPoints (bool deallocate)
 Resets sampling points with corresponding (measured) function values and weights. Dependent data is also reset. More...
 
virtual void ClearBasisFunctionValues (bool deallocate)
 Resets the array of values of basis functions precalculated in sampling points. More...
 
virtual void ClearSystemEquations (bool deallocate)
 Resets the system matrix of the set of linear equations for WLS approximation, and all dependent data. More...
 
virtual void ClearRightHandSides (bool deallocate)
 Resets the right-hand side vector of the set of linear equations for WLS approximation, and all dependent data. More...
 
virtual void ClearDecomposition (bool deallocate)
 Resets the decomposition of the system matrix of the set of linear equations for WLS approximation, and all dependent data. More...
 
virtual void ClearCoefficients (bool deallocate)
 Resets the coefficients of the WLS approximation, and all dependent data. More...
 
virtual void SetBasis (VectorFunctionBaseComponentWise basis)
 Changes basis functions of the approximation. More...
 
virtual void AddValue (IVector parameters, double value, double weight=1.0)
 Adds a new sampling point with the corresponding function value and weight. More...
 
virtual void AddValues2d (IList< IVector > parameterSets, IList< double > values, IList< double > weights=null)
 Adds a set of new sampling points with the corresponding function values and weights. More...
 
virtual void SetValue (int whichPoint, double value)
 Sets (changes) the value of the approximated function in the specified sampling point. More...
 
virtual void SetValues (int numValues, IList< double > values)
 Sets (changes) ALL values of the approximated function in the sampling points currently specified. More...
 
virtual bool CheckPointsConsistency (bool throwException=false)
 Checks consistency of storage that is related to the number of points used in the WLS approximation. (like if actual numbers of points, values, and weights are consistent with the related internal parameter). More...
 
virtual bool IsNumPointsSufficient (bool throwException=false)
 Returns true if the number of data points used in the WLS approximation is greater than or equal to the number of basis functions, otherwise it returns false. More...
 
virtual double BasisFunction (int whichFunction, int whichPoint)
 
virtual double BasisFunction (int whichFunction, IVector parameters)
 
virtual void CalculateBasisFunctionValues (bool setFlagToTrue=false)
 Precalculates values of basis functions in sampling points. More...
 
virtual double GetFinalWeight (int whichPoint)
 Returns final weight in the specified point. More...
 
virtual void CalculateSystemMatrix ()
 Calculates the system matrix of the linear system of equations for calculation of coefficients of the WLS approximation. More...
 
virtual void CalculateRighthandSides ()
 Calculated the right-hand sides of the linear system of equations for calculation of coefficients of the WLS approximation. More...
 
virtual void CalculateDecomposition ()
 Calculates Decomposition of the system matrix for calculation of WLS approximation coeddicients (if not yet calculated). More...
 
virtual void CalculateCoefficients ()
 Calculates coefficients of the WLS approximation. More...
 
virtual IVector GetCoefficients ()
 Calculates (if not yet calculated) and returns coefficients of the weighted least squares approximation. More...
 
virtual IMatrix GetSystemMatrix ()
 Calculates (if not yet calculated) and returns system matrix for calculation of the weighted least squares approximation coefficients. More...
 
virtual IVector GetRightHandSides ()
 Calculates (if not yet calculated) and returns right-hand side vector for calculation of the weighted least squares approximation coefficients. More...
 
virtual double Value (IVector parameters)
 Returns value of the current weighting least squares approximation at the specified parameters. More...
 
virtual double Derivative (int whichVariable, IVector parameters)
 Returns derivative with respect to the specified variable of the current weighting least squares approximation at the specified parameters. More...
 

Static Public Member Functions

static double TestWeightedLeastSquaresLinearBasis (int dim, int outputLevel=2, double excessFactor=1.5, int randomSeed=222, double perturbationFactor=0.0)
 Tests weighting Least squares approximation with liner basis functions. See TestWeightedLeastSquaresPolynomialBasis. More...
 
static double TestWeightedLeastSquaresQuadraticBasis (int dim, int outputLevel=2, double excessFactor=1.5, int randomSeed=222, double perturbationFactor=0.0)
 Tests weighting Least squares approximation with quadratic basis functions. See TestWeightedLeastSquaresPolynomialBasis. More...
 
static double TestWeightedLeastSquaresPolynomialBasis (int dim, bool quadratic=true, int outputLevel=2, double excessFactor=1.5, int randomSeed=222, double perturbationFactor=0.0)
 Tests weighting least squares approximation by sampling a fixed linear combination of lienar or quadratic polynomial basis functions on a random set of sampling points, calculating approximations in samplng points and comparing them to the original function. More...
 
static double TestWeightedLeastSquaresMultipleLinearBasis (int dim, int outputLevel=2, int numValueChanges=100, bool changePoints=true, bool ClearSystemEquations=true, double excessFactor=1.5, int randomSeed=555, double perturbationFactor=0.0)
 Tests weighting Least squares approximation with linear basis functions. See TestWeightedLeastSquaresMultiplePolynomialBasis. More...
 
static double TestWeightedLeastSquaresMultipleQuadraticBasis (int dim, int outputLevel=2, int numValueChanges=100, bool changePoints=true, bool ClearSystemEquations=true, double excessFactor=1.5, int randomSeed=555, double perturbationFactor=0.0)
 Tests weighting Least squares approximation with quadratic basis functions. See TestWeightedLeastSquaresMultiplePolynomialBasis. More...
 
static double TestWeightedLeastSquaresMultiplePolynomialBasis (int dim, bool quadratic=true, int outputLevel=2, int numValueChanges=100, bool changePoints=true, bool ClearSystemEquations=true, double excessFactor=1.5, int randomSeed=222, double perturbationFactor=0.0)
 Tests weighting least squares approximation by sampling fixed linear combinations of basis functions on multiple sets of points, calculating approximations in samplng points and comparing them to the original function. More...
 

Protected Attributes

int _numPoints
 
int _numBasisFunctions
 
double _decompositionTolerance = 1.0e-15
 

Properties

string ErrorString [get, set]
 Auxiliary string used to assemble error messages. More...
 
int PrecalcNumBasisFuctions [get, set]
 Number of basis functions when precalculation of basis functions was performed. More...
 
int PrecalcNumPoints [get, set]
 Number of points when precalculation of basis functions was performed. More...
 
int SpaceDimension [get, protected set]
 Dimension of the space where basis function is defined. More...
 
int NumPoints [get, protected set]
 Number of points. More...
 
int NumBasisFunctions [get, protected set]
 Number of basis functions. More...
 
IVector AuxVector [get, set]
 Auxiliary vector used in calculations. Dimension: number of functions. More...
 
IVector AuxPoint [get, set]
 Auxiliary vector used in calculation. Dimention: space dimension. More...
 
List< IVectorPoints [get, set]
 Sampling points. More...
 
List< double > PointValues [get, set]
 Values in sampling points to be approximated. More...
 
List< double > PointWeights [get, set]
 Weights corresponding to sampling points. More...
 
IMatrix SystemMatrix [get, set]
 System matrix. More...
 
IMatrix Decomposition [get, set]
 Decomposed System matrix. More...
 
IVector RighthandSides [get, set]
 Vector of right-hand sides. More...
 
IVector Coefficients [get, set]
 Vector of calculated approximation coefficients. More...
 
List< IVectorBasisFunctionValues [get, set]
 Pre-calculated values of vector funcitions in sampling points. More...
 
virtual
VectorFunctionBaseComponentWise 
Basis [get, protected set]
 Basis functions. More...
 
virtual bool PrecalculateBasisFunctionValues [get, set]
 Gets or sets a flag that indicates whether values of basis functions in sampling points should be precalculated and stored prior to calculation of system matrix and right-hand side vector, or not. More...
 
virtual bool TrimExcessive [get, set]
 Gets or sets a flag that indicates whether excessive calculated values on the lists should be removed if the number of elements is greater than the actual number used. Initialized to true by default. More...
 
virtual bool IsBasisFunctionsCalculated [get, protected set]
 Gets or sets a flag indicating whether values of basis functions in sampling points are calculated. More...
 
virtual bool IsSystemMatrixCalculated [get, protected set]
 Indicates whether the system matrix has been calculated already (and is valid for the current state of the approximator). More...
 
virtual bool IsDecompositionCalculated [get, protected set]
 Indicates whether decomposition of the system matrix has been calculated already (and is valid for the current state of the approximator). More...
 
virtual bool IsRighthandSidesCalculated [get, protected set]
 Indicates whether the right-hand sides have been calculated already (and are valid for the current state of the approximator). More...
 
virtual bool IsCoefficientsCalculated [get, protected set]
 Indicates whether the coefficients of the approximation (i.e., of linear combination of basis functions) have been calculated already (and are valid for the current state of the approximator). More...
 
bool IsCopyData [get, protected set]
 Flag indicating whether the object copies its input data internally. In this case, the provided data can be modified after it is fed to the object. More...
 
double DecompositionTolerance [get, set]
 Tolerance used for decomposition. If a pivot occurs whose absolute value is below tolerance then exception shoulld be thrown. More...
 

Private Member Functions

 ApproximatorWlsLinearBase ()
 Default constructor: do not use! More...
 
 ~ApproximatorWlsLinearBase ()
 Destructor. More...
 
VectorFunctionBaseComponentWise GetBasis ()
 Returns the set of basis functions used by the current approximation. More...
 

Private Attributes

int _spaceDimension
 
List< IVector_points = new List<IVector>()
 
List< double > _pointValues = new List<double>()
 
List< double > _pointWeights = new List<double>()
 

Detailed Description

Calculates weighted least squares approximations.

SpaceDimension returns the dimension of the space.

NumBasisFunctions returns the number of basis funcitons.

NumPoints returns the number of sampling points.

History

WLS approximator was one of the first numerical utility classes in IGLib and was firstt modeled upon its equivalents from the IOptLib C library. The class was designed for various extensions, e.g. incorporation of analytical derivative calculation and moving least squares (MLS). At that time the containing library was names IOptLib.NET (the "Investtigative Optimization Library") and has later renamed to IGLib (the "Investtigative Generic Library").

The moving least squares (MLS) support was first added in January 2008 and a part of testing libraries, which are used only internally.

The set of derived classes has undergone several modifications. Analytical derivatives were added in November 2008. In June 2008, WLS and MLS classes for handling several approximators sharing the same set of sampling points & weights / weighting functions (and thus the system matrix and its decomposition) were added. In July 2010, this was synchronized with hierarchy of vector functions.

It has for long been perceived that the implementation of the class hierarchy is overly complex. Redesign from ground up therefore started in December 2014, following the principles that simple classes (such as just a plain WLS for a single response) should be implemennted simply. For now, the classes that include MLS, vector approximators and analytical differentiation are not be included in basic IGLib.

Implementation of WLS/MLS classes was used to reproduce results from the followig paper (which were originally produced with C implementation):

Igor Grešovnik: The Use of Moving Least Squares for a Smooth Approximation of Sampled Data, Journal of Mechanical Engineering 53 (2007), 582-598, http://en.sv-jme.eu/scripts/download.php?file=/data/upload/2007/9/SV-JME_53(2007)09_582-598_Gresovnik.pdf

Other references:

Igor Grešovnik: IOptLib User's Manual (2009), http://www2.arnes.si/~ljc3m2/igor/ioptlib/doc/optlib.pdf

Igor Grešovnik: Specifications for software to determine sensitivities for optimization of the design of underground construction as part of IOPT, http://www2.arnes.si/~ljc3m2/igor/doc/pr/TUNCONSTRUCT_C3M_D1.3.2.1.pdf

$A Igor xx Jan08 Nov08 Jun09 Jul10 Dec14;

Constructor & Destructor Documentation

IG.Num.ApproximatorWlsLinearBase.ApproximatorWlsLinearBase ( )
inlineprivate

Default constructor: do not use!

IG.Num.ApproximatorWlsLinearBase.ApproximatorWlsLinearBase ( int  spaceDimension,
bool  copyData = true,
VectorFunctionBaseComponentWise  basisFunctions = null 
)
inline

Constructs a WLS calculation object with the specified space dimention.

Parameters
spaceDimensionDimension of the space on which WLS approximation is calculated.
copyDataSpecifies whether the object will create dynamic copies of input data when provided.

When true, for each input data provided (such as points and weights) internal copies are creaded.

When false, reference of provided data is taken.

For each input data provided (such as points), internal copies are creaded, and are deallocated when destructor is called.

IG.Num.ApproximatorWlsLinearBase.ApproximatorWlsLinearBase ( int  spaceDimension,
VectorFunctionBaseComponentWise  basisFunctions 
)
inline

Constructs a WLS calculation object with the specified basis and with copy mode set to true.

Parameters
spaceDimensionDimension of the space on which WLS approximation is calculated.
basisFunctionsLinear basis of type BasisFunctionsGeneric that provides basis functions.
IG.Num.ApproximatorWlsLinearBase.~ApproximatorWlsLinearBase ( )
inlineprivate

Destructor.

Member Function Documentation

override string IG.Num.ApproximatorWlsLinearBase.ToString ( )
inline

Creates and returns a human readable string representation of the current object.

The returned string can be used for immediate output to a file or output device, usually by calling the c_str() function on it to get the "char *" form.

References IG.Num.IVector.ToString().

void IG.Num.ApproximatorWlsLinearBase.ClearData ( )
inline

Called by destructor! Clears all the data used by the current object.

virtual void IG.Num.ApproximatorWlsLinearBase.ClearPoints ( bool  deallocate)
inlinevirtual

Resets sampling points with corresponding (measured) function values and weights. Dependent data is also reset.

Parameters
deallocateWhether or not the the corresponding memory is also dellocated. If false then we try to keep te memory and just adjust the flags telling that this and the dependent constructs are not calculated.
virtual void IG.Num.ApproximatorWlsLinearBase.ClearBasisFunctionValues ( bool  deallocate)
inlinevirtual

Resets the array of values of basis functions precalculated in sampling points.

Parameters
deallocateWhether or not the memory is also reset. If false then we try to keep te memory allocated and just adjust the flags telling that the dependent constructs are not calculated.
virtual void IG.Num.ApproximatorWlsLinearBase.ClearSystemEquations ( bool  deallocate)
inlinevirtual

Resets the system matrix of the set of linear equations for WLS approximation, and all dependent data.

Parameters
deallocateWhether or not the memory is also reset. If false then we try to keep te memory allocated and just adjust the flags telling that the system matrix and dependent constructs are not calculated.
virtual void IG.Num.ApproximatorWlsLinearBase.ClearRightHandSides ( bool  deallocate)
inlinevirtual

Resets the right-hand side vector of the set of linear equations for WLS approximation, and all dependent data.

Parameters
deallocateWhether or not the corresponding memory is also deallocated. If false then we try to keep te memory allocated and just adjust the flags telling that this and the dependent constructs are not calculated.
virtual void IG.Num.ApproximatorWlsLinearBase.ClearDecomposition ( bool  deallocate)
inlinevirtual

Resets the decomposition of the system matrix of the set of linear equations for WLS approximation, and all dependent data.

Parameters
deallocateWhether or not the corresponding memory is also deallocated. If false then we try to keep te memory allocated and just adjust the flags telling that this and the dependent constructs are not calculated.
virtual void IG.Num.ApproximatorWlsLinearBase.ClearCoefficients ( bool  deallocate)
inlinevirtual

Resets the coefficients of the WLS approximation, and all dependent data.

Parameters
deallocateWhether or not the corresponding memory is also deallocated. If false then we try to keep te memory allocated and just adjust the flags telling that this and the dependent constructs are not calculated.
virtual void IG.Num.ApproximatorWlsLinearBase.SetBasis ( VectorFunctionBaseComponentWise  basis)
inlinevirtual

Changes basis functions of the approximation.

If a basis different from the current basis is supplied then all the dependent data is cleared.

Parameters
basisNew set of basis functions.

References IG.Num.VectorFunctionBaseGeneral.NumValues.

VectorFunctionBaseComponentWise IG.Num.ApproximatorWlsLinearBase.GetBasis ( )
inlineprivate

Returns the set of basis functions used by the current approximation.

virtual void IG.Num.ApproximatorWlsLinearBase.AddValue ( IVector  parameters,
double  value,
double  weight = 1.0 
)
inlinevirtual

Adds a new sampling point with the corresponding function value and weight.

Dependent constructs are invalidated (flags are adjusted telling that these constructs are not calculated).

Parameters
parametersParameters for which function value is specified.
valueMeasured value of the approximated function at the specified parameters.
weightThe corresponding weight, default is 1.

References IG.Num.IVector.GetCopy().

virtual void IG.Num.ApproximatorWlsLinearBase.AddValues2d ( IList< IVector parameterSets,
IList< double >  values,
IList< double >  weights = null 
)
inlinevirtual

Adds a set of new sampling points with the corresponding function values and weights.

Dependent constructs are invalidated (flags are adjusted telling that these constructs are not calculated).

Parameters
numValuesNumber of values that are added. Must also define the guaranteed size of array parameters.
parameterSetsSets of parameters that define sampling points where function values are specified.
valuesMeasured values of the approximated function at the specified parameters (in sampling points).
weightsThe corresponding weight taken into account in the approximation. If null or without elements then default values are taken for weights (which should be 1).
virtual void IG.Num.ApproximatorWlsLinearBase.SetValue ( int  whichPoint,
double  value 
)
inlinevirtual

Sets (changes) the value of the approximated function in the specified sampling point.

Dependent constructs are invalidated (flags are adjusted telling that these constructs are not calculated).

Parameters
whichPointIndex of the sampling point for which function value is set.
valueMeasured value of the approximated function in the specified sampling point.

When only changing the values in sampling points (with weights and parameter vectors kept the same), only the right-hand side vector of the system of equations for calculation of approximation coefficients is invalidated. The system matrix (and thus its decomposition) does not need to be recalculated, and recalculation of approximation coefficients only requires back substitution.

virtual void IG.Num.ApproximatorWlsLinearBase.SetValues ( int  numValues,
IList< double >  values 
)
inlinevirtual

Sets (changes) ALL values of the approximated function in the sampling points currently specified.

Dependent constructs are invalidated (flags are adjusted telling that these constructs are not calculated).

Parameters
numValuesNumber of function values to be set. This must correspond to the actual values of sampling points currently defined on the approximated object (as a safequard for inconsistent attemps).
valuesMeasured values of the approximated function in ALL sampling points.

When only changing the values in sampling points (with weights and parameter vectors kept the same), only the right-hand side vector of the system of equations for calculation of approximation coefficients is invalidated. The system matrix (and thus its decomposition) does not need to be recalculated, and recalculation of approximation coefficients only requires back substitution.

virtual bool IG.Num.ApproximatorWlsLinearBase.CheckPointsConsistency ( bool  throwException = false)
inlinevirtual

Checks consistency of storage that is related to the number of points used in the WLS approximation. (like if actual numbers of points, values, and weights are consistent with the related internal parameter).

If the state is inconsistent, the method either returns false or throws an exception, dependent on its argument.

Parameters
throwExceptionIf true then exception is thrown in the case that the state is inconsistent.

Operations should maitain the state consistent all the time. This function tetects if someyhing failed in this mechanism.

Returns
true if the state is consistent, false otherwise.</returns<>
virtual bool IG.Num.ApproximatorWlsLinearBase.IsNumPointsSufficient ( bool  throwException = false)
inlinevirtual

Returns true if the number of data points used in the WLS approximation is greater than or equal to the number of basis functions, otherwise it returns false.

If the number of points is insufficient, the method either returns false or throws an exception, dependent on its argument.

Parameters
throwExceptionIf true then exception is thrown in the case that there are not enough points.
Returns
true if the number of points is sufficient with respect to the number of basis functions (greater or equal to), false otherwise.</returns<>
virtual double IG.Num.ApproximatorWlsLinearBase.BasisFunction ( int  whichFunction,
int  whichPoint 
)
inlinevirtual
virtual double IG.Num.ApproximatorWlsLinearBase.BasisFunction ( int  whichFunction,
IVector  parameters 
)
inlinevirtual
virtual void IG.Num.ApproximatorWlsLinearBase.CalculateBasisFunctionValues ( bool  setFlagToTrue = false)
inlinevirtual

Precalculates values of basis functions in sampling points.

If values are already calculated then nothing happens.

Parameters
setFlagToTrueIf true then the flag is also set that specifies that basis function values are normally precalculated prior to calculation of the system matrix and right-hand sides.
virtual double IG.Num.ApproximatorWlsLinearBase.GetFinalWeight ( int  whichPoint)
inlinevirtual

Returns final weight in the specified point.

Parameters
whichPointIndex of point for which final wight is returned.

This method enables use of the same methods for calculation of the system matrix and right-hand sides regardless of how weights are actually calculated. Inherited classes must only override this function.

virtual void IG.Num.ApproximatorWlsLinearBase.CalculateSystemMatrix ( )
inlinevirtual

Calculates the system matrix of the linear system of equations for calculation of coefficients of the WLS approximation.

virtual void IG.Num.ApproximatorWlsLinearBase.CalculateRighthandSides ( )
inlinevirtual

Calculated the right-hand sides of the linear system of equations for calculation of coefficients of the WLS approximation.

virtual void IG.Num.ApproximatorWlsLinearBase.CalculateDecomposition ( )
inlinevirtual

Calculates Decomposition of the system matrix for calculation of WLS approximation coeddicients (if not yet calculated).

References IG.Num.MatrixBase.CholeskyDecompose().

virtual void IG.Num.ApproximatorWlsLinearBase.CalculateCoefficients ( )
inlinevirtual

Calculates coefficients of the WLS approximation.

References IG.Num.MatrixBase.CholeskySolve().

virtual IVector IG.Num.ApproximatorWlsLinearBase.GetCoefficients ( )
inlinevirtual

Calculates (if not yet calculated) and returns coefficients of the weighted least squares approximation.

Warning: coefficients can be deallocated if the state of the approximation changes!

virtual IMatrix IG.Num.ApproximatorWlsLinearBase.GetSystemMatrix ( )
inlinevirtual

Calculates (if not yet calculated) and returns system matrix for calculation of the weighted least squares approximation coefficients.

Warning: coefficients can be deallocated if the state of the approximation changes!

Warning: Calculation of coefficients or matrix decomposition overwrites this matrix, therefore it must be re-calculated after after those are calculated!

virtual IVector IG.Num.ApproximatorWlsLinearBase.GetRightHandSides ( )
inlinevirtual

Calculates (if not yet calculated) and returns right-hand side vector for calculation of the weighted least squares approximation coefficients.

Warning: coefficients can be deallocated if the state of the approximation changes!

virtual double IG.Num.ApproximatorWlsLinearBase.Value ( IVector  parameters)
inlinevirtual

Returns value of the current weighting least squares approximation at the specified parameters.

Any intermediate results necessary are calculated automatically.

Exception is thrown if something can not be calculated (e.g. there is insufficient data or basis functions are not defined).

Parameters
parametersParameters where value is calculated.
virtual double IG.Num.ApproximatorWlsLinearBase.Derivative ( int  whichVariable,
IVector  parameters 
)
inlinevirtual

Returns derivative with respect to the specified variable of the current weighting least squares approximation at the specified parameters.

Any intermediate results necessary are calculated automatically.

Exception is thrown if something can not be calculated (e.g. there is insufficient data or basis functions are not defined).

Parameters
whichVariableVariable with respect to which derivative is calculated.
parametersParameters where derivative is calculated.
static double IG.Num.ApproximatorWlsLinearBase.TestWeightedLeastSquaresLinearBasis ( int  dim,
int  outputLevel = 2,
double  excessFactor = 1.5,
int  randomSeed = 222,
double  perturbationFactor = 0.0 
)
inlinestatic

Tests weighting Least squares approximation with liner basis functions. See TestWeightedLeastSquaresPolynomialBasis.

static double IG.Num.ApproximatorWlsLinearBase.TestWeightedLeastSquaresQuadraticBasis ( int  dim,
int  outputLevel = 2,
double  excessFactor = 1.5,
int  randomSeed = 222,
double  perturbationFactor = 0.0 
)
inlinestatic

Tests weighting Least squares approximation with quadratic basis functions. See TestWeightedLeastSquaresPolynomialBasis.

Referenced by IG.Test.TestApproximationBase.Approximation_Wls_Exact(), and IG.Test.ProgramTestNumericsIgor.Main().

static double IG.Num.ApproximatorWlsLinearBase.TestWeightedLeastSquaresPolynomialBasis ( int  dim,
bool  quadratic = true,
int  outputLevel = 2,
double  excessFactor = 1.5,
int  randomSeed = 222,
double  perturbationFactor = 0.0 
)
inlinestatic

Tests weighting least squares approximation by sampling a fixed linear combination of lienar or quadratic polynomial basis functions on a random set of sampling points, calculating approximations in samplng points and comparing them to the original function.

All components of sampling points are on the interval [0, 1], thus values of all basis functions (which are 1st or 2nd degree monomials) also lie in this interval.

Parameters
dimDimension of space where baiss functions are defined.
quadraticWhether quadratic polynomial approximation is tested. If false then linear polynomial basis is taken.
outputLevelLevel of output printed to standard output. If 0 or less then no outputs are produced, and this function can be used in unit testing.
excessFactorFactor by which there are more points than basis functions (and thus unknown coefficients to be calculated).

Must be greater than 1.

Parameters
randomSeedSeed for initialization of the random generator used to generate sampling points. By supplying the seed, results are repeatable, and the function is better suited for use in unit testing. If less or equal to 0 then random generator used for generation of sampling points is not seeded.
perturbationFactorIf different than 0 then pure cubic terms are added to the function used for sampling, which means that sampled values can not be any more exactly approximated by the used linear or quadratic basis.

References IG.Num.VectorBase.Copy(), IG.Lib.StopWatch1.CpuTime, IG.Num.VectorFunctionBaseGeneral.LinearCombinationValue(), IG.Num.IRandomGenerator.NextDouble(), IG.Num.VectorFunctionBaseGeneral.NumValues, IG.Lib.StopWatch1.Start(), IG.Lib.StopWatch1.Stop(), IG.Lib.StopWatch1.Time, and IG.Num.IVector.ToString().

static double IG.Num.ApproximatorWlsLinearBase.TestWeightedLeastSquaresMultipleLinearBasis ( int  dim,
int  outputLevel = 2,
int  numValueChanges = 100,
bool  changePoints = true,
bool  ClearSystemEquations = true,
double  excessFactor = 1.5,
int  randomSeed = 555,
double  perturbationFactor = 0.0 
)
inlinestatic

Tests weighting Least squares approximation with linear basis functions. See TestWeightedLeastSquaresMultiplePolynomialBasis.

static double IG.Num.ApproximatorWlsLinearBase.TestWeightedLeastSquaresMultipleQuadraticBasis ( int  dim,
int  outputLevel = 2,
int  numValueChanges = 100,
bool  changePoints = true,
bool  ClearSystemEquations = true,
double  excessFactor = 1.5,
int  randomSeed = 555,
double  perturbationFactor = 0.0 
)
inlinestatic

Tests weighting Least squares approximation with quadratic basis functions. See TestWeightedLeastSquaresMultiplePolynomialBasis.

Referenced by IG.Test.TestApproximationBase.Approximation_Wls_Perturbed(), and IG.Test.ProgramTestNumericsIgor.Main().

static double IG.Num.ApproximatorWlsLinearBase.TestWeightedLeastSquaresMultiplePolynomialBasis ( int  dim,
bool  quadratic = true,
int  outputLevel = 2,
int  numValueChanges = 100,
bool  changePoints = true,
bool  ClearSystemEquations = true,
double  excessFactor = 1.5,
int  randomSeed = 222,
double  perturbationFactor = 0.0 
)
inlinestatic

Tests weighting least squares approximation by sampling fixed linear combinations of basis functions on multiple sets of points, calculating approximations in samplng points and comparing them to the original function.

Parameters
dimDimension of space where baiss functions are defined.
quadraticWhether quadratic polynomial approximatio is tested. If false then linear approximation is taken.
outputLevelLevel of output printed to standard output. If 0 or less then no outputs are produced, and function can be used in unit testing.
numValueChangesNumber of times when the original function (formed as a fixed linear combination of basis functions) change.

Function values are re/calculated every time this happens, which implies that right-hand sides of the system of equations for coefficients also change.

Parameters
changePointsIf true then for each resampling the positions of sampling points also change.

If false then only the right-hand sides must be recalculated after each change of the approximated function. If true then the system matrix must be re-calculated, too.

Parameters
ClearSystemEquationsIf true then the system matrix is invalidated (and must be re-calculated when approximation coefficitnes or values are required) after each change of the approximated function, even if sampling points do not change.
excessFactorFactor by which there are more points than basis functions (and thus unknown coefficients to be calculated).

Must be greater than 1.

Parameters
randomSeedSeed for initialization of the random generator used to generate sampling points. By supplying the seed, results are repeatable, and the function is better suited for use in unit testing.
perturbationFactorIf different than 0 then pure cubic terms are added to the function used for sampling, which means that sampled values can not be any more exactly approximated by the used linear or quadratic basis.

References IG.Num.VectorBase.Copy(), IG.Lib.StopWatch1.CpuTime, IG.Num.VectorFunctionBaseGeneral.LinearCombinationValue(), IG.Num.IRandomGenerator.NextDouble(), IG.Num.VectorFunctionBaseGeneral.NumValues, IG.Lib.StopWatch1.Start(), IG.Lib.StopWatch1.Stop(), IG.Lib.StopWatch1.Time, and IG.Num.IVector.ToString().

Member Data Documentation

int IG.Num.ApproximatorWlsLinearBase._spaceDimension
private
int IG.Num.ApproximatorWlsLinearBase._numPoints
protected
int IG.Num.ApproximatorWlsLinearBase._numBasisFunctions
protected
List<IVector> IG.Num.ApproximatorWlsLinearBase._points = new List<IVector>()
private
List<double> IG.Num.ApproximatorWlsLinearBase._pointValues = new List<double>()
private
List<double> IG.Num.ApproximatorWlsLinearBase._pointWeights = new List<double>()
private
double IG.Num.ApproximatorWlsLinearBase._decompositionTolerance = 1.0e-15
protected

Property Documentation

string IG.Num.ApproximatorWlsLinearBase.ErrorString
getsetprotected

Auxiliary string used to assemble error messages.

int IG.Num.ApproximatorWlsLinearBase.PrecalcNumBasisFuctions
getsetprotected

Number of basis functions when precalculation of basis functions was performed.

int IG.Num.ApproximatorWlsLinearBase.PrecalcNumPoints
getsetprotected

Number of points when precalculation of basis functions was performed.

int IG.Num.ApproximatorWlsLinearBase.SpaceDimension
getprotected set

Dimension of the space where basis function is defined.

When setting, if the dimension differs from the current one, all internal constructs sependent oo the dimension are reset.

int IG.Num.ApproximatorWlsLinearBase.NumPoints
getprotected set

Number of points.

int IG.Num.ApproximatorWlsLinearBase.NumBasisFunctions
getprotected set

Number of basis functions.

IVector IG.Num.ApproximatorWlsLinearBase.AuxVector
getsetprotected

Auxiliary vector used in calculations. Dimension: number of functions.

IVector IG.Num.ApproximatorWlsLinearBase.AuxPoint
getsetprotected

Auxiliary vector used in calculation. Dimention: space dimension.

List<IVector> IG.Num.ApproximatorWlsLinearBase.Points
getsetprotected

Sampling points.

List<double> IG.Num.ApproximatorWlsLinearBase.PointValues
getsetprotected

Values in sampling points to be approximated.

List<double> IG.Num.ApproximatorWlsLinearBase.PointWeights
getsetprotected

Weights corresponding to sampling points.

These are always constants, even when MLS is calculated.

IMatrix IG.Num.ApproximatorWlsLinearBase.SystemMatrix
getsetprotected

System matrix.

IMatrix IG.Num.ApproximatorWlsLinearBase.Decomposition
getsetprotected

Decomposed System matrix.

IVector IG.Num.ApproximatorWlsLinearBase.RighthandSides
getsetprotected

Vector of right-hand sides.

IVector IG.Num.ApproximatorWlsLinearBase.Coefficients
getsetprotected

Vector of calculated approximation coefficients.

List<IVector> IG.Num.ApproximatorWlsLinearBase.BasisFunctionValues
getsetprotected

Pre-calculated values of vector funcitions in sampling points.

virtual VectorFunctionBaseComponentWise IG.Num.ApproximatorWlsLinearBase.Basis
getprotected set

Basis functions.

virtual bool IG.Num.ApproximatorWlsLinearBase.PrecalculateBasisFunctionValues
getset

Gets or sets a flag that indicates whether values of basis functions in sampling points should be precalculated and stored prior to calculation of system matrix and right-hand side vector, or not.

virtual bool IG.Num.ApproximatorWlsLinearBase.TrimExcessive
getset

Gets or sets a flag that indicates whether excessive calculated values on the lists should be removed if the number of elements is greater than the actual number used. Initialized to true by default.

virtual bool IG.Num.ApproximatorWlsLinearBase.IsBasisFunctionsCalculated
getprotected set

Gets or sets a flag indicating whether values of basis functions in sampling points are calculated.

virtual bool IG.Num.ApproximatorWlsLinearBase.IsSystemMatrixCalculated
getprotected set

Indicates whether the system matrix has been calculated already (and is valid for the current state of the approximator).

virtual bool IG.Num.ApproximatorWlsLinearBase.IsDecompositionCalculated
getprotected set

Indicates whether decomposition of the system matrix has been calculated already (and is valid for the current state of the approximator).

virtual bool IG.Num.ApproximatorWlsLinearBase.IsRighthandSidesCalculated
getprotected set

Indicates whether the right-hand sides have been calculated already (and are valid for the current state of the approximator).

virtual bool IG.Num.ApproximatorWlsLinearBase.IsCoefficientsCalculated
getprotected set

Indicates whether the coefficients of the approximation (i.e., of linear combination of basis functions) have been calculated already (and are valid for the current state of the approximator).

bool IG.Num.ApproximatorWlsLinearBase.IsCopyData
getprotected set

Flag indicating whether the object copies its input data internally. In this case, the provided data can be modified after it is fed to the object.

double IG.Num.ApproximatorWlsLinearBase.DecompositionTolerance
getset

Tolerance used for decomposition. If a pivot occurs whose absolute value is below tolerance then exception shoulld be thrown.


The documentation for this class was generated from the following file: