IGLib 1.4
The IGLib base library for development of numerical, technical and business applications.

IG::Lib::ScalarFunctionLoader Class Reference

Dynamically generates IScalarFunction classes from user definitions. User can define in string form how function, its derivative, second derivative, integral, or inverse function is calculated. Then this class can be used to compile these definitions in the wrapping script, which is then used to create the corresponding function objects. More...

Inheritance diagram for IG::Lib::ScalarFunctionLoader:
Collaboration diagram for IG::Lib::ScalarFunctionLoader:

List of all members.

Public Member Functions

 ScalarFunctionLoader ()
 Constructor.
void InvalidateDefinitions ()
 Clears strings that define the function (i.e. strings that define expressions for function value, derivative, integral, inverse, etc.). Number of parameters is not reset.
void SetNames (string returnedValueName, string functionArgumentName, string[] independentVariableNames)
 Sets names used in generated script code.
string[] GetDefaultIndependentVariableNames (int numParam)
 Returns a table of default names of variables (within functions in the loadable scripts) that hold the independent variables (components of vector of parameters), for the specified number of parameters.
void SaveCode (string filePath)
 Saves the generated script code to the specified file. File is overwritten if it already exists.
string getDefinitionString (string[][] definitions, int ind1, int ind2)
 Returns the specific definition string out of a 2D jagged array of definitions, or null if the specified definition is not contained in the array of definitions.
string GetParametersPlainListString ()
 Returns a string representation of the list of independent variables, separated by commas but not embedded in any braces.
string Compile ()
 Compiles the code that contains dynamically loadable definition of a real function of one variable.
LoadableScalarFunctionBase CreateScalarFunction ()
 Creates and returns an instance of dynamically compiled scalar function object.
LoadableScalarFunctionBase CreateScalarFunction (IAffineTransformation transf)
 Creates and returns an instance of dynamically compiled scalar function object, where the scalar funciton is obtained from user defined expressions and affine trensformation of vector parameters.

Static Public Member Functions

static void Example ()
 Example of use of the ScalarFunctionLoader class. Creates a function loader and uses it for dynamic definition of functions.
static void Example (string scriptPath)
 Example of use of the ScalarFunctionLoader class. Creates a function loader and uses it for dynamic definition of functions.

Public Attributes

const string DefaultScriptClassName = "ScalarFunctionScript"
 Default name of the class used in loadable scripts containing user definitions of scalar function class.
const string FuncNameInitDynamic = "InitDynamic"
 Name of the function that initializes variables realated to dynamically loaded scalar function class.
const string VarNameNumParameters = "_numParam"
 Name of variable (internal in class defined in loadable script) that holds the number of parameters.
const string VarNameReturnedValueName = "_returnedValueName"
 Name of variable (internal in class defined in loadable script) that holds the name of local variable (defined within functions in the dynamically loaded script) where returned value is stored.
const string DefaultReturnedValueName = "ret"
 Default name of the variable that holds returned value in script functions.
const string VarNameFunctionArgumentParametersName = "_functionArgumentParametersName"
 Name of variable (internal in class defined in loadable script) that holds the names of function argument (defined within functions in the dynamically loaded script) through which independent variable is passed.
const string DefaultFunctionArgumentParametersName = "parameters"
 Default name of vector of parameters in function arguments in script functions.
const string VarNameFunctionArgumentGradientName = "_functionArgumentGradientName"
const string DefaultFunctionArgumentGradientName = "gradient"
 Default name of gradient vector in function arguments in script functions.
const string VarNameFunctionArgumentHessianName = "_functionArgumentHessianName"
const string DefaultFunctionArgumentHessianName = "hessian"
 Default name of hessian vector in function arguments in script functions.
const string DefaultIndependentVariableBaseName = "x"
 Default base name of the independent variables (components of parameter vector) in expression definitions used in scripts to define calculation of function values, derivatives, etc.
const string VarNameIndependentVariableNames = "_independentVariableNames"
const string VarNameValueDefinitionString = "_valueDefinitionString"
 Name of the variable (internal in class defined in loadable script) that holds user definition (as string) of function value.
