Composite.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/Composite.h
10 
11 #ifndef __Composite_H
12 #define __Composite_H
13 
14 #include "MEAL/Function.h"
15 #include "MEAL/Projection.h"
16 
17 namespace MEAL {
18 
20  class Composite : public ParameterPolicy {
21 
22  public:
23 
25  Composite (Function* context);
26 
28  Composite* clone (Function* context) const { return 0; }
29 
31  unsigned get_nmodel () const;
32 
34  std::string class_name() const;
35 
36  // ///////////////////////////////////////////////////////////////////
37  //
38  // ParameterPolicy implementation
39  //
40  // ///////////////////////////////////////////////////////////////////
41 
43  unsigned get_nparam () const;
44 
46  std::string get_name (unsigned index) const;
47 
49  std::string get_description (unsigned index) const;
50 
52  double get_param (unsigned index) const;
53 
55  void set_param (unsigned index, double value);
56 
58  double get_variance (unsigned index) const;
59 
61  void set_variance (unsigned index, double variance);
62 
64  bool get_infit (unsigned index) const;
65 
67  void set_infit (unsigned index, bool flag);
68 
69  // ///////////////////////////////////////////////////////////////////
70  //
71  // ArgumentPolicy implementation
72  //
73  // ///////////////////////////////////////////////////////////////////
74 
76  void set_argument (unsigned dimension, Argument* axis);
77 
79  template <class Type>
80  void map (Project<Type>& model)
81  {
83  std::cerr << class_name() + "map (Project<Type>)" << std::endl;
84  map (model.get_map());
85  }
86 
88  template <class Type>
89  void unmap (Project<Type>& model)
90  {
92  std::cerr << class_name() + "unmap (Project<Type>)" << std::endl;
93  unmap (model.get_map());
94  }
95 
97  void map (Projection* model);
98 
100  void unmap (Projection* model);
101 
103  void clear ();
104 
106  void get_imap (const Function* model,
107  std::vector<unsigned>::iterator& imap) const;
108 
110  void attribute_changed (Function::Attribute attribute);
111 
112  protected:
113 
115  friend class Projection;
116 
118  unsigned find_Function (Function* model) const;
119 
121  unsigned find_Projection (Projection* model) const;
122 
123  private:
124 
126  std::vector< Reference::To<Projection> > maps;
127 
129  std::vector< Reference::To<Function> > models;
130 
132  mutable unsigned nparameters;
133 
135  mutable unsigned current_model;
136 
138  mutable unsigned current_index;
139 
141  mutable bool remap_needed;
142 
144  mutable bool disable_callbacks;
145 
147  mutable bool component_shares_this;
148 
150  void init ();
151 
153  void add_component (Function*, std::vector<unsigned>& imap);
154 
156  void remove_component (Function*);
157 
159  void remap ();
160 
162  void remap_later ();
163 
165  void callbacks ();
166 
168  void recount () const;
169 
171  const Function* get_Function (unsigned& index) const;
172 
174  Function* get_Function (unsigned& index);
175 
177  void reference_check (unsigned imodel, const char* method) const;
178 
179  };
180 
181  void get_imap (const Function* composite, const Function* component,
182  std::vector<unsigned>& imap);
183 
184 }
185 
186 
187 #endif
188 
void set_variance(unsigned index, double variance)
Set the variance of the specified parameter.
Definition: Composite.C:87
std::string get_description(unsigned index) const
Return the name of the specified parameter.
Definition: Composite.C:59
void clear()
Clear all models.
Definition: Composite.C:35
bool has_parameter_policy() const
Some wrappers may not have a parameter policy.
Definition: Function.h:188
void set_infit(unsigned index, bool flag)
Set flag for parameter at index to be fitted.
Definition: Composite.C:101
std::string class_name() const
Get the name used in verbose output.
Definition: Composite.C:127
unsigned get_nparam() const
Return the number of parameters.
Definition: Function.h:115
void set_argument(unsigned dimension, Argument *axis)
Set the independent variable of the specified dimension.
Definition: Composite.C:109
const ParameterPolicy * get_parameter_policy() const
Provide access to the parameter_policy attribute.
Definition: Function.h:184
unsigned get_nparam() const
Return the number of parameters.
Definition: Composite.C:43
unsigned find_Projection(Projection *model) const
Return the index for the specified model.
Definition: Composite.C:573
Pure virtual base class of function arguments.
Definition: Argument.h:30
Parameter policy for composite functions.
Definition: Composite.h:25
void attribute_changed(Function::Attribute attribute)
Method called when a Function attribute has changed.
Definition: Composite.C:479
Composite(Function *context)
Default constructor.
Definition: Composite.C:18
Composite * clone(Function *context) const
Clone constructor.
Definition: Composite.h:38
void disconnect(Class *instance, Method method)
void get_imap(const Function *model, std::vector< unsigned >::iterator &imap) const
Get the mapping for the given Function.
Definition: Composite.C:591
Function * get_Function()
Return the model.
Definition: Projection.C:50
Function * get_context() const
Return the Function for whom this policy operates.
Definition: FunctionPolicy.h:37
Namespace in which all modeling and calibration related code is declared.
Definition: ExampleComplex2.h:16
static bool verbose
Verbosity flag.
Definition: Function.h:54
Manages a Function and the mapping of its parameters into a Composite.
Definition: Projection.h:27
static bool very_verbose
Low-level verbosity flag.
Definition: Function.h:57
std::vector< unsigned > imap
The parameter index mapping into Composite.
Definition: Projection.h:56
Reference::To< Composite, false > meta
The Composite into which the model is mapped.
Definition: Projection.h:59
@ ParameterCount
Number of Function parameters, as returned by get_nparam.
Definition: Function.h:169
void set_param(unsigned index, double value)
Set the value of the specified parameter.
Definition: Composite.C:73
unsigned find_Function(Function *model) const
Return the index for the specified model.
Definition: Composite.C:558
virtual std::string get_name() const =0
Return the name of the class.
void connect(Class *instance, Method method)
void unmap(Project< Type > &model)
Convenience interface to unmap (Projection*)
Definition: Composite.h:99
Managers of Function parameters.
Definition: ParameterPolicy.h:24
Pure virtual base class of all functions.
Definition: Function.h:49
bool get_infit(unsigned index) const
Return true if parameter at index is to be fitted.
Definition: Composite.C:94
double get_variance(unsigned index) const
Return the variance of the specified parameter.
Definition: Composite.C:80
Attribute
Function attributes that require the attention of Composite models.
Definition: Function.h:167
Callback< Attribute > changed
Callback executed when a Function Attribute has been changed.
Definition: Function.h:175
void map(Project< Type > &model)
Convenience interface to map (Projection*)
Definition: Composite.h:90
Template combines a reference to a Component and its Projection.
Definition: Projection.h:65
Adapts an object with the ArgumentPolicy interface.
Definition: ArgumentPolicyAdapter.h:25
std::string get_name(unsigned index) const
Return the name of the specified parameter.
Definition: Composite.C:52
Projection * get_map()
Return the Projection.
Definition: Projection.h:85
@ Evaluation
Function evaluation, as returned by the evaluate method.
Definition: Function.h:171
unsigned get_nmodel() const
Get the number of models mapped into this model.
Definition: Composite.C:133
double get_param(unsigned index) const
Return the value of the specified parameter.
Definition: Composite.C:66

Generated using doxygen 1.8.17