NegationRule.h
1//-*-C++-*-
2/***************************************************************************
3 *
4 * Copyright (C) 2004 by Willem van Straten
5 * Licensed under the Academic Free License version 2.1
6 *
7 ***************************************************************************/
8
9// psrchive/More/MEAL/MEAL/NegationRule.h
10
11#ifndef __MEAL_NegationRule_H
12#define __MEAL_NegationRule_H
13
14#include "MEAL/UnaryRule.h"
15
16namespace MEAL {
17
19 template<class T>
20 class NegationRule : public UnaryRule<T>
21 {
22
23 public:
24
25 typedef typename T::Result Result;
26
27 // ///////////////////////////////////////////////////////////////////
28 //
29 // Function implementation
30 //
31 // ///////////////////////////////////////////////////////////////////
32
34 std::string get_name () const;
35
36 protected:
37
38 // ///////////////////////////////////////////////////////////////////
39 //
40 // Optimized implementation
41 //
42 // ///////////////////////////////////////////////////////////////////
43
45 void calculate (Result& result, std::vector<Result>* gradient);
46
47 };
48
50 template<class T>
52 {
53 NegationRule<T>* result = new NegationRule<T>;
54 result->set_model (model);
55 return result;
56 }
57}
58
59template<class T>
61{
62 return "NegationRule<" + std::string(T::Name)+ ">";
63}
64
65
66template<class T>
68 std::vector<Result>* grad)
69{
70 if (!this->model)
71 throw Error (InvalidState, "MEAL::NegationRule::calculate",
72 "no model to evaluate");
73
74 if (T::verbose)
75 std::cerr << "MEAL::NegationRule::calculate" << std::endl;
76
77 result = - this->model->evaluate (grad);
78
79 if (T::verbose)
80 std::cerr << "MEAL::NegationRule::calculate result\n"
81 " " << result << std::endl;
82
83 if (!grad)
84 return;
85
86 for (unsigned igrad=0; igrad<grad->size(); igrad++)
87 (*grad)[igrad] *= -1.0;
88
89 if (T::verbose) {
90 std::cerr << "MEAL::NegationRule::calculate gradient\n";
91 for (unsigned i=0; i<grad->size(); i++)
92 std::cerr << " "
93 << i << ":" << this->get_infit(i) << "=" << (*grad)[i] << std::endl;
94 }
95
96}
97
98
99#endif
Computes the inverse of a model and its partial derivatives.
Definition NegationRule.h:21
void calculate(Result &result, std::vector< Result > *gradient)
Return the Result and its gradient.
Definition NegationRule.h:67
std::string get_name() const
Return the name of the class.
Definition NegationRule.h:60
void set_model(T *model)
Set the Function on which the operation will be performed.
Definition UnaryRule.h:67
UnaryRule()
Default constructor.
Definition UnaryRule.h:27
Project< T > model
The Function on which the operation will be performed.
Definition UnaryRule.h:44
Namespace in which all modeling and calibration related code is declared.
Definition ExampleComplex2.h:16
NegationRule< T > * negation(T *model)
Returns a new negation of the model.
Definition NegationRule.h:51

Generated using doxygen 1.14.0