const string VarNameGradientDefinitionStrings = "_gradientDefinitionStrings"
 Name of the variable (internal in class defined in loadable script) that holds user definition (as string) of function derivative.
const string VarNameHessianDefinitionStrings = "_hessianDefinitionStrings"
 Name of the variable (internal in class defined in loadable script) that holds user definition (as string) of function second derivative.
const string FuncNameValueDefinition = "ReferenceValue"
 Name of the function (internal in class defined in loadable script) that defines calculation of function value.
const string FuncNameGradientDefinition = "ReferenceGradientPlain"
 Name of the function (internal in class defined in loadable script) that defines calculation of function gradient.
const string FuncNameHessianDefinition = "ReferenceHessianPlain"
 Name of the function (internal in class defined in loadable script) that defines calculation of function hessian.
const string VarNameValueDefined = "_valueDefined"
 Name of the variable (internal in class defined in loadable script) that holds a flag telling whether calculation of function value is implemented.
const string VarNameGradientDefined = "_gradientDefined"
 Name of the variable (internal in class defined in loadable script) that holds a flag telling whether calculation of function gradient is implemented.
const string VarNameHessianDefined = "_hessianDefined"
 Name of the variable (internal in class defined in loadable script) that holds a flag telling whether calculation of function hessian is implemented.

Protected Member Functions

void AppendIndents (StringBuilder sb, int numIndent)
 Appends to the apecified string builder the specified level of indentation.
void AppendBeginComment (StringBuilder sb)
 Appends beginning of comment.
void AppendEndcomment (StringBuilder sb)
 Appends end of comment.
void AppendIndexComment (StringBuilder sb, string coponentBaseName, int index)
 Appends comment that denotes the componenent index.
void AppendIndexComment (StringBuilder sb, string coponentBaseName, int index1, int index2)
 Appends comment that denotes the componenent index.
void AppendSetVariable (StringBuilder sb, string varName, object value, int numIndents)
 Appends to the apecified string builder the C# statements that sets the specified variable to the specified value.
void AppendSetVariable (StringBuilder sb, string varName, string[] values, string coponentBaseName, int numIndents)
 Appends to the apecified string builder the C# statements that sets the specified variable to the specified value.
void AppendSetVariable (StringBuilder sb, string varName, string[][] values, string componentBaseName, int numIndents)
 Appends to the apecified string builder the C# statements that sets the specified variable to the specified value.
virtual string GetCode ()
 Generates and returns script code for dynamically loadable function definition.

Properties

object Lock [get]
 Current object's central lock object.
bool ValueDefined [get]
 Whether calculation of function value is defined.
bool GradientDefined [get]
 Whether calculation of function gradient is defined.
bool HessianDefined [get]
 Whether calculation of function Hessian is defined.
string ReturnedValueName [get, set]
 Name of variable (within functions in the loadable scripts) that temporarily holds the returned value(s). Set to constant DefaultReturnedValueName by default.
string FunctionArgumentParametersName [get, set]
 Name of parameters vector in function arguments (in functions in the loadable scripts). Set to constant DefaultFunctionArgumentParametersName by default.
string FunctionArgumentGradientName [get, set]
 Name of gradient vector in function arguments (in functions in the loadable scripts). Set to constant DefaultFunctionArgumentGradientName by default.
string FunctionArgumentHessianName [get, set]
 Name of Hessian matrix in function arguments (in functions in the loadable scripts). Set to constant DefaultFunctionArgumentHessianName by default.
int NumParameters [get, set]
 Number of parameters of the scalar function that will be defined by a generated script

  • dimension of space in which the scalar function is defined.

string IndependentVariableBaseName [get, set]
 Base name from which names of individual components of independent variables (names of parameters used within fucntion definitions in scripts) are derived in the case that these names are not defined.
string[] IndependentVariableNames [get, set]
 Names of variables (within functions in the loadable scripts) that hold the independent variables (components of vector of parameters).
string ValueDefinitionString [get, set]
 Expression that defines function value.
string[] GradientDefinitionStrings [get, set]
 Expressions that defines function gradient components.
string[][] HessianDefinitionStrings [get, set]
 Expressions that define function hessian components.
