IGLib
1.7.2
The IGLib base library EXTENDED - with other lilbraries and applications.
|
Base class for least squares approximation and various derived methods. More...
Public Member Functions | |
ApproximationLeastSquaresBase () | |
Constructs a new object of the ApproximationLeastSquaresBase that is NOT a master object. More... | |
ApproximationLeastSquaresBase (bool isMaster) | |
Creates a new object of the ApproximationLeastSquaresBase that is or is not a master object, and doesn't have any master object. More... | |
ApproximationLeastSquaresBase (ApproximationLeastSquaresBase master) | |
Constructs a new object of the ApproximationLeastSquaresBase that is NOT a master object, and has the specified master object. More... | |
virtual ApproximationLeastSquaresBase | CreateSlave () |
void | AddApproximator (params ApproximationLeastSquaresBase[] approximators) |
Adds the specified approximator to the current master approximator objects. More... | |
virtual void | UpdateParametersChange () |
Updates dependencies on parameters where approximaiton is evaluated. More... | |
virtual void | UpDateCenterChange () |
Updated dependencies on the center of approximation. More... | |
double | GetBasisFunctionValue (int whichFunction, int whichPoint) |
Returns value of the base function in the specified point. More... | |
double | GetWeight (int whichPoint) |
Returns value of the overall weight assigned to the specified sampling point. More... | |
double | GetValue (int whichPoint) |
Returns value of the approximated function in the specified sampling point. More... | |
virtual void | AssembleSystemMatrix () |
Assembles the system matrix. More... | |
virtual void | AssembleRighthandSide () |
Assembles the right-hand side vector. More... | |
virtual void | CalculateCoefficients () |
virtual double | ApproximationValue (IVector x) |
virtual double | ApproximationGradient (IVector x, ref IVector grad) |
Static Public Member Functions | |
static void | TestMlsQuadratic (IRandomGenerator rand, int dimension, double dataExcessFactor) |
Tests the MLS approximation by sampling and approximating a quadratic function. More... | |
Static Public Attributes | |
static volatile bool | DefaultIsTestMode = false |
Default value of the testmode flag. More... | |
Protected Attributes | |
int | _outputLevel = DefaultOutputLevel |
bool | _isTestMode = DefaultIsTestMode |
StopWatch1 | _timer = null |
bool | _isMaster = false |
ApproximationLeastSquaresBase | _master |
List < ApproximationLeastSquaresBase > | _elementApproximators |
bool | _delegatedStaticWeights = false |
bool | _delegatedWeightingFunction = false |
bool | _delegateNodalPositions = false |
int | _numPoints |
Number of sampling points. More... | |
bool | _isMovingLeastSquares = true |
IVector | _parameters |
Current evaluation point. More... | |
IVector | _center |
double[] | _weightsStatic |
Vector of static weights. More... | |
IScalarFunctionUntransformed | _weightingFunction |
Weighting function used for calculation of weights. More... | |
bool | _isWeightingFunctionRadial = false |
Whether weighting function is a radial weighting function with affine transformation. More... | |
ScalarFunctionRadial | _weightingFunctionRadial |
bool | _isSystemMatrixAssembled = false |
Whether the system matrix has been assembled. More... | |
IMatrix | _systemMatrix |
System matrix. More... | |
bool | _isSolverCreated = false |
Whether solver hsa been created. More... | |
ILinearSolver | _solver |
Solver used for calculating approximation coefficients. More... | |
bool | _isRightHandSideAssembled = false |
Whether the right-hand side has been assembled. More... | |
IVector | _righthandSides |
Vector of right-hand sides. More... | |
bool | _isCoefficientsCalculated = false |
Whether coefficients of the approximation have been calculated. More... | |
IVector | _coefficients |
Vector of coefficients of linear basis functions at the evaluation point. More... | |
Static Protected Attributes | |
static int | _defaultOutputLevel = 0 |
Properties | |
object | Lock [get] |
This object's central lock object to be used by other object. Do not use this object for locking in class' methods, for this you should use InternalLock. More... | |
static int | DefaultOutputLevel [get, set] |
Gets or sets the default level of output for this class. More... | |
int | OutputLevel [get, set] |
Level of output to the console for the current object. More... | |
bool | IsTestMode [get, set] |
Whether the current job data conntainer is in test mode. In this mode, delays specified by internal variables are automatically added in job execution. More... | |
StopWatch1 | Timer [get] |
Gets a stopwatch that measures time of operations when in test mode. More... | |
virtual bool | IsMaster [get, set] |
Whether the current approximation object is a master object that contains a list of approximation objects that calculate individual components of approximated vector function. More... | |
virtual bool | IsSlave [get] |
Gets the flag indicating whether the current approximator is a slave object, i.e. it has a master object that may contain (or not) some of its data necessary to calculate the approximation. More... | |
virtual ApproximationLeastSquaresBase | Master [get, set] |
Eventual master object that contains the current approximation object. More... | |
virtual List < ApproximationLeastSquaresBase > | ElementApproximators [get, protected set] |
Approximators that approximate elements of a vector function. More... | |
virtual bool | DelegateBasis [get, set] |
Whether basis functions are delegated to the master object containing the current object. More... | |
virtual bool | DelegateStaticWeights [get, set] |
Whether static weights are delegated to master object containing the current object. More... | |
virtual bool | delegateWeightingFunction [get, set] |
Whether static weights are delegated to master object containing the current object. More... | |
virtual bool | DelegateNodalPositions [get, set] |
Whether positions of nodes (parameters of sampled data) are delegated to master object containing the current object. More... | |
virtual bool | DelegateNodalValues [get, set] |
Whether approximated function values (and derivatives) at nodes are delegated to master object containing the current object. More... | |
virtual bool | DelegateSystemMatrix [get] |
Whether the system matrix is delegated. More... | |
virtual bool | DelegateRightHandSides [get] |
Whether the system matrix is delegated. More... | |
virtual bool | DelegateCoefficients [get] |
Whether the vector of calculated coefficients is delegated. More... | |
virtual int | Dimension [get, protected set] |
Number of parameters (independent variables of approximation). More... | |
virtual int | NumPoints [get, protected set] |
Number of sampling points. More... | |
virtual int | NumBasisFunctions [get, protected set] |
LinearBasis | Basis [get, set] |
Basis functions. More... | |
bool | IsMovingLeastSquares [get, set] |
Whether the current approximator is a moving least squares approximator, i.e. the center of approximatiion coinceeds with parameters where approximation is evaluated. More... | |
virtual IVector | Parameters [get, set] |
Current evaluation point. More... | |
virtual IVector | Center [get, set] |
Center of weighting functions. More... | |
virtual double[] | WeightsStatic [get, set] |
Vector of static weights. More... | |
virtual IScalarFunctionUntransformed | WeightingFunction [get, set] |
Weighting function used for calculation of weights. More... | |
virtual bool | IsWeightingFunctionRadial [get, protected set] |
Whether weifhting function is a radial weighting function with affine transformation. More... | |
ScalarFunctionRadial | WeightingFunctionRadial [get, set] |
Auxliliary property whose getter evaluates to WeightingFunction if it is of type ScalarFunctionRadial (i.e. radial function with affine transformation fo parameters), or null if weighting function is not of that type. It is also possible to set weighting function through this property. More... | |
virtual bool | IsSystemMatrixAssembled [get, set] |
Whether the system matrix has been assembled. More... | |
IMatrix | SystemMatrix [get, set] |
System matrix. More... | |
bool | IsSolverCreated [get, set] |
Whether a linear solver for calculating coefficients has been created. More... | |
ILinearSolver | Solver [get, set] |
Solver used for calculating approximation coefficients. More... | |
virtual bool | IsRightHandSideAssembled [get, protected set] |
Whether the right-hand side vector has been assembled. More... | |
IVector | RighthandSides [get, set] |
Vector of right-hand sides. More... | |
virtual bool | IsCoefficientsCalculated [get, protected set] |
Whether coefficients of the approximation have been calculated. More... | |
IVector | Coefficients [get, protected set] |
Vector of coefficients of linear basis functions at the evaluation point. More... | |
![]() | |
object | Lock [get] |
Private Attributes | |
readonly object | _mainLock = new object() |
int | _dimension |
Number of parameters (independent variables of approximation). More... | |
int | _numBasisFunctions |
LinearBasis | _basis |
Basis functions. More... | |
double[] | AuxBaseFunctionValues |
Auxiliary array for temporarily storing values of base functions in the specific point. More... | |
Base class for least squares approximation and various derived methods.
Base for ordinary least squares, weighted least squares (WLS), and moving least squares (MLS).
History:
This class is a part object-oriented re-implementation of the moving least squares (MLS) module of IOptLib.
Information for developers:
The current base class is multifunctional and therefore contains some overhead as regard to internal variables and properties. It implements all data necessary for approximators from linear ordinary least squares through linear weighted least squares and finally moving least squares. Subclasses then make appropriate use of the data and some data is not used in these classes at all. Assumption that justifies this is that such approximators will not be used in scenarios where light-weight approximation objects are required. It should also be noted that handling of internal data structures is quite complex in some kinds of derived classes such as those for moving least squares. Therefore, this base class provides tools for rather complex scenarios, and some implementation of sub-classes can use only a small portion of these tools. Derived classes are intended for use in optimization or in approximation-based modeling of processes, especially with several process parameters.
CPU efficiency is given priority over small memory usage and also over good object oriented design to some extent. Internal variables are defined as protected rather than private, in order to increase performance where these variables are accessed in loops. Some data is copied to higher performance structures before execution of code that uses such data in loops with many iterations. The nature of thinhs is such that algorithms make use of intensive iterative computations. Therefoer preparation activities are not performance-critical and are be implemented with overhead that aids reusability and other benefits of object oriented programming. This includes use of properties instead of direct variables, complex data validation procedures, use of virtual functions, complex branching in order to cover a wide range of usage scenarios (e.g. WLS vs. MLS, calculation of sensitivities, inclusio of derivative data), etc.
Sources:
Igor Grešovnik: Linear Approximation with Regularization and Moving Least Squares, technical study.
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
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
History:
This is one of the first higher level classes in the IGLib, created after some basic numerical classes such as Matrix, Vector, etc. Also the first class that has been transfered from the IOptLib optimization library (ported from ANSI C).
Adopted fully object oriented approach in January 2008 (giving up numerical efficiency as first priority).
Adapted for approximation of vector functions, allowing for approximation of several scalar functions that can share sampling points, weighting functions, static weights, etc.
In June 2009, the class has been updated to fully comply with scalar and vector function definitions in the IGLib.
In July & August 2010, extensive testing and some detail improvements were made. Since this point, the class is considered mature, stable and suitable for any professional use, excpet prehaps in cases where mroe specialized implementations should be used for efficiency reasons. This is possible in lower dimensions, especially where the approximations are used in simulation codes (such as mesh free simulations, geometry or graphics), but is not expected elsewhere.
$A Igor xx Jan08 Nov08 Jun09 Jul10;
|
inline |
Constructs a new object of the ApproximationLeastSquaresBase that is NOT a master object.
|
inline |
Creates a new object of the ApproximationLeastSquaresBase that is or is not a master object, and doesn't have any master object.
isMaster | Whether this is a master approximation object or not. |
|
inline |
Constructs a new object of the ApproximationLeastSquaresBase that is NOT a master object, and has the specified master object.
The ApproximationLeastSquaresBase.IsMaster property is set to false.
master | The master object of the created object. |
|
inlinevirtual |
|
inline |
Adds the specified approximator to the current master approximator objects.
Added approximators will approximate individual elements of the vector function.
Exception is thrown if the current object is not a master approximator object (i.e., if IsMaster == false)
approximators | Approximators to be added for approximation of elements of a vector function. |
|
inlinevirtual |
Updates dependencies on parameters where approximaiton is evaluated.
If Master property is defined then parameters are always delegated to the Master, i.e. change of parameters always affects all slave approximation objects.
If the current object is a master object then the call to this method will also call the same method on all contained slave objects.
|
inlinevirtual |
Updated dependencies on the center of approximation.
If Master property is defined then center of approximation is always delegated to the Master, i.e. change of the center always affects all slave approximation objects.
Center of approximation makes sense when weighting functions are defined.
If the current object is a master object then the call to this method will also call the same method on all contained slave objects.
|
inline |
Returns value of the base function in the specified point.
Usually not thread safe.
whichFunction | Index of base function whose value is to be returned. |
whichPoint | Index of sampling point in which base function value is calculated. |
|
inline |
Returns value of the overall weight assigned to the specified sampling point.
whichPoint | Index of sampling point for which weight is returned. |
|
inline |
Returns value of the approximated function in the specified sampling point.
whichPoint | Index of sampling point for which function is returned. |
|
inlinevirtual |
Assembles the system matrix.
References IG.Num.MatrixBase.Resize(), and IG.Num.MatrixBase.SetZero().
|
inlinevirtual |
Assembles the right-hand side vector.
References IG.Num.VectorBase.Resize(), and IG.Num.VectorBase.SetZero().
|
inlinevirtual |
References IG.Num.ILinearSolver.Solve().
|
inlinevirtual |
|
inlinevirtual |
|
inlinestatic |
Tests the MLS approximation by sampling and approximating a quadratic function.
dimension | |
dataExcessFactor |
References IG.Num.SampledDataSet.CreateExample(), IG.Num.ScalarFunctionQuadratic.GetNumConstants(), IG.Num.IRandomGenerator.NextDouble(), IG.Num.IMatrix.SetRandom(), IG.Num.IVector.SetRandom(), IG.Num.MatrixBase.SymmetricPartPlain(), and IG.Num.IBoundingBox.UpdateAll().
|
private |
|
staticprotected |
|
protected |
|
static |
Default value of the testmode flag.
Also used for classes derived from ParallelJobServerBase and ParallelJobDispatcherBase
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
private |
Number of parameters (independent variables of approximation).
|
protected |
Number of sampling points.
|
private |
|
private |
Basis functions.
|
protected |
|
protected |
Current evaluation point.
|
protected |
|
protected |
Vector of static weights.
|
protected |
Weighting function used for calculation of weights.
|
protected |
Whether weighting function is a radial weighting function with affine transformation.
|
protected |
|
protected |
Whether the system matrix has been assembled.
|
protected |
Whether solver hsa been created.
|
protected |
Solver used for calculating approximation coefficients.
|
protected |
Whether the right-hand side has been assembled.
|
protected |
Whether coefficients of the approximation have been calculated.
|
protected |
Vector of coefficients of linear basis functions at the evaluation point.
Coefficients of the linear combination of base functions that define the approximation.
|
private |
Auxiliary array for temporarily storing values of base functions in the specific point.
|
get |
This object's central lock object to be used by other object. Do not use this object for locking in class' methods, for this you should use InternalLock.
|
staticgetset |
Gets or sets the default level of output for this class.
When accessed for the first time, the current value of Util.OutputLevel is returned.
If set to less than 0 then the first subsequent set access will return the current the current value of Util.OutputLevel.
|
getset |
Level of output to the console for the current object.
|
getset |
Whether the current job data conntainer is in test mode. In this mode, delays specified by internal variables are automatically added in job execution.
|
get |
Gets a stopwatch that measures time of operations when in test mode.
|
getset |
Whether the current approximation object is a master object that contains a list of approximation objects that calculate individual components of approximated vector function.
|
get |
Gets the flag indicating whether the current approximator is a slave object, i.e. it has a master object that may contain (or not) some of its data necessary to calculate the approximation.
|
getset |
Eventual master object that contains the current approximation object.
|
getprotected set |
Approximators that approximate elements of a vector function.
|
getset |
Whether basis functions are delegated to the master object containing the current object.
|
getset |
Whether static weights are delegated to master object containing the current object.
|
getset |
Whether static weights are delegated to master object containing the current object.
|
getset |
Whether positions of nodes (parameters of sampled data) are delegated to master object containing the current object.
|
getset |
Whether approximated function values (and derivatives) at nodes are delegated to master object containing the current object.
|
get |
Whether the system matrix is delegated.
This is a dependent flag.
|
get |
Whether the system matrix is delegated.
This is a dependent flag.
|
get |
Whether the vector of calculated coefficients is delegated.
This is a dependent flag.
|
getprotected set |
Number of parameters (independent variables of approximation).
Not thread safe.
|
getprotected set |
Number of sampling points.
Approximation is calculated on basis of function values in these points.
|
getprotected set |
|
getset |
Basis functions.
|
getset |
Whether the current approximator is a moving least squares approximator, i.e. the center of approximatiion coinceeds with parameters where approximation is evaluated.
If a master approximator object exist then this property is always delegated to it.
If the current object is a master object and the property is assigned a value then the same value is assigned to all slave approximator objects.
|
getset |
Current evaluation point.
Must be overridden in the case of MLS where changing x affects coefficients and thus system matrix and right-hand side.
|
getset |
Center of weighting functions.
In WLS, this affects calculation of weights corresponding to sampling points. In MLS, this does not have effect because center is set to the current point of evaluation every time.
|
getset |
Vector of static weights.
If this vector is null then all weights are assumed to be 1.
These are multiplicative weights by which values of weighting functions are multiplied in the case of MLS.
|
getset |
Weighting function used for calculation of weights.
If the weighting function is not specified then it is assumed to be a constant function equal to 1 everywhere.
Weights assigned to sampling points are calculated by evaluating this function on the difference between the sampling point and point of evaluation, and multiplying the result with the corresponding static weight.
|
getprotected set |
Whether weifhting function is a radial weighting function with affine transformation.
|
getset |
Auxliliary property whose getter evaluates to WeightingFunction if it is of type ScalarFunctionRadial (i.e. radial function with affine transformation fo parameters), or null if weighting function is not of that type. It is also possible to set weighting function through this property.
|
getset |
Whether the system matrix has been assembled.
|
getset |
|
getset |
Whether a linear solver for calculating coefficients has been created.
|
getset |
Solver used for calculating approximation coefficients.
|
getprotected set |
Whether the right-hand side vector has been assembled.
|
getset |
Vector of right-hand sides.
Right-hand side of the system of equations to be solved for coefficients of the linear combination of functions that define the approximation.
|
getprotected set |
Whether coefficients of the approximation have been calculated.
Indicates whether coefficients of the approximation have been calculated (in the case of moving least squares with coefficient dependent on intependent variable, this refers to the current point of evaluation).
|
getprotected set |
Vector of coefficients of linear basis functions at the evaluation point.
Coefficients of the linear combination of base functions that define the approximation.