KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sample_recorder.h
Go to the documentation of this file.
1 /* $Id: sample_recorder.h 12975 2012-09-11 23:15:57Z ksimek $ */
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
18  * =========================================================================== */
19 
20 #ifndef SAMPLE_RECORDER_H
21 #define SAMPLE_RECORDER_H
22 
23 #include <limits>
24 #include <deque>
25 #include <vector>
26 #include <ostream>
27 #include <string>
28 
29 #include <boost/function.hpp>
30 #include <boost/concept_check.hpp>
31 #include <boost/concept_archetype.hpp>
32 #include <boost/lambda/lambda.hpp>
33 #include <boost/bind.hpp>
34 #include <boost/bind/apply.hpp>
35 #include <boost/any.hpp>
36 #include <boost/concept_check.hpp>
37 
38 //#include <l_cpp/l_cpp_incl.h>
39 #include <l/l_sys_io.h>
40 
42 #include "sample_cpp/sample_base.h"
43 #include <l_cpp/l_serialization.h>
44 
45 struct Null_value{ };
55 template <class Model>
57 {
58 public:
60 
61  typedef Model Model_type;
62  typedef Model Value_type;
63 
65  m_current_model(),
66  m_current_lt(-std::numeric_limits<double>::max())
67  {}
68 
69  Current_model_recorder(const Model& initial_model) :
70  m_current_model(initial_model),
71  m_current_lt(-std::numeric_limits<double>::max())
72  {}
73 
74  void operator()(const Model& m, const Step_log<Model>& step_log)
75  {
76  assert(step_log.size() >= 1);
77 
78  // final entry of the log contains most recent log-target value
79  //Step_result& result = *(step_log.end()--);
80  const Step_result<Model>& result = step_log.back();
81 
82  m_current_model = m;
83  m_current_lt = result.lt;
84  }
85 
86  const Value_type& get() const
87  {
88  if(m_current_lt == -std::numeric_limits<double>::max())
89  {
90  KJB_THROW_2(kjb::Runtime_error, "current model has not been recorded yet.");
91  }
92 
93  return *m_current_model;
94  }
95 
96 private:
97  boost::optional<Model> m_current_model;
98  double m_current_lt;
99 };
100 
101 template <class Model>
103 {
104 public:
106 
107  typedef Model Model_type;
109 
111  m_current_log()
112  {}
113 
114  void operator()(const Model& /*m*/, const Step_log<Model>& step_log)
115  {
116  assert(step_log.size() >= 1);
117 
118  m_current_log = step_log;
119  }
120 
121  const Value_type& get() const
122  {
123  if(m_current_log.size() == 0)
124  {
125  KJB_THROW_2(kjb::Runtime_error, "current log has not been recorded yet.");
126  }
127 
128  return m_current_log;
129  }
130 
131 private:
132  Step_log<Model> m_current_log;
133 };
134 
144 template <class Model>
146 {
147 public:
149 
150  typedef Model Model_type;
151  typedef Model Value_type;
152 
154  m_best_model(),
155  m_best_lt(-std::numeric_limits<double>::max())
156  {}
157 
158  Best_model_recorder(const Model& initial_model, double initial_lt) :
159  m_best_model(initial_model),
160  m_best_lt(initial_lt)
161  {}
162 
163  void operator()(const Model& m, Step_log<Model> step_log)
164  {
165 
166  assert(step_log.size() >= 1);
167 
168  // final entry of the log contains most recent log-target value
169  Step_result<Model>& result = step_log.back();
170 
171  if(!m_best_model || result.lt > m_best_lt)
172  {
173  m_best_model = m;
174  m_best_lt = result.lt;
175  }
176 
177  }
178 
179  const Value_type& get() const
180  {
181  if(m_best_lt == -std::numeric_limits<double>::max())
182  {
183  KJB_THROW_2(kjb::Runtime_error, "Best model has not been recorded yet.");
184  }
185 
186  return *m_best_model;
187  }
188 
189  double get_log_target() const
190  {
191  return m_best_lt;
192  }
193 
194 private:
195  boost::optional<Model> m_best_model;
196  double m_best_lt;
197 };
198 
206 template <class Model>
208 {
209 public:
211 
212  typedef Model Model_type;
213  typedef double Value_type;
214 
216  m_best_lt(-std::numeric_limits<double>::max())
217  {}
218 
219  void operator()(const Model& /*m*/, Step_log<Model> step_log)
220  {
221 
222  assert(step_log.size() >= 1);
223 
224  // final entry of the log contains most recent log-target value
225  //Step_result<Model>& result = *(step_log.end()--);
226  Step_result<Model>& result = step_log.back();
227 
228  if(result.lt > m_best_lt)
229  {
230  m_best_lt = result.lt;
231  }
232  }
233 
234  const Value_type& get() const
235  {
236  if(m_best_lt == -std::numeric_limits<double>::max())
237  {
238  KJB_THROW_2(kjb::Runtime_error, "Best model has not been recorded yet.");
239  }
240 
241  return m_best_lt;
242  }
243 
244 private:
245  double m_best_lt;
246 };
247 
255 template <class Model>
256 class All_model_recorder : public std::vector<Model>
257 {
258 public:
260 
261  typedef Model Model_type;
262  typedef std::vector<Model> Value_type;
263 
264 
266  std::vector<Model>()
267  {}
268 
269  void operator()(const Model& m, const Step_log<Model>& /*step_log*/)
270  {
271  this->push_back(m);
272  }
273 
274  const Value_type& get() const { return *this; }
275 };
276 
277 
285 template <class Model>
286 class All_log_recorder : public Step_log<Model>
287 {
288 public:
290 
291  typedef Model Model_type;
293 
295  Step_log<Model>()
296  {}
297 
298  void operator()(const Model& /*m*/, const Step_log<Model>& step_log)
299  {
300  (*this) += step_log;
301  }
302 
303  const Value_type& get() const { return *this; }
304 };
305 
306 
315 template <class Model>
316 class Recent_model_recorder : public std::deque<Model>
317 {
318 public:
320 
321  typedef Model Model_type;
322  typedef std::deque<Model> Value_type;
323  typedef std::deque<Model> Parent;
324 
329  m_n(n)
330  {}
331 
333  {}
334 
335  virtual void operator()(const Model& m, const Step_log<Model>& /*step_log*/)
336  {
337  this->push_back(m);
338 
339  if(m_n > 0 && Parent::size() > m_n)
340  {
341  Parent::pop_front();
342  }
343  }
344 
345  const Value_type& get() const { return *this; }
346 private:
347  size_t m_n;
348 };
349 
350 
358 template <class Model>
359 class Recent_log_recorder : public Step_log<Model>
360 {
361 public:
363 
364  typedef Model Model_type;
366 
367  Recent_log_recorder(size_t n = 0) :
368  Step_log<Model>(),
369  m_n(n)
370  {}
371 
372  void operator()(const Model& /*m*/, const Step_log<Model>& step_log)
373  {
374  (*this) += step_log;
375 
376  if(m_n > 0 && this->size() > m_n)
377  {
378  this->pop_front();
379  }
380 
381  }
382 
383  const Value_type& get() const
384  {
385  return *this;
386  }
387 private:
388  size_t m_n;
389 };
390 
391 
392 
400 template <class Model, class Value>
402 {
403 public:
405 
406  typedef Model Model_type;
407  typedef Value Value_type;
408 
409  typedef boost::function1<Value_type, const Model&> Func;
410 
411  Expectation_recorder(const Func& f, const Value_type& initial_val = Value_type()) :
412  m_func(f),
413  m_total(initial_val),
414  m_n(0)
415  {}
416 
418  {}
419 
420  virtual void operator()(const Model& m, const Step_log<Model>& /* step_log */)
421  {
422  m_total += m_func(m);
423  m_n++;
424  }
425 
426  const Value_type get() const
427  {
428  return m_total / m_n;
429  }
430 private:
431  Func m_func;
432  Value_type m_total;
433  size_t m_n;
434 };
435 
436 
500 template <class Model>
502 {
503 struct null_deleter {
504  void operator()(void const * ) const {}
505 };
506 
507 protected:
509 
511 // typedef std::vector<typename Model_recorder<Model>::Type > Base;
512 
513  std::vector<typename Model_recorder<Model>::Type > record_callbacks_;
514 
515  // important that this is a list, because record_callbacks_
516  // will store references to these, and we don't want them reallocated.
517  std::vector<boost::any> recorders_;
518 
519  std::vector<bool> is_reference_;
520 
521 
522 public:
523  typedef Model Model_type;
524  typedef Null_value Value_type; // no get function
525 
527  {}
528 
529  virtual void operator()(const Model& m, const Step_log<Model>& step_log)
530  {
531  using namespace boost;
532  // call all recorder callbacks, sending these parameters
533 // for_each(record_callbacks_.begin(), record_callbacks_.end(), bind(apply<void>(), _1, m, step_log));
534  for(size_t i = 0; i < record_callbacks_.size(); i++)
535  {
536  record_callbacks_[i](m, step_log);
537  }
538  }
539 
540  size_t size() const { return recorders_.size(); }
541 
545  template <class RecorderIn>
546  void push_back(const RecorderIn& r)
547  {
548  add(r);
549  }
550 
554  template <class RecorderIn>
555  void add(const RecorderIn& r_in)
556  {
557  BOOST_CONCEPT_ASSERT((boost::CopyConstructible<RecorderIn>));
559 
560  // we MUST store recorders as pointers. We tried
561  // storing as values, but copying a Multi_model_recorder
562  // breaks the references in recorder_callbacks_, and
563  // it's impossible to fix, because by the time we copy,
564  // we don't know the types stored in the recorders_ array.
565  //
566  // Shared pointers solves this problem and makes copying straightforward.
567  boost::shared_ptr<RecorderIn> r(new RecorderIn(r_in));
568  add(r);
569 
570  }
571 
575  template <class RecorderIn>
576  void add(const typename boost::reference_wrapper<RecorderIn>& r)
577  {
579 
580  // value stored in recorders_ is a boost::ref (special case)
581  is_reference_.push_back(true);
582  recorders_.push_back(r);
583  record_callbacks_.push_back(r);
584  }
585 
589  template <class RecorderIn>
590  void add(const typename boost::shared_ptr<RecorderIn>& r)
591  {
593 
594  // value stored in recorders_ is a boost::shared_ptr (Defualt)
595  is_reference_.push_back(false);
596  // copy recorder into generic array
597  recorders_.push_back(r);
598  // store operator() as callback so we don't need to know the type later on.
599  // convert pointer to a reference, then store
600  record_callbacks_.push_back(boost::ref(*r));
601  }
602 
606  template <class RecorderIn>
607  void add(RecorderIn* r)
608  {
610  boost::shared_ptr<RecorderIn> r_sptr(r, null_deleter());
611  add(r_sptr);
612  }
613 
614 
616  const Value_type& get() const {static Value_type a; return a;}
617 
618  template <class RecorderOut>
619  const RecorderOut& get_recorder(size_t i) const
620  {
621 
622  typedef typename boost::shared_ptr<RecorderOut> RecorderPtr;
623  typedef typename boost::reference_wrapper<RecorderOut> RecorderRef;
624 
625  if(is_reference_[i])
626  {
627  const RecorderRef result = boost::any_cast<RecorderRef>(recorders_[i]);
628  return result;
629  }
630  else
631  {
632  const RecorderPtr result = boost::any_cast<RecorderPtr>(recorders_[i]);
633  return *result;
634  }
635 
636  }
637 
638  template <class RecorderOut>
639  const typename RecorderOut::Value_type& get(size_t i) const
640  {
641  typedef typename boost::shared_ptr<RecorderOut> RecorderPtr;
642  typedef typename boost::reference_wrapper<RecorderOut> RecorderRef;
643 
644  if(is_reference_[i])
645  {
646  const RecorderRef result = boost::any_cast<RecorderRef>(recorders_[i]);
647  return static_cast<const RecorderOut&>(result).get();
648 
649  }
650  else
651  {
652  const RecorderPtr result = boost::any_cast<RecorderPtr>(recorders_[i]);
653  return result->get();
654  }
655  }
656 };
657 
665 template <class Recorder>
667 {
668 public:
670 
671  typedef typename Recorder::Model_type Model_type;
672  typedef typename Recorder::Value_type Value_type;
673 
682  Modulo_recorder(const Recorder& recorder, int interval, int start = 0) :
683  r(recorder),
684  N(interval),
685  n(start)
686  {
688  }
689 
690  virtual void operator()(const Model_type& m, const Step_log<Model_type>& step_log)
691  {
692  if(n++ % N == 0)
693  {
694  // record the entry
695  r(m, step_log);
696  }
697 
698  // prevent overflow of n.
699  while(n > N)
700  {
701  n -= N;
702  }
703  }
704 
705  const Value_type& get() const
706  {
707  return r.get();
708  }
709 
710 private:
711  Recorder r;
712  int N, n;
713 
714 };
715 
716 
726 template <class Recorder>
728 {
729 public:
731 
732  typedef typename Recorder::Model_type Model_type;
733  typedef typename Recorder::Value_type Value_type;
734  typedef boost::function2<std::ostream&, std::ostream&, const Value_type&> Write_function;
735 
736 // /**
737 // * @param recorder The recorder to wrap. This will be stored be value,
738 // * so the caller is responsible for making sure the
739 // * recorder remains in scope
740 // * @param os ostream to output.
741 // */
742 // Ostream_recorder(const Recorder& recorder, std::ostream& os, const std::string& separator = "\n") :
743 // r(recorder),
744 // m_os(os),
745 // m_sep(separator),
746 // write_func_(static_cast<std::ostream&(*)(std::ostream&, const Value_type&)>(operator<<))
747 // {
748 // BOOST_CONCEPT_ASSERT((ModelRecorder<Recorder>));
749 //
750 // if(!m_os)
751 // {
752 // KJB_THROW_2(kjb::IO_error, "Error with output stream");
753 // }
754 // }
755 
764  const Recorder& recorder,
765  std::ostream& os,
766  const std::string& separator = "\n",
767  const Write_function& write_func = Ostream_recorder::default_write) :
768  r(recorder),
769  m_os(os),
770  m_sep(separator),
771  write_func_(write_func)
772  {
774 
775  if(!m_os)
776  {
777  KJB_THROW_2(kjb::IO_error, "Error with output stream");
778  }
779  }
780 
781  virtual void operator()(const Model_type& m, const Step_log<Model_type>& step_log)
782  {
783  r(m, step_log);
784  write_func_(m_os, r.get());
785  m_os << m_sep;
786 
787  m_os << std::flush;
788 
789  if(!m_os)
790  {
791  KJB_THROW_2(kjb::IO_error, "Error with output stream");
792  }
793  }
794 
795  const Value_type& get() const
796  {
797  return r.get();
798  }
799 
800  static std::ostream& default_write(std::ostream& ost, const Value_type& v)
801  {
802  return ost << v;
803  }
804 
805 private:
806  Recorder r;
807  std::ostream& m_os;
808  std::string m_sep;
809  Write_function write_func_;
810 };
811 
812 template <class Recorder>
814 (
815  const Recorder& r,
816  std::ostream& ost,
817  const std::string& separator = "\n"
818 )
819 {
820  return Ostream_recorder<Recorder>(r, ost, separator);
821 }
822 
823 template <class Recorder, class Write_function>
825 (
826  const Recorder& r,
827  std::ostream& ost,
828  const Write_function& write_func,
829  const std::string& separator = "\n"
830 )
831 {
832  typedef typename Ostream_recorder<Recorder>::Write_function Function;
833  Function f = write_func;
834  return Ostream_recorder<Recorder>(r, ost, separator, f);
835 }
836 
837 
846 template <class Recorder_type>
848 {
849 public:
850 typedef typename Recorder_type::Model_type Model_type;
851 typedef typename Recorder_type::Value_type Value_type;
852 
858  Serialize_recorder(const Recorder_type& r, const std::string& fname_fmt, size_t iterations) :
859  recorder_(r),
860  fname_fmt_(fname_fmt),
861  period_(iterations),
862  it_counter_(0),
863  file_counter_(0),
864  tmp(fname_fmt)
865  {
868 
869  try{
870  std::string fname = str(boost::format(fname_fmt_) % file_counter_);
871  }
872  catch(...)
873  {
874  KJB_THROW_2(kjb::Illegal_argument, "Invalid filename format. Must be a printf-formatted string with one integer field.");
875  }
876 
877  }
878 
883  void operator()(const Model_type& model, const Step_log<Model_type>& log)
884  {
885  // record as usual
886  recorder_(model, log);
887 
888  if(period_ == 0) return;
889 
890  it_counter_++;
891 
892  // if enough iterations have passed, write to file
893  if(it_counter_ == period_)
894  {
895  it_counter_ = 0;
896  write();
897  }
898 
899  }
900 
901  const Value_type& get() const
902  {
903  recorder_.get();
904  }
905 
906 private:
907  void write()
908  {
909  const Value_type& value = recorder_.get();
910 
911 // KJB_DEPENDENCY
912  // for some reason, reusing some persistent boost:format object here fails. so we reconstruct it each time.
913  std::string fname = str(boost::format(fname_fmt_) % file_counter_);
914  kjb::save(value, fname);
915 
916  file_counter_++;
917  }
918 
919  Recorder_type recorder_;
920  std::string fname_fmt_;
921  size_t period_;
922 
923  // iteration counter
924  size_t it_counter_;
925  size_t file_counter_;
926 
927  std::string tmp;
928 };
929 
930 template <class Recorder>
931 Serialize_recorder<Recorder> make_serialization_recorder(const Recorder& r, std::string fname_fmt, size_t iterations = 1)
932 {
933  return Serialize_recorder<Recorder>(r, fname_fmt, iterations);
934 }
935 
936 
937 
938 
944 template <class Model>
946 {
947 public:
949  typedef Model Model_type;
950  void operator()(const Model_type&, const Step_log<Model>&)
951  {}
952 
953  const Value_type& get() const {static Value_type out; return out;}
954 };
955 
959 template <class Model>
960 class Callback_recorder : public Null_recorder<Model>
961 {
962  typedef Null_recorder<Model> Base;
963 public:
964  typedef typename Base::Value_type Value_type;
965  typedef typename Base::Model_type Model_type;
966  template <class Function>
967  Callback_recorder(Function f) :
968  f_(f)
969  { }
970 
971  void operator()(const Model_type& model, const Step_log<Model>& step_log)
972  {
973  return f_(model, step_log);
974  }
975 private:
976  boost::function2<void, const Model_type&, const Step_log<Model>&> f_;
977 };
978 
988 template <class Recorder, class Updater>
990 {
991 public:
994 
995  typedef typename Recorder::Value_type Value_type;
996  typedef typename Recorder::Model_type Model_type;
997  typedef typename Updater::Update_type Update_type;
998 
999  // Recorder's output must match Updater's input.
1000  //BOOST_CONCEPT_ASSERT((boost::Convertible<Value_type, Update_type>));
1001 
1002 public:
1003  Viewing_recorder(const Recorder& r, Updater& u) :
1004  m_recorder(r),
1005  m_updater(u)
1006  {}
1007 
1008  void operator()(const Model_type& model, const Step_log<Model_type>& step_log)
1009  {
1010  // pass through to recorder
1011  m_recorder(model, step_log);
1012 
1013  // update viewer
1014  m_updater.update(m_recorder.get());
1015  }
1016 
1017  const Value_type& get() const
1018  {
1019  return m_recorder.get();
1020  }
1021 
1022 private:
1023  Recorder m_recorder;
1024  Updater& m_updater;
1025 };
1026 
1027 #endif
1028 
Current_log_recorder()
Definition: sample_recorder.h:110
void add(RecorderIn *r)
Definition: sample_recorder.h:607
double get_log_target() const
Definition: sample_recorder.h:189
Definition: sample_concept.h:123
Model Model_type
Definition: sample_recorder.h:949
virtual void operator()(const Model &m, const Step_log< Model > &step_log)
Definition: sample_recorder.h:529
Definition: sample_recorder.h:666
Int_matrix::Value_type max(const Int_matrix &mat)
Return the maximum value in this matrix.
Definition: l_int_matrix.h:1397
Serialize_recorder(const Recorder_type &r, const std::string &fname_fmt, size_t iterations)
Definition: sample_recorder.h:858
Definition: sample_recorder.h:501
Value Value_type
Definition: sample_recorder.h:407
BOOST_CONCEPT_ASSERT((BaseModel< Model >))
void operator()(const Model_type &model, const Step_log< Model_type > &log)
Definition: sample_recorder.h:883
void operator()(const Model_type &model, const Step_log< Model > &step_log)
Definition: sample_recorder.h:971
Definition: sample_recorder.h:359
Definition: sample_recorder.h:207
void add(const typename boost::shared_ptr< RecorderIn > &r)
Definition: sample_recorder.h:590
void operator()(const Model &, Step_log< Model > step_log)
Definition: sample_recorder.h:219
void operator()(const Model &m, const Step_log< Model > &)
Definition: sample_recorder.h:269
virtual void operator()(const Model_type &m, const Step_log< Model_type > &step_log)
Definition: sample_recorder.h:781
Definition: sample_recorder.h:256
Definition: sample_recorder.h:56
Recorder::Model_type Model_type
Definition: sample_recorder.h:669
const RecorderOut & get_recorder(size_t i) const
Definition: sample_recorder.h:619
void operator()(const Model &m, Step_log< Model > step_log)
Definition: sample_recorder.h:163
size_t size() const
Definition: sample_recorder.h:540
r
Definition: APPgetLargeConnectedEdges.m:127
boost::function2< std::ostream &, std::ostream &, const Value_type & > Write_function
Definition: sample_recorder.h:734
Updater::Update_type Update_type
Definition: sample_recorder.h:997
Recorder::Value_type Value_type
Definition: sample_recorder.h:995
BOOST_CONCEPT_ASSERT((BaseModel< Model >))
Current_model_recorder()
Definition: sample_recorder.h:64
Structure for returning results of a single sampling move.
Definition: sample_base.h:55
Step_log< Model > Value_type
Definition: sample_recorder.h:292
virtual ~Recent_model_recorder()
Definition: sample_recorder.h:332
Definition: sample_base.h:160
BOOST_CONCEPT_ASSERT((BaseModel< Model >))
Base::Value_type Value_type
Definition: sample_recorder.h:964
Serialize_recorder< Recorder > make_serialization_recorder(const Recorder &r, std::string fname_fmt, size_t iterations=1)
Definition: sample_recorder.h:931
Recent_log_recorder(size_t n=0)
Definition: sample_recorder.h:367
void operator()(const Model &, const Step_log< Model > &step_log)
Definition: sample_recorder.h:298
std::deque< Model > Parent
Definition: sample_recorder.h:323
BOOST_CONCEPT_ASSERT((BaseModel< Model >))
Definition: sample_recorder.h:45
BOOST_CONCEPT_ASSERT((BaseModel< Model >))
Recorder::Model_type Model_type
Definition: sample_recorder.h:996
Model Model_type
Definition: sample_recorder.h:150
Base::Model_type Model_type
Definition: sample_recorder.h:965
Expectation_recorder(const Func &f, const Value_type &initial_val=Value_type())
Definition: sample_recorder.h:411
double Value_type
Definition: sample_recorder.h:213
All_log_recorder()
Definition: sample_recorder.h:294
Step_log< Model > Value_type
Definition: sample_recorder.h:365
void operator()(const Model_type &model, const Step_log< Model_type > &step_log)
Definition: sample_recorder.h:1008
Definition: sample_recorder.h:727
Model Model_type
Definition: sample_recorder.h:406
All_model_recorder()
Definition: sample_recorder.h:265
void push_back(const RecorderIn &r)
Definition: sample_recorder.h:546
boost::function1< Value_type, const Model & > Func
Definition: sample_recorder.h:409
Definition: sample_recorder.h:286
void operator()(const Model &m, const Step_log< Model > &step_log)
Definition: sample_recorder.h:74
Model Model_type
Definition: sample_recorder.h:61
Definition: sample_recorder.h:960
Definition: sample_recorder.h:989
Recent_model_recorder(int n=0)
Definition: sample_recorder.h:328
Best_model_recorder(const Model &initial_model, double initial_lt)
Definition: sample_recorder.h:158
Definition: sample_recorder.h:102
virtual void operator()(const Model_type &m, const Step_log< Model_type > &step_log)
Definition: sample_recorder.h:690
Step_log< Model > Value_type
Definition: sample_recorder.h:108
Null_value Value_type
Definition: sample_recorder.h:524
Recorder_type::Value_type Value_type
Definition: sample_recorder.h:851
std::deque< Model > Value_type
Definition: sample_recorder.h:322
Definition: sample_concept.h:144
Model Model_type
Definition: sample_recorder.h:523
Model Value_type
Definition: sample_recorder.h:151
Model Model_type
Definition: sample_recorder.h:364
#define KJB_THROW_2(ex, msg)
Definition: l_exception.h:48
void write(const Data &data, const std::string &fname)
Write to file.
Definition: bbb_data.cpp:123
Definition: sample_base.h:247
void operator()(const Model &, const Step_log< Model > &step_log)
Definition: sample_recorder.h:372
BOOST_CONCEPT_ASSERT((BaseModel< Model >))
BOOST_CONCEPT_ASSERT((BaseModel< Model >))
void add(const RecorderIn &r_in)
Definition: sample_recorder.h:555
Null_value Value_type
Definition: sample_recorder.h:948
Callback_recorder(Function f)
Definition: sample_recorder.h:967
Multi_model_recorder()
Definition: sample_recorder.h:526
void save(const Edge_set &edges, const std::string &fname)
Definition: edge.h:608
void operator()(const Model &, const Step_log< Model > &step_log)
Definition: sample_recorder.h:114
Model Model_type
Definition: sample_recorder.h:212
static std::ostream & default_write(std::ostream &ost, const Value_type &v)
Definition: sample_recorder.h:800
virtual void operator()(const Model &m, const Step_log< Model > &)
Definition: sample_recorder.h:420
std::vector< boost::any > recorders_
Definition: sample_recorder.h:517
BOOST_CONCEPT_ASSERT((BaseModel< Model >))
Model_recorder< Model > Recorder
Definition: sample_recorder.h:510
Ostream_recorder(const Recorder &recorder, std::ostream &os, const std::string &separator="\n", const Write_function &write_func=Ostream_recorder::default_write)
Definition: sample_recorder.h:763
BOOST_CONCEPT_ASSERT((BaseModel< Model >))
Object thrown when an argument to a function is not acceptable.
Definition: l_exception.h:377
Recorder::Value_type Value_type
Definition: sample_recorder.h:733
Model Model_type
Definition: sample_recorder.h:107
Definition: sample_recorder.h:945
Model Model_type
Definition: sample_recorder.h:321
Modulo_recorder(const Recorder &recorder, int interval, int start=0)
Definition: sample_recorder.h:682
virtual void operator()(const Model &m, const Step_log< Model > &)
Definition: sample_recorder.h:335
Ostream_recorder< Recorder > make_ostream_recorder(const Recorder &r, std::ostream &ost, const std::string &separator="\n")
Definition: sample_recorder.h:814
get the indices of edges in each direction for i
Definition: APPgetLargeConnectedEdges.m:48
Model Model_type
Definition: sample_recorder.h:261
Object thrown when input or output fails.
Definition: l_exception.h:496
Definition: l_serialization.h:82
for m
Definition: APPgetLargeConnectedEdges.m:64
Recorder::Value_type Value_type
Definition: sample_recorder.h:672
std::vector< Model > Value_type
Definition: sample_recorder.h:262
void add(const typename boost::reference_wrapper< RecorderIn > &r)
Definition: sample_recorder.h:576
Definition: sample_recorder.h:401
Viewing_recorder(const Recorder &r, Updater &u)
Definition: sample_recorder.h:1003
Model Model_type
Definition: sample_recorder.h:291
Definition: sample_concept.h:41
Current_model_recorder(const Model &initial_model)
Definition: sample_recorder.h:69
Definition: sample_recorder.h:145
BOOST_CONCEPT_ASSERT((BaseModel< Model >))
Best_model_recorder()
Definition: sample_recorder.h:153
virtual ~Expectation_recorder()
Definition: sample_recorder.h:417
Model Value_type
Definition: sample_recorder.h:62
Best_target_recorder()
Definition: sample_recorder.h:215
std::vector< bool > is_reference_
Definition: sample_recorder.h:519
Recorder_type::Model_type Model_type
Definition: sample_recorder.h:850
std::vector< typename Model_recorder< Model >::Type > record_callbacks_
Definition: sample_recorder.h:513
Object thrown when computation fails somehow during execution.
Definition: l_exception.h:321
void operator()(const Model_type &, const Step_log< Model > &)
Definition: sample_recorder.h:950
Recorder::Model_type Model_type
Definition: sample_recorder.h:730
Definition: sample_recorder.h:316
Definition: sample_recorder.h:847