Tomographer  v4.0
Tomographer C++ Framework Documentation
mhrwstatscollectors.h
Go to the documentation of this file.
1 /* This file is part of the Tomographer project, which is distributed under the
2  * terms of the MIT license.
3  *
4  * The MIT License (MIT)
5  *
6  * Copyright (c) 2016 ETH Zurich, Institute for Theoretical Physics, Philippe Faist
7  * Copyright (c) 2017 Caltech, Institute for Quantum Information and Matter, Philippe Faist
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining a copy
10  * of this software and associated documentation files (the "Software"), to deal
11  * in the Software without restriction, including without limitation the rights
12  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13  * copies of the Software, and to permit persons to whom the Software is
14  * furnished to do so, subject to the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be included in
17  * all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25  * SOFTWARE.
26  */
27 
28 #ifndef TOMOGRAPHER_MHRWSTATSCOLLECTORS_H
29 #define TOMOGRAPHER_MHRWSTATSCOLLECTORS_H
30 
31 #include <cstddef>
32 
33 #include <limits>
34 #include <tuple>
35 #include <utility>
36 #include <type_traits>
37 #include <typeinfo>
38 
39 
42 #include <tomographer/histogram.h>
44 
55 namespace Tomographer {
56 
57 
87 template<typename... MHRWStatsCollectors>
88 TOMOGRAPHER_EXPORT class MultipleMHRWStatsCollectors
89 {
90 public:
91  typedef std::tuple<MHRWStatsCollectors&...> MHRWStatsCollectorsRefTupleType;
92  typedef std::tuple<MHRWStatsCollectors...> MHRWStatsCollectorsTupleType;
93 
95  static constexpr int NumStatColl = sizeof...(MHRWStatsCollectors);
96 
97 private:
98  MHRWStatsCollectorsRefTupleType statscollectors;
99 
100 public:
101 
102  MultipleMHRWStatsCollectors(MHRWStatsCollectors&... statscollectors_)
103  : statscollectors(statscollectors_...)
104  {
105  }
106 
107  // method to get a particular stats collector
108  template<int I>
109  inline const typename std::tuple_element<I, MHRWStatsCollectorsTupleType>::type & getStatsCollector() const
110  {
111  return std::get<I>(statscollectors);
112  }
113 
114  // init() callback
115 
116  template<int I = 0>
117  inline typename std::enable_if<I < NumStatColl, void>::type init()
118  {
119  std::get<I>(statscollectors).init();
120  init<I+1>();
121  }
122  template<int I = 0>
123  inline typename std::enable_if<I == NumStatColl, void>::type init()
124  {
125  }
126 
127  // thermalizingDone() callback
128 
129  template<int I = 0>
130  inline typename std::enable_if<I < NumStatColl, void>::type thermalizingDone()
131  {
132  std::get<I>(statscollectors).thermalizingDone();
133  thermalizingDone<I+1>();
134  }
135  template<int I = 0>
136  inline typename std::enable_if<I == NumStatColl, void>::type thermalizingDone()
137  {
138  }
139 
140  // done() callback
141 
142  template<int I = 0>
143  inline typename std::enable_if<I < NumStatColl, void>::type done()
144  {
145  std::get<I>(statscollectors).done();
146  done<I+1>();
147  }
148  template<int I = 0>
149  inline typename std::enable_if<I == NumStatColl, void>::type done()
150  {
151  }
152 
153 
154  // rawMove() callback
155 
156  template<typename CountIntType, typename PointType, typename FnValueType, typename MHRandomWalk, int I = 0>
157  inline typename std::enable_if<I < NumStatColl, void>::type rawMove(
158  CountIntType k, bool is_thermalizing, bool is_live_iter, bool accepted,
159  double a, const PointType & newpt, FnValueType newptval,
160  const PointType & curpt, FnValueType curptval,
161  MHRandomWalk & rw
162  )
163  {
164  std::get<I>(statscollectors).rawMove(
165  k, is_thermalizing, is_live_iter, accepted, a,
166  newpt, newptval, curpt, curptval, rw
167  );
168  rawMove<CountIntType, PointType, FnValueType, MHRandomWalk, I+1>(
169  k, is_thermalizing, is_live_iter, accepted, a,
170  newpt, newptval, curpt, curptval, rw
171  );
172  }
173  template<typename CountIntType, typename PointType, typename FnValueType, typename MHRandomWalk, int I = 0>
174  inline typename std::enable_if<I == NumStatColl, void>::type rawMove(
175  CountIntType, bool, bool, bool, double, const PointType &, FnValueType,
176  const PointType &, FnValueType, MHRandomWalk &
177  )
178  {
179  }
180 
181 
182  // processSample() callback
183 
184  template<typename CountIntType, typename PointType, typename FnValueType, typename MHRandomWalk, int I = 0>
185  inline typename std::enable_if<I < NumStatColl, void>::type processSample(
186  CountIntType k, CountIntType n, const PointType & curpt, FnValueType curptval, MHRandomWalk & rw
187  )
188  {
189  std::get<I>(statscollectors).processSample(k, n, curpt, curptval, rw);
190  processSample<CountIntType, PointType, FnValueType, MHRandomWalk, I+1>(k, n, curpt, curptval, rw);
191  }
192 
193  template<typename CountIntType, typename PointType, typename FnValueType, typename MHRandomWalk, int I = 0>
194  inline typename std::enable_if<I == NumStatColl, void>::type processSample(
195  CountIntType, CountIntType, const PointType &, FnValueType, MHRandomWalk &
196  )
197  {
198  }
199 
200 };
201 
202 
203 
204 
205 
213 
214 
215 
216 
217 // -----------------
218 
219 
220 
235 template<typename ValueCalculator_,
236  typename LoggerType = Logger::VacuumLogger,
238  >
239 TOMOGRAPHER_EXPORT class ValueHistogramMHRWStatsCollector
240  : public virtual Tools::NeedOwnOperatorNew<ValueCalculator_, HistogramType_>::ProviderType
241 {
242 public:
246  typedef ValueCalculator_ ValueCalculator;
247 
249  typedef typename ValueCalculator::ValueType ValueType;
250 
252  typedef HistogramType_ HistogramType;
253 
255  typedef HistogramType_ ResultType;
256 
258  typedef typename HistogramType::Params HistogramParams;
259 
260 private:
261 
263  HistogramType _histogram;
264 
269  ValueCalculator _vcalc;
270 
271  LoggerType & _logger;
272 
273 public:
275  ValueHistogramMHRWStatsCollector(HistogramParams histogram_params,
276  const ValueCalculator & vcalc,
277  LoggerType & logger)
278  : _histogram(histogram_params),
279  _vcalc(vcalc),
280  _logger(logger)
281  {
282  }
283 
285  inline const HistogramType & histogram() const
286  {
287  return _histogram;
288  }
289 
299  inline const ResultType & getResult() const
300  {
301  return _histogram;
302  }
303 
304  // stats collector part
305 
307  inline void init()
308  {
309  // reset our array
310  _histogram.reset();
311  }
313  inline void thermalizingDone()
314  {
315  }
323  template<bool PrintHistogram = true>
324  inline void done()
325  {
326  if (PrintHistogram) {
327  if (_logger.enabledFor(Logger::LONGDEBUG)) {
328  // _logger.longdebug("ValueHistogramMHRWStatsCollector", "done()");
329  _logger.longdebug("ValueHistogramMHRWStatsCollector",
330  "Done walking & collecting stats. Here's the histogram:\n"
331  + _histogram.prettyPrint());
332  }
333  }
334  }
335 
337  template<typename CountIntType, typename PointType, typename LLHValueType, typename MHRandomWalk>
338  void rawMove(CountIntType k, bool /*is_thermalizing*/, bool /*is_live_iter*/, bool /*accepted*/,
339  double /*a*/, const PointType & /*newpt*/, LLHValueType /*newptval*/,
340  const PointType & /*curpt*/, LLHValueType /*curptval*/, MHRandomWalk & /*mh*/)
341  {
342  _logger.longdebug("ValueHistogramMHRWStatsCollector", [&](std::ostream & stream) {
343  stream << "rawMove(): k=" << k;
344  });
345  }
346 
348  template<typename CountIntType, typename PointType, typename LLHValueType, typename MHRandomWalk>
349  std::size_t processSample(CountIntType k, CountIntType n, const PointType & curpt,
350  LLHValueType /*curptval*/, MHRandomWalk & /*mh*/)
351  {
352  ValueType val = _vcalc.getValue(curpt);
353 
354  _logger.longdebug("ValueHistogramMHRWStatsCollector", [&](std::ostream & stream) {
355  stream << "in processSample(): "
356  << "k=" << k << ", n=" << n << ", val=" << val
357  << " [with ValueType=" << typeid(ValueType).name() << "]" ;
358  });
359 
360  return _histogram.record(val);
361 
362  //_logger.longdebug("ValueHistogramMHRWStatsCollector", "processSample() finished");
363  }
364 
365 
366 };
367 
368 
369 
370 
376 template<typename HistogramType_, typename BinningAnalysisParamsType_>
378  : public virtual Tools::NeedOwnOperatorNew<
379  HistogramType_,
380  typename BinningAnalysisParamsType_::BinSumSqArray
381  >::ProviderType
382 {
383  typedef HistogramType_ HistogramType;
384  typedef typename HistogramType::Params HistogramParams;
385  typedef BinningAnalysisParamsType_ BinningAnalysisParamsType;
386 
389  : hist(), error_levels(), converged_status()
390  {
391  }
392 
394  template<typename EigenDerived1, typename EigenDerived2>
396  const Eigen::DenseBase<EigenDerived1> & error_levels_,
397  const Eigen::DenseBase<EigenDerived2> & converged_status_)
398  : hist(hist_), error_levels(error_levels_), converged_status(converged_status_)
399  {
400  }
401 
403  template<typename BinningAnalysisType>
404  ValueHistogramWithBinningMHRWStatsCollectorResult(HistogramParams p, const BinningAnalysisType & b)
405  : hist(p),
406  error_levels(b.numTrackValues(), b.numLevels()+1),
407  converged_status(Eigen::ArrayXi::Constant(b.numTrackValues(), BinningAnalysisType::UNKNOWN_CONVERGENCE))
408  {
409  tomographer_assert(converged_status.rows() == b.numTrackValues() && converged_status.cols() == 1);
410  }
411 
421  HistogramType hist;
422 
425  typename BinningAnalysisParamsType::BinSumSqArray error_levels;
426 
430  Eigen::ArrayXi converged_status;
431 
433  inline void dumpConvergenceAnalysis(std::ostream & str) const
434  {
435  for (int k = 0; k < converged_status.size(); ++k) {
436  str << "\tval[" << std::setw(3) << k << "] = "
437  << std::setw(12) << hist.bins(k)
438  << " +- " << std::setw(12) << hist.delta(k);
439  if (converged_status(k) == BinningAnalysisParamsType::CONVERGED) {
440  str << " [CONVERGED]";
441  } else if (converged_status(k) == BinningAnalysisParamsType::NOT_CONVERGED) {
442  str << " [NOT CONVERGED]";
443  } else if (converged_status(k) == BinningAnalysisParamsType::UNKNOWN_CONVERGENCE) {
444  str << " [UNKNOWN]";
445  } else {
446  str << " [UNKNOWN CONVERGENCE STATUS: " << converged_status(k) << "]";
447  }
448  str << "\n";
449  }
450  }
451 
454  {
456  dumpConvergenceAnalysis(ss);
457  return ss.str();
458  }
459 
460 };
461 
462 
463 
464 
472 template<typename ValueCalculator_,
473  typename CountIntType_ = int,
474  typename CountRealAvgType_ = double,
475  int NumTrackValues_ = Eigen::Dynamic,
476  int NumLevels_ = Eigen::Dynamic
477  >
479 {
482  typedef ValueCalculator_ ValueCalculator;
484  typedef CountIntType_ CountIntType;
486  typedef CountRealAvgType_ CountRealAvgType;
487 
489  static constexpr int NumTrackValues = NumTrackValues_;
491  static constexpr int NumLevels = NumLevels_;
492 
494  typedef typename ValueCalculator::ValueType ValueType;
495 
497  typedef BinningAnalysisParams<ValueType,NumTrackValues,NumLevels,false/*StoreBinSums*/,CountIntType>
499 
513 
517 
518 };
519 
527 template<typename Params,
528  typename LoggerType_ = Logger::VacuumLogger
529  >
531  : public virtual Tools::NeedOwnOperatorNew<ValueHistogramMHRWStatsCollector<
532  typename Params::ValueCalculator,
533  LoggerType_,
534  typename Params::BaseHistogramType
535  >,
536  BinningAnalysis<typename Params::BinningAnalysisParamsType, LoggerType_>,
537  typename Params::Result
538  >::ProviderType
539 {
540 public:
541 
543  typedef typename Params::ValueCalculator ValueCalculator;
545  typedef typename Params::CountIntType CountIntType;
547  typedef typename Params::CountRealAvgType CountRealAvgType;
548 
550  typedef LoggerType_ LoggerType;
551 
553  typedef typename Params::BaseHistogramType BaseHistogramType;
555  typedef typename Params::HistogramParams HistogramParams;
556 
558  typedef typename Params::ValueType ValueType;
559 
561  typedef typename Params::BinningAnalysisParamsType BinningAnalysisParamsType;
564 
566  static constexpr int NumTrackValuesCTime = Params::NumTrackValues;
568  static constexpr int NumLevelsCTime = Params::NumLevels;
569 
571  typedef typename Params::Result ResultType;
572 
577  ValueCalculator,
578  LoggerType,
579  BaseHistogramType
581 
582 private:
583 
584  ValueHistogramMHRWStatsCollectorType value_histogram;
585 
586  BinningAnalysisType binning_analysis;
587 
588  LoggerType & logger;
589 
590  ResultType result;
591 
592 public:
593 
594  ValueHistogramWithBinningMHRWStatsCollector(HistogramParams histogram_params,
595  const ValueCalculator & vcalc,
596  int num_levels,
597  LoggerType & logger_)
598  : value_histogram(histogram_params, vcalc, logger_),
599  binning_analysis((int)histogram_params.num_bins, num_levels, logger_),
600  logger(logger_),
601  result(histogram_params, binning_analysis)
602  {
603  logger.longdebug("ValueHistogramWithBinningMHRWStatsCollector", "constructor()");
604  }
605 
607  inline const BaseHistogramType & histogram() const
608  {
609  return value_histogram.histogram();
610  }
611 
612  inline const BinningAnalysisType & getBinningAnalysis() const
613  {
614  return binning_analysis;
615  }
616 
623  inline const ResultType & getResult() const
624  {
625  return result;
626  }
627 
628  // stats collector part
629 
631  inline void init()
632  {
633  value_histogram.init();
634  }
636  inline void thermalizingDone()
637  {
638  value_histogram.thermalizingDone();
639  }
641  inline void done()
642  {
643  logger.longdebug("ValueHistogramWithBinningMHRWStatsCollector::done()", "finishing up ...");
644 
645  value_histogram.template done<false>();
646 
647  //
648  // Determine the error bars from the binning analysis. Remember, the binning analysis was
649  // applied to each of the indicator functions "chi(value) = (value in bin # i) ? 1 : 0"
650  //
651  // The total number of samples is simply h.bins.sum()+h.off_chart; this is the relevant
652  // coefficient to calculate the bin means needed by binning_analysis.calcErrorLevels(). Indeed,
653  // in this way we really get the averaged observed value of each indicator function for each
654  // value interval.
655  //
656  const BaseHistogramType & h = value_histogram.histogram();
657  result.hist.params = h.params;
658  CountRealAvgType numsamples = h.bins.sum() + h.off_chart;
659  result.hist.bins = h.bins.template cast<CountRealAvgType>() / numsamples;
660  result.error_levels = binning_analysis.calcErrorLevels(result.hist.bins);
661  result.hist.delta = result.error_levels.col(binning_analysis.numLevels()).template cast<CountRealAvgType>();
662  result.hist.off_chart = h.off_chart / numsamples;
663 
664  result.converged_status = binning_analysis.determineErrorConvergence(result.error_levels);
665 
666  logger.debug("ValueHistogramWithBinningMHRWStatsCollector", [&,this](std::ostream & str) {
667  str << "Binning analysis: bin sqmeans at different binning levels are:\n"
668  << binning_analysis.getBinSqmeans() << "\n"
669  << "\t-> so the error bars at different binning levels are:\n"
670  << result.error_levels << "\n"
671  << "\t-> convergence analysis: \n";
672  result.dumpConvergenceAnalysis(str);
673  str << "\t... and just for you, here is the final histogram:\n" << result.hist.prettyPrint() << "\n";
674  });
675  }
676 
678  template<typename CountIntType2, typename PointType, typename LLHValueType, typename MHRandomWalk>
679  inline void rawMove(CountIntType2 k, bool is_thermalizing, bool is_live_iter, bool accepted,
680  double a, const PointType & newpt, LLHValueType newptval,
681  const PointType & curpt, LLHValueType curptval, MHRandomWalk & mh)
682  {
683  value_histogram.rawMove(k, is_thermalizing, is_live_iter, accepted, a, newpt, newptval, curpt, curptval, mh);
684  }
685 
687  template<typename CountIntType2, typename PointType, typename LLHValueType, typename MHRandomWalk>
688  inline void processSample(CountIntType2 k, CountIntType2 n, const PointType & curpt,
689  LLHValueType curptval, MHRandomWalk & mh)
690  {
691  std::size_t histindex = value_histogram.processSample(k, n, curpt, curptval, mh);
692  binning_analysis.processNewValues(
694  histindex,
695  value_histogram.histogram().numBins()
696  )
697  );
698  }
699 
700 };
701 
702 
703 
704 
705 
706 
713 template<typename MHRWStatsCollector_>
714 TOMOGRAPHER_EXPORT struct MHRWStatsCollectorStatus
715 {
716  typedef MHRWStatsCollector_ MHRWStatsCollector;
717 
718  static constexpr bool CanProvideStatus = false;
719 
724  static inline std::string getStatus(const MHRWStatsCollector * /*stats*/)
725  {
726  return std::string();
727  }
728 };
729 // static members:
730 template<typename MHRWStatsCollector_>
732 
733 
734 
738 template<typename... Args>
739 TOMOGRAPHER_EXPORT struct MHRWStatsCollectorStatus<MultipleMHRWStatsCollectors<Args... > >
740 {
742 
743  static constexpr int NumStatColl = MHRWStatsCollector::NumStatColl;
744 
745  static constexpr bool CanProvideStatus = true;
746 
747  template<int I = 0, typename std::enable_if<(I < NumStatColl), bool>::type dummy = true>
748  static inline std::string getStatus(const MHRWStatsCollector * stats)
749  {
750  typedef typename std::tuple_element<I, typename MHRWStatsCollector::MHRWStatsCollectorsTupleType>::type
751  ThisStatsCollector;
752  return
754  ? (MHRWStatsCollectorStatus<ThisStatsCollector>::getStatus(& stats->template getStatsCollector<I>())
755  + ((I < (NumStatColl-1)) ? std::string("\n") : std::string()))
756  : std::string())
757  + getStatus<I+1>(stats);
758  };
759 
760  template<int I = 0, typename std::enable_if<(I == NumStatColl), bool>::type dummy = true>
761  static inline std::string getStatus(const MHRWStatsCollector * stats)
762  {
763  (void)stats;
764  return std::string();
765  }
766 
767 };
768 // static members:
769 template<typename... Args>
771 template<typename... Args>
772 constexpr bool MHRWStatsCollectorStatus<MultipleMHRWStatsCollectors<Args... > >::CanProvideStatus;
773 
774 
775 
779 template<typename ValueCalculator_,
780  typename LoggerType_,
781  typename HistogramType_
782  >
783 TOMOGRAPHER_EXPORT struct MHRWStatsCollectorStatus<ValueHistogramMHRWStatsCollector<ValueCalculator_, LoggerType_, HistogramType_> >
784 {
786 
787  static constexpr bool CanProvideStatus = true;
788 
789  static inline std::string getStatus(const MHRWStatsCollector * stats)
790  {
791  const int maxbarwidth = 50;
792 
793  typedef typename MHRWStatsCollector::HistogramType HistogramType;
794 
795  return "Histogram: " + histogramShortBar<HistogramType>(stats->histogram(), true, maxbarwidth);
796  }
797 };
798 // static members:
799 template<typename ValueCalculator_,
800  typename LoggerType_,
801  typename HistogramType_
802  >
803 constexpr bool
805 
806 
810 template<typename Params_,
811  typename LoggerType_
812  >
813 TOMOGRAPHER_EXPORT struct MHRWStatsCollectorStatus<ValueHistogramWithBinningMHRWStatsCollector<Params_, LoggerType_> >
814 {
816 
817  static constexpr bool CanProvideStatus = true;
818 
819  static inline std::string getStatus(const MHRWStatsCollector * stats)
820  {
821  const int maxbarwidth = 50;
822 
823  typedef typename MHRWStatsCollector::BaseHistogramType BaseHistogramType;
824  const BaseHistogramType & histogram = stats->histogram();
825 
826  // calculate the error bars at different levels, to determine convergence status.
827  typedef typename MHRWStatsCollector::BinningAnalysisType BinningAnalysisType;
828  //typedef typename MHRWStatsCollector::CountRealAvgType CountRealAvgType;
829  typedef typename BinningAnalysisType::ValueType ValueType;
830  const auto& binning_analysis = stats->getBinningAnalysis();
831  Eigen::Array<ValueType, Eigen::Dynamic, 1> binmeans(histogram.numBins());
832  binmeans = histogram.bins.template cast<ValueType>() /
833  (ValueType)(histogram.bins.sum() + histogram.off_chart);
834 
835  auto error_levels = binning_analysis.calcErrorLevels(binmeans);
836  auto conv_status = binning_analysis.determineErrorConvergence(error_levels);
837 
838  int n_cnvg = 0;
839  int n_unknown = 0;
840  int n_not_cnvg = 0;
841  for (std::size_t k = 0; k < (std::size_t)histogram.numBins(); ++k) {
842  if (conv_status(k) == BinningAnalysisType::CONVERGED) {
843  ++n_cnvg;
844  } else if (conv_status(k) == BinningAnalysisType::NOT_CONVERGED) {
845  ++n_not_cnvg;
846  } else {
847  ++n_unknown;
848  }
849  }
850 
851  return tomo_internal::histogram_short_bar_fmt<BaseHistogramType>(histogram, "", maxbarwidth)
852  + Tools::fmts(" err: (cnvg/?/fail) %d/%d/%d", n_cnvg, n_unknown, n_not_cnvg);
853  }
854 };
855 // static members:
856 template<typename Params_,
857  typename LoggerType_
858  >
859 constexpr bool
861 
862 
863 } // namespace Tomographer
864 
865 
866 
867 #endif
A StatsCollector which builds a histogram of values calculated with a ValueCalculator for each data s...
A Metropolis-Hastings Random Walk.
Definition: mhrw.h:290
auto canonicalBasisVec(IndexType k, IndexType size) -> const Eigen::CwiseNullaryOp< tomo_internal::can_basis_vec_generator< typename Eigen::internal::traits< Der >::Scalar, IndexType >, Der >
Expression for the k-th canonical basis vector of given dimension.
Definition: eigenutil.h:213
Params::BaseHistogramType BaseHistogramType
See ValueHistogramWithBinningMHRWStatsCollectorParams::BaseHistogramType .
void done()
Finalize the data collection. Part of the MHRWStatsCollector Interface.
BinningAnalysis< BinningAnalysisParamsType, LoggerType > BinningAnalysisType
The corresponding BinningAnalysis type for this value histogram stats collector.
auto getBinSqmeans() const
Get the raw average of the squared values observed, for each binning level.
Definition: mhrw_bin_err.h:579
void done()
Part of the MHRWStatsCollector Interface.
Base namespace for the Tomographer project.
Definition: densellh.h:45
CountRealAvgType_ CountRealAvgType
Type used to store the averages of the histogram bins.
ValueHistogramMHRWStatsCollector(HistogramParams histogram_params, const ValueCalculator &vcalc, LoggerType &logger)
Simple constructor, initializes with the given values.
const BaseHistogramType & histogram() const
Get the histogram data collected so far. See BaseHistogramType .
Stores a histogram along with error bars.
Definition: histogram.h:477
ValueCalculator::ValueType ValueType
The type to use to represent a calculated distance.
Eigen::ArrayXi converged_status
Information of convergence status of the error bars (see e.g. BinningAnalysisParamsType::CONVERGED) ...
Group template parameters for BinningAnalysis.
Definition: mhrw_bin_err.h:110
Eigen::ArrayXi determineErrorConvergence(const Eigen::Ref< const BinSumSqArray > &error_levels) const
Attempt to determine if the error bars have converged.
Definition: mhrw_bin_err.h:729
Result type of a ValueHistogramWithBinningMHRWStatsCollector.
HistogramType::Params HistogramParams
The corresponding histogram params type.
ValueHistogramWithBinningMHRWStatsCollectorResult(HistogramParams p, const BinningAnalysisType &b)
Constructor which initializes the fields from the histogram and binning analysis type.
Params::HistogramParams HistogramParams
See ValueHistogramWithBinningMHRWStatsCollectorParams::HistogramParams .
void processNewValues(const Eigen::DenseBase< Derived > &vals)
Process new raw samples.
Definition: mhrw_bin_err.h:457
Provide appropriate operator new() definitions for a structure which has a member of the given stored...
ValueCalculator_ ValueCalculator
The type which calculates the interesting value. Should be of type interface ValueCalculator Interfac...
const Tools::StaticOrDynamic< int,(NumLevelsCTime==Eigen::Dynamic), NumLevelsCTime > numLevels
The number of levels in the binning analysis.
Definition: mhrw_bin_err.h:326
void thermalizingDone()
Part of the MHRWStatsCollector Interface. No-op.
Logger that discards all messages.
Definition: loggers.h:1280
HistogramType hist
Histogram, already with error bars.
void rawMove(CountIntType2 k, bool is_thermalizing, bool is_live_iter, bool accepted, double a, const PointType &newpt, LLHValueType newptval, const PointType &curpt, LLHValueType curptval, MHRandomWalk &mh)
Part of the MHRWStatsCollector Interface. No-op.
UniformBinsHistogram< typename ValueCalculator::ValueType, CountIntType > BaseHistogramType
The Base Histogram Type.
HistogramType::Params HistogramParams
Structure which holds the parameters of the histogram we&#39;re recording.
ValueHistogramWithBinningMHRWStatsCollectorResult(const HistogramType &hist_, const Eigen::DenseBase< EigenDerived1 > &error_levels_, const Eigen::DenseBase< EigenDerived2 > &converged_status_)
Simple constructor with direct initialization of fields.
T setw(T... args)
static constexpr int NumStatColl
The number of stats collectors we are tracking.
STL class.
HistogramType_ ResultType
Required for compliance with Resultable Interface type.
const ResultType & getResult() const
Get the histogram data collected. This method is needed for Resultable Interface compliance.
Traits-like class for ValueHistogramWithBinningMHRWStatsCollector.
std::size_t processSample(CountIntType k, CountIntType n, const PointType &curpt, LLHValueType, MHRandomWalk &)
Part of the MHRWStatsCollector Interface. Records the sample in the histogram.
Collect a histogram of values from a MH random walk, with binning analysis.
BinSumSqArray calcErrorLevels(const Eigen::ArrayBase< Derived > &means) const
Calculate the error bars of samples at different binning levels.
Definition: mhrw_bin_err.h:629
const HistogramType & histogram() const
Get the histogram data collected so far. See HistogramType.
Params::ValueType ValueType
See ValueHistogramWithBinningMHRWStatsCollectorParams::ValueType .
Params::BinningAnalysisParamsType BinningAnalysisParamsType
See ValueHistogramWithBinningMHRWStatsCollectorParams::BinningAnalysisParamsType .
Params::ValueCalculator ValueCalculator
See ValueHistogramWithBinningMHRWStatsCollectorParams::ValueCalculator .
void thermalizingDone()
Part of the MHRWStatsCollector Interface. No-op.
void rawMove(CountIntType k, bool, bool, bool, double, const PointType &, LLHValueType, const PointType &, LLHValueType, MHRandomWalk &)
Part of the MHRWStatsCollector Interface. No-op.
ValueHistogramWithBinningMHRWStatsCollectorResult< HistogramType, BinningAnalysisParamsType > Result
Result type of the corresponding ValueHistogramWithBinningMHRWStatsCollector.
T str(T... args)
Params::CountRealAvgType CountRealAvgType
See ValueHistogramWithBinningMHRWStatsCollectorParams::CountRealAvgType .
Some C++ utilities, with a tad of C++11 tricks.
HistogramType_ HistogramType
The type of the histogram. Usually a UniformBinsHistogram with ValueType range type.
static std::string getStatus(const MHRWStatsCollector *)
Prepare a string which reports the status of the given stats collector.
void init()
Part of the MHRWStatsCollector Interface. Initializes the histogram to zeros.
std::string fmts(const char *fmt,...)
printf- format to a std::string
Definition: fmt.h:125
std::string dumpConvergenceAnalysis() const
Dump values, error bars and convergence status in human-readable form as string.
Template, specializable class to get status reports from stats collectors.
Params::CountIntType CountIntType
See ValueHistogramWithBinningMHRWStatsCollectorParams::CountIntType .
BinningAnalysisParams< ValueType, NumTrackValues, NumLevels, false, CountIntType > BinningAnalysisParamsType
The relevant BinningAnalysis parameters for us.
void dumpConvergenceAnalysis(std::ostream &str) const
Dump values, error bars and convergence status in human-readable form into ostream.
ValueCalculator_ ValueCalculator
The type of the ValueCalculator Interface which calculates the value of which we&#39;re collecting a hist...
void processSample(CountIntType2 k, CountIntType2 n, const PointType &curpt, LLHValueType curptval, MHRandomWalk &mh)
Part of the MHRWStatsCollector Interface. Records the sample in the histogram.
LoggerType_ LoggerType
Somewhere where this object may log what it&#39;s doing.
ValueHistogramWithBinningMHRWStatsCollectorResult()
Simple default constructor (e.g. to use as std::vector<Result>).
Definitions for Histogram Types.
The parameters of a UniformBinsHistogram.
Definition: histogram.h:68
UniformBinsHistogramWithErrorBars< typename ValueCalculator::ValueType, CountRealAvgType > HistogramType
The Final Histogram Type (with error bars).
Long Debug logging level.
Definition: loggers.h:123
Params::Result ResultType
See ValueHistogramWithBinningMHRWStatsCollectorParams::Result .
Stores a histogram.
Definition: histogram.h:211
Binning Analysis in a Metropolis-Hastings random walk.
STL class.
void init()
Part of the MHRWStatsCollector Interface. Initializes the histogram to zeros.
const ResultType & getResult() const
Get the final histogram data. This method is needed for Resultable Interface compliance.
#define tomographer_assert(...)
Assertion test macro.
Definition: cxxdefs.h:83
BinningAnalysisParamsType::BinSumSqArray error_levels
Detailed error bars for all binning levels.
ValueHistogramMHRWStatsCollector< ValueCalculator, LoggerType, BaseHistogramType > ValueHistogramMHRWStatsCollectorType
This is the natural ValueHistogramMHRWStatsCollector type on which we&#39;re adding error bars...
Utilities for logging messages.
ValueCalculator::ValueType ValueType
The type of a value calculated by the ValueCalculator Interface.
A simple MHRWStatsCollector interface which combines several stats collectors.
MultipleMHRWStatsCollectors TrivialMHRWStatsCollector
Trivial, NO-OP stats collector.
CountIntType_ CountIntType
Type used to count the number of hits in each bin.