20
20
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
22
* @author: $LastChangedBy: dutka $
23
* @date: $LastChangedDate: 2008-06-26 13:50:17 +0200 (jeu, 26 jun 2008) $
24
* Id: $Id: NumericalMathFunctionImplementation.cxx 862 2008-06-26 11:50:17Z dutka $
23
* @date: $LastChangedDate: 2008-10-15 17:56:07 +0200 (mer 15 oct 2008) $
24
* Id: $Id: NumericalMathFunctionImplementation.cxx 972 2008-10-15 15:56:07Z dutka $
26
26
#include "NumericalMathFunction.hxx"
27
27
#include "NumericalMathFunctionImplementation.hxx"
62
61
/* Default constructor */
63
62
NumericalMathFunctionImplementation::NumericalMathFunctionImplementation()
64
: PersistentObject(OT::DefaultName),
65
p_evaluationImplementation_(new NoNumericalMathEvaluationImplementation(OT::DefaultName)),
66
p_gradientImplementation_(new NoNumericalMathGradientImplementation(OT::DefaultName)),
67
p_hessianImplementation_(new NoNumericalMathHessianImplementation(OT::DefaultName)),
64
p_evaluationImplementation_(new NoNumericalMathEvaluationImplementation),
65
p_gradientImplementation_(new NoNumericalMathGradientImplementation),
66
p_hessianImplementation_(new NoNumericalMathHessianImplementation),
68
67
p_initialEvaluationImplementation_(p_evaluationImplementation_),
69
68
p_initialGradientImplementation_(p_gradientImplementation_),
70
69
p_initialHessianImplementation_(p_hessianImplementation_)
75
/* Default constructor */
74
/* Constructor from a wrapper name */
76
75
NumericalMathFunctionImplementation::NumericalMathFunctionImplementation(const String & name)
77
76
: PersistentObject(name),
78
p_evaluationImplementation_(new NoNumericalMathEvaluationImplementation(OT::DefaultName)),
79
p_gradientImplementation_(new NoNumericalMathGradientImplementation(OT::DefaultName)),
80
p_hessianImplementation_(new NoNumericalMathHessianImplementation(OT::DefaultName)),
81
p_initialEvaluationImplementation_(p_evaluationImplementation_),
82
p_initialGradientImplementation_(p_gradientImplementation_),
83
p_initialHessianImplementation_(p_hessianImplementation_)
85
// We need to constructs object in the body because of some useful temporary
86
// It also speeds the creation of the object because the wrapper file is parsed only once
89
// Find the path of the wrapper file that describes the numerical
90
// math function interface
91
wrapperPath = Common::WrapperFile::FindWrapperPathByName( name );
93
// Open the wrapper file and get the name of the library and the names of
94
// the function, its gradient and its hessian if defined
95
// If the gradient or the hessian are not defined, ask for default ones
96
// Then create the actual functions
97
// Get also the data read inside the wrapper file and pass them to the wrapper
98
Common::WrapperFile wrapperFile( wrapperPath );
77
p_evaluationImplementation_(new NoNumericalMathEvaluationImplementation),
78
p_gradientImplementation_(new NoNumericalMathGradientImplementation),
79
p_hessianImplementation_(new NoNumericalMathHessianImplementation),
80
p_initialEvaluationImplementation_(p_evaluationImplementation_),
81
p_initialGradientImplementation_(p_gradientImplementation_),
82
p_initialHessianImplementation_(p_hessianImplementation_)
84
// Read the description file of the wrapper
85
WrapperFile wrapperFile = WrapperFile::FindWrapperByName( name );
87
// We set the implementations
88
initImplementations( wrapperFile );
91
/* Constructor from a wrapper file */
92
NumericalMathFunctionImplementation::NumericalMathFunctionImplementation(const WrapperFile & wrapperFile)
93
: PersistentObject(wrapperFile.getName()),
94
p_evaluationImplementation_(new NoNumericalMathEvaluationImplementation),
95
p_gradientImplementation_(new NoNumericalMathGradientImplementation),
96
p_hessianImplementation_(new NoNumericalMathHessianImplementation),
97
p_initialEvaluationImplementation_(p_evaluationImplementation_),
98
p_initialGradientImplementation_(p_gradientImplementation_),
99
p_initialHessianImplementation_(p_hessianImplementation_)
101
// We set the implementations
102
initImplementations( wrapperFile );
106
/* This method set the implementations with the values listed in the wrapper file */
107
void NumericalMathFunctionImplementation::initImplementations(const WrapperFile & wrapperFile)
109
const String name = wrapperFile.getName();
100
111
ComputedNumericalMathEvaluationImplementation * implementation = new ComputedNumericalMathEvaluationImplementation( name, wrapperFile );
101
112
p_evaluationImplementation_.reset(implementation);
103
114
p_gradientImplementation_.reset(new ComputedNumericalMathGradientImplementation( name, wrapperFile, implementation->getState() ));
105
116
catch (Common::Exception & ex) {
106
Log::Debug(OSS() << "DBG - " << ex.type() << " catched. Using CenteredFiniteDifferenceGradient for gradient");
117
Log::Debug(OSS() << "" << ex.type() << " catched. Using CenteredFiniteDifferenceGradient for gradient");
107
118
p_gradientImplementation_.reset(new CenteredFiniteDifferenceGradient(sqrt(CenteredFiniteDifferenceGradient::DefaultEpsilon), p_evaluationImplementation_));
111
122
p_hessianImplementation_.reset(new ComputedNumericalMathHessianImplementation( name, wrapperFile, implementation->getState() ));
113
124
catch (Common::Exception & ex) {
114
Log::Debug(OSS() << "DBG - " << ex.type() << " catched. Using CenteredFiniteDifferenceHessian for hessian");
125
Log::Debug(OSS() << "" << ex.type() << " catched. Using CenteredFiniteDifferenceHessian for hessian");
115
126
p_hessianImplementation_.reset(new CenteredFiniteDifferenceHessian(sqrt(CenteredFiniteDifferenceHessian::DefaultEpsilon), p_evaluationImplementation_));
120
131
/* Analytical formula constructor */
121
132
NumericalMathFunctionImplementation::NumericalMathFunctionImplementation(const Description & inputVariablesNames,
122
133
const Description & outputVariablesNames,
123
const Description & formulas,
125
: PersistentObject(name),
126
p_evaluationImplementation_(new AnalyticalNumericalMathEvaluationImplementation(inputVariablesNames, outputVariablesNames, formulas, name)),
134
const Description & formulas)
135
: PersistentObject(),
136
p_evaluationImplementation_(new AnalyticalNumericalMathEvaluationImplementation(inputVariablesNames, outputVariablesNames, formulas)),
127
137
p_gradientImplementation_(new CenteredFiniteDifferenceGradient(CenteredFiniteDifferenceGradient::DefaultEpsilon, p_evaluationImplementation_)),
128
138
p_hessianImplementation_(new CenteredFiniteDifferenceHessian(CenteredFiniteDifferenceHessian::DefaultEpsilon, p_evaluationImplementation_)),
129
139
p_initialEvaluationImplementation_(p_evaluationImplementation_),
136
146
/* Single function implementation constructor */
137
NumericalMathFunctionImplementation::NumericalMathFunctionImplementation(const EvaluationImplementation & evaluationImplementation,
139
: PersistentObject(name),
147
NumericalMathFunctionImplementation::NumericalMathFunctionImplementation(const EvaluationImplementation & evaluationImplementation)
148
: PersistentObject(),
140
149
p_evaluationImplementation_(evaluationImplementation),
141
150
p_gradientImplementation_(new CenteredFiniteDifferenceGradient(CenteredFiniteDifferenceGradient::DefaultEpsilon, p_evaluationImplementation_)),
142
151
p_hessianImplementation_(new CenteredFiniteDifferenceHessian(CenteredFiniteDifferenceHessian::DefaultEpsilon, p_evaluationImplementation_)),
150
159
/* Constructor from implementations */
151
160
NumericalMathFunctionImplementation::NumericalMathFunctionImplementation(const EvaluationImplementation & evaluationImplementation,
152
161
const GradientImplementation & gradientImplementation,
153
const HessianImplementation & hessianImplementation,
155
: PersistentObject(name),
162
const HessianImplementation & hessianImplementation)
163
: PersistentObject(),
156
164
p_evaluationImplementation_(evaluationImplementation),
157
165
p_gradientImplementation_(gradientImplementation),
158
166
p_hessianImplementation_(hessianImplementation),