string Code [get, set]
 Generated script code.
ScriptLoaderBase Loader [get, set]
 Script loader used to load and instantiate real function class generated from script.
bool IsCompiled [get, set]
 Whether the current function definition has been compiled or not.
string ScriptClassName [get, set]
 Name of the script class that containe definition of the compiled real function class.
LoadableScriptScalarFunctionBase Creator [get]
 Returns an object of the dynamically compiled class that can create function objects.

Private Member Functions

void AppendFunctonDefinition (StringBuilder sb, string functionName, string definitionString, int numIndents)
 Appends to the apecified string builder the C# definition of a function of parameters returning double. Function is of form 'protected override double (double arg)'.
void AppendFunctonDefinition (StringBuilder sb, string functionName, string[] definitionStrings, string returnedVectorName, int numIndents)
 Appends to the apecified string builder the C# definition of a function of parameters returning a vector throufh IVector argument. Function is of form 'protected override double (IVector param, IVector result)'.
void AppendFunctonDefinition (StringBuilder sb, string functionName, string[][] definitionStrings, string returnedMatrixName, int numIndents)
 Appends to the apecified string builder the C# definition of a function of parameters returning a vector throufh IVector argument. Function is of form 'protected override double (IVector param, IVector result)'.

Private Attributes

object _mainLock = new object()
string _returnedValueName = DefaultReturnedValueName
string _functionArgumentParametersName = DefaultFunctionArgumentParametersName
string _functionArgumentGradientName = DefaultFunctionArgumentGradientName
string _functionArgumentHessianName = DefaultFunctionArgumentHessianName
string _independentVariableBaseName = DefaultIndependentVariableBaseName
string _valueDefinitionString
string _code
int _numParameters
string[] _independentVariableNames = null
string[] _gradientDefinitionStrings = null
string[][] _hessianDefinitionStrings = null
ScriptLoaderBase _loader
bool _iscompiled = false
string _scriptClassName

Detailed Description

Dynamically generates IScalarFunction classes from user definitions. User can define in string form how function, its derivative, second derivative, integral, or inverse function is calculated. Then this class can be used to compile these definitions in the wrapping script, which is then used to create the corresponding function objects.

$A Igor Jun10;


Constructor & Destructor Documentation

IG::Lib::ScalarFunctionLoader::ScalarFunctionLoader ( ) [inline]

Constructor.


Member Function Documentation

void IG::Lib::ScalarFunctionLoader::InvalidateDefinitions ( ) [inline]

Clears strings that define the function (i.e. strings that define expressions for function value, derivative, integral, inverse, etc.). Number of parameters is not reset.

void IG::Lib::ScalarFunctionLoader::SetNames ( string  returnedValueName,
string  functionArgumentName,
string[]  independentVariableNames 
) [inline]

Sets names used in generated script code.

Parameters:
returnedValueNameName of the variabble that holds returned value in functions in generated script code.
FunctionArgumentParametersNameName of function argument in generated script code.
independentVariableNamesNames of independent variable in generated script code.
string [] IG::Lib::ScalarFunctionLoader::GetDefaultIndependentVariableNames ( int  numParam) [inline]

Returns a table of default names of variables (within functions in the loadable scripts) that hold the independent variables (components of vector of parameters), for the specified number of parameters.

Parameters:
numParamNumber of parameters.
void IG::Lib::ScalarFunctionLoader::SaveCode ( string  filePath) [inline]

Saves the generated script code to the specified file. File is overwritten if it already exists.

Parameters:
filePathPath to the file where script code is saved.
void IG::Lib::ScalarFunctionLoader::AppendIndents ( StringBuilder  sb,
int  numIndent 
) [inline, protected]

Appends to the apecified string builder the specified level of indentation.

Parameters:
sbString builder to which indents are appended.
numIndenteNumber of indents that are appended.
void IG::Lib::ScalarFunctionLoader::AppendBeginComment ( StringBuilder  sb) [inline, protected]

Appends beginning of comment.

Parameters:
sbString buider that is used to assemble the compiled script.
void IG::Lib::ScalarFunctionLoader::AppendEndcomment ( StringBuilder  sb) [inline, protected]

