KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sample_concept.h
Go to the documentation of this file.
1 /* $Id: sample_concept.h 17393 2014-08-23 20:19:14Z predoehl $ */
2 /* =========================================================================== *
3  |
4  | Copyright (c) 1994-2010 by Kobus Barnard (author)
5  |
6  | Personal and educational use of this code is granted, provided that this
7  | header is kept intact, and that the authorship is not misrepresented, that
8  | its use is acknowledged in publications, and relevant papers are cited.
9  |
10  | For other use contact the author (kobus AT cs DOT arizona DOT edu).
11  |
12  | Please note that the code in this file has not necessarily been adequately
13  | tested. Naturally, there is no guarantee of performance, support, or fitness
14  | for any particular task. Nonetheless, I am interested in hearing about
15  | problems that you encounter.
16  |
17  | Author: Kyle Simek, Ernesto Brau
18  * =========================================================================== */
19 
20 #ifndef SAMPLE_CONCEPT_H_INCLUDED
21 #define SAMPLE_CONCEPT_H_INCLUDED
22 
23 #include <boost/concept_check.hpp>
24 #include <boost/concept_archetype.hpp>
25 #include <sample_cpp/sample_base.h>
26 
27 
28 // Forward declarations
29 // (should we just include sample_base.h?)
30 //struct Mh_proposal_result;
31 //template<class Model> class Step_log<Model>;
32 
40 template <class X>
41 struct BaseModel
42 {
43  BOOST_CONCEPT_ASSERT((boost::Assignable<X>));
44  //BOOST_CONCEPT_ASSERT((boost::DefaultConstructible<X>));
45 };
46 
47 
48 template <class Func, class Model>
50  boost::UnaryFunction<Func, double, const Model&>
51 {
52 public:
53  // Arg must be a BaseModel
55 };
56 
57 
58 
59 template <class Func, class Model>
60 struct ModelProposer :
61  boost::BinaryFunction<Func, Mh_proposal_result, const Model&, Model&>
62 {
63 public:
64  // Model must be a BaseModel
66 };
67 
68 
72 template <class X>
73 struct VectorModel : public BaseModel<X>
74 {
75  typedef typename X::value_type Type;
76 
78  {
79  X* i;
80  const X* c_i;
81 
82  const Type& c_v = (*c_i)[0];
83  Type& v = (*i)[0];
84  size_t size = dimensionality(v);
85  }
86 };
87 
88 template <class T>
89 size_t dimensionality(const T& v)
90 {
91  return v.size();
92 }
93 
97 /* template <class X>
98 struct GibbsModel : public BaseModel<X>
99 {
100  BOOST_CONCEPT_USAGE(GibbsModel)
101  {
102  const X* c_i;
103 
104  size_t size = gibbs_size(*c_i);
105  }
106 }; */
107 
111 /* template <class X>
112 struct HmcModel : public BaseModel<X>
113 {
114  BOOST_CONCEPT_USAGE(HmcModel)
115  {
116  const X* c_i;
117 
118  size_t size = hmc_size(*c_i);
119  }
120 }; */
121 
122 template <class X>
124 {
125 public:
126  typedef typename X::Value_type Value_type;
127  typedef typename X::Model_type Model;
128 
129  // Arg must be a BaseModel
131 
132  BOOST_CONCEPT_ASSERT((boost::BinaryFunction<X, void, const Model&, const Step_log<Model>&>));
133 
135  {
136  const X* i = NULL;
137  const Value_type& vr = i->get(); // must have "get" function that returns const-reference to value_type;
138 
139  boost::ignore_unused_variable_warning(vr);
140  }
141 };
142 
143 template <class X>
144 struct Updatable
145 {
146  // must have a typedef ::update_type
147  typedef typename X::Update_type Update_type;
148 
150  {
151  // must have a method called "update" that receives update_type
152  i->update(*u);
153  }
154 
155 private:
156  X* i;
157  const Update_type* u;
158 };
159 
160 template <class X>
162 {
164  {
165  // must have a method called "set_temperature" that receives a double
166  double t;
167  i->set_temperature(t);
168  }
169 
170 private:
171  X* i;
172 };
173 
174 
176 {
177 public:
178  typedef base_model_archetype self;
179 
181  self& operator=(const self&){ return *this; }
182 };
183 
184 
186 {
187 public:
188  typedef double Value_type;
189  const Value_type& operator[](unsigned int /*i*/) const
190  {
191  static Value_type result = 0.0;
192  return result;
193  }
194 
195  Value_type& operator[](unsigned int /*i*/)
196  {
197  static Value_type result = 0.0;
198  return result;
199  }
200 };
201 
202 template <class Model>
204  public boost::unary_function_archetype<const Model, double>
205 {
206 private:
208 public:
209  model_evaluator_archetype(boost::detail::dummy_constructor c) :
210  boost::unary_function_archetype<const Model, double>(c){}
211 };
212 
213 template <class Model>
215  public boost::binary_function_archetype<const Model, Model, Mh_proposal_result>
216 {
217  private:
219  public:
220  model_proposer_archetype(boost::detail::dummy_constructor c) :
221  boost::binary_function_archetype<const Model, Model, Mh_proposal_result>(c){}
222 };
223 
224 
225 template <class Model>
227  public boost::binary_function_archetype<const Model, const Step_log<Model>, void>
228 {
229  private:
231  public:
232  model_recorder_archetype(boost::detail::dummy_constructor c) :
233  boost::binary_function_archetype<const Model, const Step_log<Model>, void>(c){}
234 };
235 
236 #endif /*SAMPLE_CONCEPT_H_INCLUDED */
237 
const Value_type & operator[](unsigned int) const
Definition: sample_concept.h:189
Definition: sample_concept.h:123
size_t dimensionality(const T &v)
Definition: sample_concept.h:89
Definition: sample_concept.h:49
Definition: sample_concept.h:175
X::Update_type Update_type
Definition: sample_concept.h:147
X::Model_type Model
Definition: sample_concept.h:127
BOOST_CONCEPT_USAGE(Updatable)
Definition: sample_concept.h:149
Definition: sample_concept.h:60
Indicates the result of an MH proposal. It is simply a pair of probabilities, forward and backward...
Definition: sample_base.h:334
BOOST_CONCEPT_ASSERT((boost::Assignable< X >))
Definition: sample_concept.h:73
self & operator=(const self &)
Definition: sample_concept.h:181
model_recorder_archetype(boost::detail::dummy_constructor c)
Definition: sample_concept.h:232
Definition: sample_concept.h:203
Value_type & operator[](unsigned int)
Definition: sample_concept.h:195
Definition: sample_base.h:160
base_model_archetype()
Definition: sample_concept.h:180
BOOST_CONCEPT_ASSERT((BaseModel< Model >))
BOOST_CONCEPT_USAGE(ModelRecorder)
Definition: sample_concept.h:134
BOOST_CONCEPT_USAGE(Annealable)
Definition: sample_concept.h:163
BOOST_CONCEPT_ASSERT((BaseModel< Model >))
BOOST_CONCEPT_ASSERT((BaseModel< Model >))
double Value_type
Definition: sample_concept.h:188
Definition: sample_concept.h:144
Definition: sample_concept.h:226
Definition: sample_concept.h:214
X::value_type Type
Definition: sample_concept.h:75
model_evaluator_archetype(boost::detail::dummy_constructor c)
Definition: sample_concept.h:209
X::Value_type Value_type
Definition: sample_concept.h:126
Definition: sample_concept.h:161
get the indices of edges in each direction for i
Definition: APPgetLargeConnectedEdges.m:48
model_proposer_archetype(boost::detail::dummy_constructor c)
Definition: sample_concept.h:220
BOOST_CONCEPT_USAGE(VectorModel)
Definition: sample_concept.h:77
Definition: sample_concept.h:41
Definition: sample_concept.h:185