21 #ifndef SAMPLE_BASE_H_INCLUDED
22 #define SAMPLE_BASE_H_INCLUDED
25 #include <boost/function.hpp>
30 #include <boost/optional.hpp>
31 #include <boost/algorithm/string.hpp>
32 #include <boost/foreach.hpp>
54 template <
class Model>
76 Step_result(
const std::string& type_,
const std::string name_,
bool accept_,
double lt_) :
85 Step_result(
const std::string& type_,
const std::string name_,
bool accept_,
double lt_,
const Model*
m) :
105 std::map<std::string, double>
extra;
111 template <
class Model>
112 inline std::ostream& operator<<(std::ostream& ost, const Step_result<Model>& result)
114 std::string tmp = result.type;
116 assert(!tmp.empty());
119 ost.precision(std::numeric_limits<double>::digits10);
139 ost << result.accept <<
" ";
143 typedef std::map<std::string, double>::value_type Map_pair;
145 BOOST_FOREACH(
const Map_pair& pair, result.extra)
147 ost <<
' ' << pair.first <<
'=' << pair.second;
159 template <
class Model>
160 class Step_log :
public std::deque<Step_result<Model> >
172 this->insert(this->end(), op.begin(), op.end());
177 template <
class Model>
178 inline std::ostream& operator<<(std::ostream& ost, const Step_log<Model>& log)
181 for(; it != log.end(); it++)
185 if(it != log.end() - 1)
211 template <
typename Model>
214 typedef boost::function1<double, const Model&>
Type;
225 template <
typename Model>
228 typedef boost::function2<Step_log<Model>, Model&,
double>
Type;
246 template <
typename Model>
249 typedef typename boost::function2<void, const Model&, const Step_log<Model>&>
Type;
267 template <
typename Model>
270 typedef typename boost::function2<double, const Model&, size_t>
Type;
279 template <
typename Model>
282 typedef typename boost::function3<void, Model&, size_t, double>
Type;
291 template <
typename Model>
294 typedef typename boost::function3<void, Model&, size_t, double>
Type;
302 template <
typename Model>
305 typedef typename boost::function1<size_t, const Model&>
Type;
314 template <
typename Model>
317 typedef boost::function1<kjb::Vector, const Model&>
Type;
403 template <
typename Model>
406 typedef boost::function2<Mh_proposal_result, const Model&, Model&>
Type;
423 template <
typename Model>
426 typedef boost::function2<boost::optional<double>, Model&,
size_t>
Type;
double fwd_prob
log forward proposal probability
Definition: sample_base.h:379
Mh_proposal_result(const std::string &type_=std::string(""))
Definition: sample_base.h:337
Indicates the result of an MH proposal. It is simply a pair of probabilities, forward and backward...
Definition: sample_base.h:334
Step_log< Model > & operator+=(const Step_log< Model > &op)
Definition: sample_base.h:170
Returns the dimension of the model.
Definition: sample_base.h:303
std::map< std::string, double > extra
Definition: sample_base.h:105
boost::function2< boost::optional< double >, Model &, size_t > Type
Definition: sample_base.h:426
Structure for returning results of a single sampling move.
Definition: sample_base.h:55
Definition: sample_base.h:160
bool no_change
proposal didn't modify the model
Definition: sample_base.h:386
std::string type
Definition: sample_base.h:95
double rev_prob
log reverse proposal probability
Definition: sample_base.h:381
static Mh_proposal_result unchanged(const std::string &type_=std::string(""))
named constructor - returns a proposal result indicating the model was not changed ...
Definition: sample_base.h:353
bool operator!=(const Mh_proposal_result &pr)
Definition: sample_base.h:365
bool accept
Definition: sample_base.h:100
Step_result()
Definition: sample_base.h:58
Definition: sample_base.h:404
boost::function3< void, Model &, size_t, double > Type
Definition: sample_base.h:282
boost::function1< double, const Model & > Type
Definition: sample_base.h:214
boost::function2< Mh_proposal_result, const Model &, Model & > Type
Definition: sample_base.h:406
Step_result(const std::string &type_, const std::string name_, bool accept_, double lt_)
Definition: sample_base.h:76
Moves the specified parameter of a model. For now, we assume all parameters are type double...
Definition: sample_base.h:292
Step_log()
Definition: sample_base.h:163
Definition: sample_base.h:315
std::string name
Definition: sample_base.h:97
boost::function1< kjb::Vector, const Model & > Type
Definition: sample_base.h:317
Definition: sample_base.h:212
Definition: sample_base.h:247
boost::function3< void, Model &, size_t, double > Type
Definition: sample_base.h:294
Mh_proposal_result & operator+=(const Mh_proposal_result &pr)
Definition: sample_base.h:370
Step_log(const Step_result< Model > &result)
construct from a single result object
Definition: sample_base.h:166
double lt
Definition: sample_base.h:102
Definition: sample_base.h:226
std::string type
Name of proposal type.
Definition: sample_base.h:383
Step_result(const std::string &type_, const std::string name_, bool accept_, double lt_, const Model *m)
Definition: sample_base.h:85
boost::function2< void, const Model &, const Step_log< Model > & > Type
Definition: sample_base.h:249
const Model * m_p
Definition: sample_base.h:108
Definition: sample_base.h:424
Gets the specified parameter of a model. For now, we assume all parameters are type double...
Definition: sample_base.h:268
boost::function2< Step_log< Model >, Model &, double > Type
Definition: sample_base.h:228
bool operator==(const Mh_proposal_result &pr)
Definition: sample_base.h:360
Sets the specified parameter of a model. For now, we assume all parameters are type double...
Definition: sample_base.h:280
Mh_proposal_result operator+(const Mh_proposal_result &pr1, const Mh_proposal_result &pr2)
Definition: sample_base.h:389
for m
Definition: APPgetLargeConnectedEdges.m:64
boost::function2< double, const Model &, size_t > Type
Definition: sample_base.h:270
Mh_proposal_result(double fp, double rp, const std::string &type_=std::string(""))
Definition: sample_base.h:345
Definition for the Vector class, a thin wrapper on the KJB Vector struct and its related functionalit...
boost::function1< size_t, const Model & > Type
Definition: sample_base.h:305
Step_result(const char *type_, bool accept_, double lt_)
Definition: sample_base.h:67