Appends end of comment.

Parameters:
sbString buider that is used to assemble the compiled script.
void IG::Lib::ScalarFunctionLoader::AppendIndexComment ( StringBuilder  sb,
string  coponentBaseName,
int  index 
) [inline, protected]

Appends comment that denotes the componenent index.

Parameters:
sbString buider that is used to assemble the compiled script.
coponentBaseNameComponent's base name used in the comment denoting indices.
index2Second component index.
void IG::Lib::ScalarFunctionLoader::AppendIndexComment ( StringBuilder  sb,
string  coponentBaseName,
int  index1,
int  index2 
) [inline, protected]

Appends comment that denotes the componenent index.

Parameters:
sbString buider that is used to assemble the compiled script.
coponentBaseNameComponent's base name used in the comment denoting indices.
index1First component index.
index2Second component index.
void IG::Lib::ScalarFunctionLoader::AppendSetVariable ( StringBuilder  sb,
string  varName,
object  value,
int  numIndents 
) [inline, protected]

Appends to the apecified string builder the C# statements that sets the specified variable to the specified value.

Parameters:
sbString builder to which the statement is appended.
varNameName of the variable that is set.
valueValue that is assigned to the variable.
numIndentsNumber of indents that are written before code lines.
void IG::Lib::ScalarFunctionLoader::AppendSetVariable ( StringBuilder  sb,
string  varName,
string[]  values,
string  coponentBaseName,
int  numIndents 
) [inline, protected]

Appends to the apecified string builder the C# statements that sets the specified variable to the specified value.

Parameters:
sbString builder to which the statement is appended.
varNameName of the variable that is set.
valueValue that is assigned to the variable.
numIndentsNumber of indents that are written before code lines.
void IG::Lib::ScalarFunctionLoader::AppendSetVariable ( StringBuilder  sb,
string  varName,
stringvalues  [][],
string  componentBaseName,
int  numIndents 
) [inline, protected]

Appends to the apecified string builder the C# statements that sets the specified variable to the specified value.

Parameters:
sbString builder to which the statement is appended.
varNameName of the variable that is set.
valueValue that is assigned to the variable.
numIndentsNumber of indents that are written before code lines.
void IG::Lib::ScalarFunctionLoader::AppendFunctonDefinition ( StringBuilder  sb,
string  functionName,
string  definitionString,
int  numIndents 
) [inline, private]

Appends to the apecified string builder the C# definition of a function of parameters returning double. Function is of form 'protected override double (double arg)'.

Parameters:
sbString builder to which the code (function definition) is appended.
functionNameName of the function.
definitionStringExpression that specifies how the returned value is calculated.
numIndentsNumber of indents that are prepended before code lines.
void IG::Lib::ScalarFunctionLoader::AppendFunctonDefinition ( StringBuilder  sb,
string  functionName,
string[]  definitionStrings,
string  returnedVectorName,
int  numIndents 
) [inline, private]

Appends to the apecified string builder the C# definition of a function of parameters returning a vector throufh IVector argument. Function is of form 'protected override double (IVector param, IVector result)'.

Parameters:
sbString builder to which the code (function definition) is appended.
functionNameName of the function.
definitionStringsExpressions that specify how components of the returned vector are calculated.
returnedVectorNameName of the formal vector argument that contains returned values.
numIndentsNumber of indents that are prepended before code lines.
string IG::Lib::ScalarFunctionLoader::getDefinitionString ( string  definitions[][],
int  ind1,
int  ind2 
) [inline]

Returns the specific definition string out of a 2D jagged array of definitions, or null if the specified definition is not contained in the array of definitions.

Parameters:
definitionsDefinitions arranged in a 2D jagged array.
ind1First index.
ind2Second index.
void IG::Lib::ScalarFunctionLoader::AppendFunctonDefinition ( StringBuilder  sb,
string  functionName,
string  definitionStrings[][],
string  returnedMatrixName,
int  numIndents 
) [inline, private]

Appends to the apecified string builder the C# definition of a function of parameters returning a vector throufh IVector argument. Function is of form 'protected override double (IVector param, IVector result)'.

