Home
Install
Use
Develop
Support
News
Credits
hosted by
|
11 #ifndef __MEAL_BasisRule_H
12 #define __MEAL_BasisRule_H
15 #include "MEAL/Composite.h"
16 #include "MEAL/Null.h"
28 template< unsigned N, class T>
29 class BasisRule : public T
34 typedef typename T::Result Result;
37 BasisRule () : composite (this) { init(); }
63 void calculate (Result& result, std::vector<Result>* gradient);
90 template< unsigned N, class T>
93 return "BasisRule<" + tostring(N) + "," + std::string(T::Name)+ ">";
96 template< unsigned N, class T>
103 set_model (rule.model);
104 set_transformation (rule.transformation);
109 template< unsigned N, class T>
115 std::cerr << "MEAL::BasisRule::set_model"
116 " unmap old model" << std::endl;
117 composite.unmap (model);
126 std::cerr << "MEAL::BasisRule::set_model"
127 " map new model" << std::endl;
129 composite.map (model);
131 Vector<N,double> params;
133 for ( unsigned i=0; i<N; i++)
135 model->set_infit (i, false);
136 params[i] = model->get_param(i);
139 params = inv(transformation) * params;
141 for ( unsigned i=0; i<N; i++)
142 parameters.set_param(i, params[i]);
146 template< unsigned N, class T>
149 transformation = xform;
154 Vector<N,double> params;
156 for ( unsigned i=0; i<N; i++)
157 params[i] = model->get_param(i);
159 params = inv(transformation) * params;
161 for ( unsigned i=0; i<N; i++)
162 parameters.set_param(i, params[i]);
165 template< unsigned N, class T>
167 std::vector<Result>* grad)
170 throw Error (InvalidState, "MEAL::BasisRule::calculate", "no model");
173 std::cerr << "MEAL::BasisRule::calculate" << std::endl;
175 Vector<N,double> params;
176 for ( unsigned i=0; i<N; i++)
177 params[i] = parameters.get_param(i);
179 params = transformation * params;
181 for ( unsigned i=0; i<N; i++)
182 model->set_param (i, params[i]);
184 std::vector<Result> model_grad;
185 std::vector<Result>* model_grad_ptr = 0;
187 model_grad_ptr = & model_grad;
189 result = model->evaluate (model_grad_ptr);
193 unsigned ngrad = this->get_nparam();
194 grad->resize (ngrad);
197 for (igrad=0; igrad<ngrad; igrad++)
198 (*grad)[igrad] = 0.0;
201 ProjectGradient (model, model_grad, *(grad));
204 std::vector<Result> fgrad (N, 0);
206 for (igrad=0; igrad<N; igrad++)
207 for ( unsigned idep=0; idep<N; idep++)
208 fgrad[igrad] += model_grad[idep] * transformation[idep][igrad];
210 ProjectGradient (project, fgrad, *(grad));
215 std::cerr << "MEAL::BasisRule::calculate result\n"
216 " " << result << std::endl;
218 std::cerr << "MEAL::BasisRule::calculate gradient\n";
219 for ( unsigned i=0; i<grad->size(); i++)
220 std::cerr << " " << i << ":" << this->get_infit(i) << "="
221 << (*grad)[i] << std::endl;
Null function holds an arbitrary number of parameters. Definition: Null.h:25
Null parameters The free parameters. Definition: BasisRule.h:79
void set_model(T *model) Set the Function with the parameters to be transformed. Definition: BasisRule.h:110
void calculate(Result &result, std::vector< Result > *gradient) Return the Result and its gradient. Definition: BasisRule.h:166
Changes the basis of the parameterization. Definition: BasisRule.h:34
Parameter policy for composite functions. Definition: Composite.h:25
std::string get_name() const Return the name of the class. Definition: BasisRule.h:91
Matrix< N, N, double > transformation The basis transformation. Definition: BasisRule.h:85
Namespace in which all modeling and calibration related code is declared. Definition: ExampleComplex2.h:16
Project< T > model The Function with the parameters to be transformed. Definition: BasisRule.h:76
void resize(unsigned nparam) Resize, setting fit=true for new parameters. Definition: Null.C:47
BasisRule & operator=(const BasisRule &rule) Assignment operator. Definition: BasisRule.h:98
BasisRule() Default constructor. Definition: BasisRule.h:47
void set_transformation(const Matrix< N, N, double > &xform) Set the basis transformation. Definition: BasisRule.h:147
void map(Project< Type > &model) Convenience interface to map (Projection*) Definition: Composite.h:90
Project< Null > project The projection of the free parameters. Definition: BasisRule.h:82
Generated using doxygen 1.8.17
|