11 #ifndef __MEAL_InverseRule_H
12 #define __MEAL_InverseRule_H
14 #include "MEAL/UnaryRule.h"
20 class InverseRule :
public UnaryRule<T>
25 typedef typename T::Result Result;
45 void calculate (Result& result, std::vector<Result>* gradient);
54 return "InverseRule<" + std::string(T::Name)+
">";
60 std::vector<Result>* grad)
63 throw Error (InvalidState,
"MEAL::InverseRule::calculate",
64 "no model to evaluate");
67 std::cerr <<
"MEAL::InverseRule::calculate" << std::endl;
69 result = inv( this->model->evaluate (grad) );
72 std::cerr <<
"MEAL::InverseRule::calculate result\n"
73 " " << result << std::endl;
78 for (
unsigned igrad=0; igrad<grad->size(); igrad++)
79 (*grad)[igrad] = - result * (*grad)[igrad] * result;
82 std::cerr <<
"MEAL::InverseRule::calculate gradient\n";
83 for (
unsigned i=0; i<grad->size(); i++)
85 << i <<
":" << this->get_infit(i) <<
"=" << (*grad)[i] << std::endl;