Parameters:
sbString builder to which the code (function definition) is appended.
functionNameName of the function.
definitionStringsExpressions that specify how components of the returned vector are calculated.
returnedVectorNameName of the formal vector argument that contains returned values.
numIndentsNumber of indents that are prepended before code lines.
string IG::Lib::ScalarFunctionLoader::GetParametersPlainListString ( ) [inline]

Returns a string representation of the list of independent variables, separated by commas but not embedded in any braces.

virtual string IG::Lib::ScalarFunctionLoader::GetCode ( ) [inline, protected, virtual]

Generates and returns script code for dynamically loadable function definition.

string IG::Lib::ScalarFunctionLoader::Compile ( ) [inline]

Compiles the code that contains dynamically loadable definition of a real function of one variable.

Returns:
LoadableScalarFunctionBase IG::Lib::ScalarFunctionLoader::CreateScalarFunction ( ) [inline]

Creates and returns an instance of dynamically compiled scalar function object.

LoadableScalarFunctionBase IG::Lib::ScalarFunctionLoader::CreateScalarFunction ( IAffineTransformation  transf) [inline]

Creates and returns an instance of dynamically compiled scalar function object, where the scalar funciton is obtained from user defined expressions and affine trensformation of vector parameters.

$A Igor Sep11;

static void IG::Lib::ScalarFunctionLoader::Example ( ) [inline, static]

Example of use of the ScalarFunctionLoader class. Creates a function loader and uses it for dynamic definition of functions.

$A Igor Jun10;

static void IG::Lib::ScalarFunctionLoader::Example ( string  scriptPath) [inline, static]

Example of use of the ScalarFunctionLoader class. Creates a function loader and uses it for dynamic definition of functions.

Parameters:
scriptPathPath where script that defines the function is saved. If null or empty string then script is not saved to a file.

$A Igor Jun10;


Member Data Documentation

object IG::Lib::ScalarFunctionLoader::_mainLock = new object() [private]
const string IG::Lib::ScalarFunctionLoader::DefaultScriptClassName = "ScalarFunctionScript"

Default name of the class used in loadable scripts containing user definitions of scalar function class.

Name of the function that initializes variables realated to dynamically loaded scalar function class.

Name of variable (internal in class defined in loadable script) that holds the number of parameters.

const string IG::Lib::ScalarFunctionLoader::VarNameReturnedValueName = "_returnedValueName"

Name of variable (internal in class defined in loadable script) that holds the name of local variable (defined within functions in the dynamically loaded script) where returned value is stored.

Default name of the variable that holds returned value in script functions.

const string IG::Lib::ScalarFunctionLoader::VarNameFunctionArgumentParametersName = "_functionArgumentParametersName"

Name of variable (internal in class defined in loadable script) that holds the names of function argument (defined within functions in the dynamically loaded script) through which independent variable is passed.

Default name of vector of parameters in function arguments in script functions.

const string IG::Lib::ScalarFunctionLoader::VarNameFunctionArgumentGradientName = "_functionArgumentGradientName"

Default name of gradient vector in function arguments in script functions.

const string IG::Lib::ScalarFunctionLoader::VarNameFunctionArgumentHessianName = "_functionArgumentHessianName"

Default name of hessian vector in function arguments in script functions.

Default base name of the independent variables (components of parameter vector) in expression definitions used in scripts to define calculation of function values, derivatives, etc.

const string IG::Lib::ScalarFunctionLoader::VarNameIndependentVariableNames = "_independentVariableNames"
const string IG::Lib::ScalarFunctionLoader::VarNameValueDefinitionString = "_valueDefinitionString"

Name of the variable (internal in class defined in loadable script) that holds user definition (as string) of function value.

const string IG::Lib::ScalarFunctionLoader::VarNameGradientDefinitionStrings = "_gradientDefinitionStrings"

Name of the variable (internal in class defined in loadable script) that holds user definition (as string) of function derivative.

const string IG::Lib::ScalarFunctionLoader::VarNameHessianDefinitionStrings = "_hessianDefinitionStrings"

Name of the variable (internal in class defined in loadable script) that holds user definition (as string) of function second derivative.

Name of the function (internal in class defined in loadable script) that defines calculation of function value.

const string IG::Lib::ScalarFunctionLoader::FuncNameGradientDefinition = "ReferenceGradientPlain"

Name of the function (internal in class defined in loadable script) that defines calculation of function gradient.

const string IG::Lib::ScalarFunctionLoader::FuncNameHessianDefinition = "ReferenceHessianPlain"

Name of the function (internal in class defined in loadable script) that defines calculation of function hessian.

Name of the variable (internal in class defined in loadable script) that holds a flag telling whether calculation of function value is implemented.

const string IG::Lib::ScalarFunctionLoader::VarNameGradientDefined = "_gradientDefined"

Name of the variable (internal in class defined in loadable script) that holds a flag telling whether calculation of function gradient is implemented.

const string IG::Lib::ScalarFunctionLoader::VarNameHessianDefined = "_hessianDefined"

Name of the variable (internal in class defined in loadable script) that holds a flag telling whether calculation of function hessian is implemented.


Property Documentation

object IG::Lib::ScalarFunctionLoader::Lock [get]

Current object's central lock object.

Implements IG::Lib::ILockable.

bool IG::Lib::ScalarFunctionLoader::ValueDefined [get]

Whether calculation of function value is defined.

bool IG::Lib::ScalarFunctionLoader::GradientDefined [get]

Whether calculation of function gradient is defined.

bool IG::Lib::ScalarFunctionLoader::HessianDefined [get]

Whether calculation of function Hessian is defined.

string IG::Lib::ScalarFunctionLoader::ReturnedValueName [get, set]

Name of variable (within functions in the loadable scripts) that temporarily holds the returned value(s). Set to constant DefaultReturnedValueName by default.

string IG::Lib::ScalarFunctionLoader::FunctionArgumentParametersName [get, set]

Name of parameters vector in function arguments (in functions in the loadable scripts). Set to constant DefaultFunctionArgumentParametersName by default.

string IG::Lib::ScalarFunctionLoader::FunctionArgumentGradientName [get, set]

Name of gradient vector in function arguments (in functions in the loadable scripts). Set to constant DefaultFunctionArgumentGradientName by default.

string IG::Lib::ScalarFunctionLoader::FunctionArgumentHessianName [get, set]

Name of Hessian matrix in function arguments (in functions in the loadable scripts). Set to constant DefaultFunctionArgumentHessianName by default.

int IG::Lib::ScalarFunctionLoader::NumParameters [get, set]

Number of parameters of the scalar function that will be defined by a generated script

  • dimension of space in which the scalar function is defined.

string IG::Lib::ScalarFunctionLoader::IndependentVariableBaseName [get, set]

Base name from which names of individual components of independent variables (names of parameters used within fucntion definitions in scripts) are derived in the case that these names are not defined.

string [] IG::Lib::ScalarFunctionLoader::IndependentVariableNames [get, set]

Names of variables (within functions in the loadable scripts) that hold the independent variables (components of vector of parameters).

string IG::Lib::ScalarFunctionLoader::ValueDefinitionString [get, set]

Expression that defines function value.

string [] IG::Lib::ScalarFunctionLoader::GradientDefinitionStrings [get, set]

Expressions that defines function gradient components.

string [][] IG::Lib::ScalarFunctionLoader::HessianDefinitionStrings [get, set]

Expressions that define function hessian components.

string IG::Lib::ScalarFunctionLoader::Code [get, set]

Generated script code.

ScriptLoaderBase IG::Lib::ScalarFunctionLoader::Loader [get, set]

Script loader used to load and instantiate real function class generated from script.

$A Igor Jun10 Aug10;

bool IG::Lib::ScalarFunctionLoader::IsCompiled [get, set]

Whether the current function definition has been compiled or not.

string IG::Lib::ScalarFunctionLoader::ScriptClassName [get, set]

Name of the script class that containe definition of the compiled real function class.

LoadableScriptScalarFunctionBase IG::Lib::ScalarFunctionLoader::Creator [get]

Returns an object of the dynamically compiled class that can create function objects.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Enumerations Properties Events