Tomographer  v2.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  *
8  * Permission is hereby granted, free of charge, to any person obtaining a copy
9  * of this software and associated documentation files (the "Software"), to deal
10  * in the Software without restriction, including without limitation the rights
11  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12  * copies of the Software, and to permit persons to whom the Software is
13  * furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24  * SOFTWARE.
25  */
26 
27 #ifndef TOMOGRAPHER_MHRWSTATSCOLLECTORS_H
28 #define TOMOGRAPHER_MHRWSTATSCOLLECTORS_H
29 
30 #include <cstddef>
31 
32 #include <limits>
33 #include <tuple>
34 #include <utility>
35 #include <type_traits>
36 #include <typeinfo>
37 
38 
41 #include <tomographer2/histogram.h>
43 
54 namespace Tomographer {
55 
56 
86 template<typename... MHRWStatsCollectors>
88 {
89 public:
90  typedef std::tuple<MHRWStatsCollectors&...> MHRWStatsCollectorsRefTupleType;
91  typedef std::tuple<MHRWStatsCollectors...> MHRWStatsCollectorsTupleType;
92 
94  static constexpr int NumStatColl = sizeof...(MHRWStatsCollectors);
95 
96 private:
97  MHRWStatsCollectorsRefTupleType statscollectors;
98 
99 public:
100 
101  MultipleMHRWStatsCollectors(MHRWStatsCollectors&... statscollectors_)
102  : statscollectors(statscollectors_...)
103  {
104  }
105 
106  // method to get a particular stats collector
107  template<int I>
108  inline const typename std::tuple_element<I, MHRWStatsCollectorsTupleType>::type & getStatsCollector() const
109  {
110  return std::get<I>(statscollectors);
111  }
112 
113  // init() callback
114 
115  template<int I = 0>
116  inline typename std::enable_if<I < NumStatColl, void>::type init()
117  {
118  std::get<I>(statscollectors).init();
119  init<I+1>();
120  }
121  template<int I = 0>
122  inline typename std::enable_if<I == NumStatColl, void>::type init()
123  {
124  }
125 
126  // thermalizingDone() callback
127 
128  template<int I = 0>
129  inline typename std::enable_if<I < NumStatColl, void>::type thermalizingDone()
130  {
131  std::get<I>(statscollectors).thermalizingDone();
132  thermalizingDone<I+1>();
133  }
134  template<int I = 0>
135  inline typename std::enable_if<I == NumStatColl, void>::type thermalizingDone()
136  {
137  }
138 
139  // done() callback
140 
141  template<int I = 0>
142  inline typename std::enable_if<I < NumStatColl, void>::type done()
143  {
144  std::get<I>(statscollectors).done();
145  done<I+1>();
146  }
147  template<int I = 0>
148  inline typename std::enable_if<I == NumStatColl, void>::type done()
149  {
150  }
151 
152 
153  // rawMove() callback
154 
155  template<typename CountIntType, typename PointType, typename FnValueType, typename MHRandomWalk, int I = 0>
156  inline typename std::enable_if<I < NumStatColl, void>::type rawMove(
157  CountIntType k, bool is_thermalizing, bool is_live_iter, bool accepted,
158  double a, const PointType & newpt, FnValueType newptval,
159  const PointType & curpt, FnValueType curptval,
160  MHRandomWalk & rw
161  )
162  {
163  std::get<I>(statscollectors).rawMove(
164  k, is_thermalizing, is_live_iter, accepted, a,
165  newpt, newptval, curpt, curptval, rw
166  );
167  rawMove<CountIntType, PointType, FnValueType, MHRandomWalk, I+1>(
168  k, is_thermalizing, is_live_iter, accepted, a,
169  newpt, newptval, curpt, curptval, rw
170  );
171  }
172  template<typename CountIntType, typename PointType, typename FnValueType, typename MHRandomWalk, int I = 0>
173  inline typename std::enable_if<I == NumStatColl, void>::type rawMove(
174  CountIntType, bool, bool, bool, double, const PointType &, FnValueType,
175  const PointType &, FnValueType, MHRandomWalk &
176  )
177  {
178  }
179 
180 
181  // processSample() callback
182 
183  template<typename CountIntType, typename PointType, typename FnValueType, typename MHRandomWalk, int I = 0>
184  inline typename std::enable_if<I < NumStatColl, void>::type processSample(
185  CountIntType k, CountIntType n, const PointType & curpt, FnValueType curptval, MHRandomWalk & rw
186  )
187  {
188  std::get<I>(statscollectors).processSample(k, n, curpt, curptval, rw);
189  processSample<CountIntType, PointType, FnValueType, MHRandomWalk, I+1>(k, n, curpt, curptval, rw);
190  }
191 
192  template<typename CountIntType, typename PointType, typename FnValueType, typename MHRandomWalk, int I = 0>
193  inline typename std::enable_if<I == NumStatColl, void>::type processSample(
194  CountIntType, CountIntType, const PointType &, FnValueType, MHRandomWalk &
195  )
196  {
197  }
198 
199 };
200 
201 
202 
203 
204 
212 
213 
214 
215 
216 // -----------------
217 
218 
219 
234 template<typename ValueCalculator_,
235  typename LoggerType = Logger::VacuumLogger,
237  >
239  : public virtual Tools::NeedOwnOperatorNew<ValueCalculator_, HistogramType_>::ProviderType,
240  public virtual Tools::EigenAlignedOperatorNewProvider // DEBUG:: REDUNDANT???
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 // // specialize NeedOwnOperatorNew for this class
370 // namespace Tools {
371 // template<typename ValueCalculator_,
372 // typename LoggerType,
373 // typename HistogramType_>
374 // >
375 // struct NeedOwnOperatorNew<ValueHistogramMHRWStatsCollector<ValueCalculator_,LoggerType_,HistogramType_> >
376 // : public NeedEigenAlignedOperatorNew { };
377 // };
378 
379 
380 
388 template<typename ValueCalculator_,
389  typename CountIntType_ = int,
390  typename CountRealAvgType_ = double,
391  int NumTrackValues_ = Eigen::Dynamic,
392  int NumLevels_ = Eigen::Dynamic
393  >
395 {
398  typedef ValueCalculator_ ValueCalculator;
400  typedef CountIntType_ CountIntType;
402  typedef CountRealAvgType_ CountRealAvgType;
403 
405  static constexpr int NumTrackValues = NumTrackValues_;
407  static constexpr int NumLevels = NumLevels_;
408 
410  typedef typename ValueCalculator::ValueType ValueType;
411 
413  typedef BinningAnalysisParams<ValueType,NumTrackValues,NumLevels,false/*StoreBinSums*/,CountIntType>
415 
429 
435  struct Result
436  : public virtual Tools::NeedOwnOperatorNew<
437  HistogramType,
438  typename BinningAnalysisParamsType::BinSumSqArray
439  >::ProviderType
440  {
442  explicit Result()
443  : hist(), error_levels(), converged_status()
444  {
445  }
446 
448  template<typename BinningAnalysisType>
449  Result(HistogramParams p, const BinningAnalysisType & b)
450  : hist(p),
451  error_levels(b.numTrackValues(), b.numLevels()+1),
452  converged_status(Eigen::ArrayXi::Constant(b.numTrackValues(), BinningAnalysisType::UNKNOWN_CONVERGENCE))
453  {
454  tomographer_assert(converged_status.rows() == b.numTrackValues() && converged_status.cols() == 1);
455  }
456 
458  HistogramType hist;
464  Eigen::ArrayXi converged_status;
465 
467  inline void dumpConvergenceAnalysis(std::ostream & str) const
468  {
469  for (int k = 0; k < converged_status.size(); ++k) {
470  str << "\tval[" << std::setw(3) << k << "] = "
471  << std::setw(12) << hist.bins(k)
472  << " +- " << std::setw(12) << hist.delta(k);
473  if (converged_status(k) == BinningAnalysisParamsType::CONVERGED) {
474  str << " [CONVERGED]";
475  } else if (converged_status(k) == BinningAnalysisParamsType::NOT_CONVERGED) {
476  str << " [NOT CONVERGED]";
477  } else if (converged_status(k) == BinningAnalysisParamsType::UNKNOWN_CONVERGENCE) {
478  str << " [UNKNOWN]";
479  } else {
480  str << " [UNKNOWN CONVERGENCE STATUS: " << converged_status(k) << "]";
481  }
482  str << "\n";
483  }
484  }
485 
488  {
490  dumpConvergenceAnalysis(ss);
491  return ss.str();
492  }
493 
494  };
495 
496 };
497 
505 template<typename Params,
506  typename LoggerType_ = Logger::VacuumLogger
507  >
509  : public virtual Tools::NeedOwnOperatorNew<ValueHistogramMHRWStatsCollector<
510  typename Params::ValueCalculator,
511  LoggerType_,
512  typename Params::BaseHistogramType
513  >,
514  BinningAnalysis<typename Params::BinningAnalysisParamsType, LoggerType_>,
515  typename Params::Result
516  >::ProviderType
517 {
518 public:
519 
521  typedef typename Params::ValueCalculator ValueCalculator;
523  typedef typename Params::CountIntType CountIntType;
525  typedef typename Params::CountRealAvgType CountRealAvgType;
526 
528  typedef LoggerType_ LoggerType;
529 
531  typedef typename Params::BaseHistogramType BaseHistogramType;
533  typedef typename Params::HistogramParams HistogramParams;
534 
536  typedef typename Params::ValueType ValueType;
537 
539  typedef typename Params::BinningAnalysisParamsType BinningAnalysisParamsType;
542 
544  static constexpr int NumTrackValuesCTime = Params::NumTrackValues;
546  static constexpr int NumLevelsCTime = Params::NumLevels;
547 
549  typedef typename Params::Result ResultType;
550 
555  ValueCalculator,
556  LoggerType,
557  BaseHistogramType
559 
560 private:
561 
562  ValueHistogramMHRWStatsCollectorType value_histogram;
563 
564  BinningAnalysisType binning_analysis;
565 
566  LoggerType & logger;
567 
568  ResultType result;
569 
570 public:
571 
572  ValueHistogramWithBinningMHRWStatsCollector(HistogramParams histogram_params,
573  const ValueCalculator & vcalc,
574  int num_levels,
575  LoggerType & logger_)
576  : value_histogram(histogram_params, vcalc, logger_),
577  binning_analysis(histogram_params.num_bins, num_levels, logger_),
578  logger(logger_),
579  result(histogram_params, binning_analysis)
580  {
581  logger.longdebug("ValueHistogramWithBinningMHRWStatsCollector", "constructor()");
582  }
583 
585  inline const BaseHistogramType & histogram() const
586  {
587  return value_histogram.histogram();
588  }
589 
590  inline const BinningAnalysisType & getBinningAnalysis() const
591  {
592  return binning_analysis;
593  }
594 
601  inline const ResultType & getResult() const
602  {
603  return result;
604  }
605 
606  // stats collector part
607 
609  inline void init()
610  {
611  value_histogram.init();
612  }
614  inline void thermalizingDone()
615  {
616  value_histogram.thermalizingDone();
617  }
619  inline void done()
620  {
621  logger.longdebug("ValueHistogramWithBinningMHRWStatsCollector::done()", "finishing up ...");
622 
623  value_histogram.template done<false>();
624 
625  const BaseHistogramType & h = value_histogram.histogram();
626  result.hist.params = h.params;
627  CountRealAvgType normalization = h.bins.sum() + h.off_chart; // need ALL samples, because that's
628  // what the binning analysis sees
629  result.hist.bins = h.bins.template cast<CountRealAvgType>() / normalization;
630  result.error_levels = binning_analysis.calcErrorLevels(result.hist.bins);
631  result.hist.delta = result.error_levels.col(binning_analysis.numLevels()).template cast<CountRealAvgType>();
632  result.hist.off_chart = h.off_chart / normalization;
633 
634  result.converged_status = binning_analysis.determineErrorConvergence(result.error_levels);
635 
636  logger.debug("ValueHistogramWithBinningMHRWStatsCollector", [&,this](std::ostream & str) {
637  str << "Binning analysis: bin sqmeans at different binning levels are:\n"
638  << binning_analysis.getBinSqmeans() << "\n"
639  << "\t-> so the error bars at different binning levels are:\n"
640  << result.error_levels << "\n"
641  << "\t-> convergence analysis: \n";
642  result.dumpConvergenceAnalysis(str);
643  str << "\t... and just for you, here is the final histogram:\n" << result.hist.prettyPrint() << "\n";
644  });
645  }
646 
648  template<typename CountIntType2, typename PointType, typename LLHValueType, typename MHRandomWalk>
649  inline void rawMove(CountIntType2 k, bool is_thermalizing, bool is_live_iter, bool accepted,
650  double a, const PointType & newpt, LLHValueType newptval,
651  const PointType & curpt, LLHValueType curptval, MHRandomWalk & mh)
652  {
653  value_histogram.rawMove(k, is_thermalizing, is_live_iter, accepted, a, newpt, newptval, curpt, curptval, mh);
654  }
655 
657  template<typename CountIntType2, typename PointType, typename LLHValueType, typename MHRandomWalk>
658  inline void processSample(CountIntType2 k, CountIntType2 n, const PointType & curpt,
659  LLHValueType curptval, MHRandomWalk & mh)
660  {
661  std::size_t histindex = value_histogram.processSample(k, n, curpt, curptval, mh);
662  binning_analysis.processNewValues(
664  histindex,
665  value_histogram.histogram().numBins()
666  )
667  );
668  }
669 
670 };
671 
672 
673 
674 
675 
676 
683 template<typename MHRWStatsCollector_>
685 {
686  typedef MHRWStatsCollector_ MHRWStatsCollector;
687 
688  static constexpr bool CanProvideStatus = false;
689 
694  static inline std::string getStatus(const MHRWStatsCollector * /*stats*/)
695  {
696  return std::string();
697  }
698 };
699 // static members:
700 template<typename MHRWStatsCollector_>
702 
703 
704 
708 template<typename... Args>
710 {
712 
713  static constexpr int NumStatColl = MHRWStatsCollector::NumStatColl;
714 
715  static constexpr bool CanProvideStatus = true;
716 
717  template<int I = 0, typename std::enable_if<(I < NumStatColl), bool>::type dummy = true>
718  static inline std::string getStatus(const MHRWStatsCollector * stats)
719  {
720  typedef typename std::tuple_element<I, typename MHRWStatsCollector::MHRWStatsCollectorsTupleType>::type
721  ThisStatsCollector;
722  return
724  ? (MHRWStatsCollectorStatus<ThisStatsCollector>::getStatus(& stats->template getStatsCollector<I>())
725  + ((I < (NumStatColl-1)) ? std::string("\n") : std::string()))
726  : std::string())
727  + getStatus<I+1>(stats);
728  };
729 
730  template<int I = 0, typename std::enable_if<(I == NumStatColl), bool>::type dummy = true>
731  static inline std::string getStatus(const MHRWStatsCollector * stats)
732  {
733  (void)stats;
734  return std::string();
735  }
736 
737 };
738 // static members:
739 template<typename... Args>
741 template<typename... Args>
742 constexpr bool MHRWStatsCollectorStatus<MultipleMHRWStatsCollectors<Args... > >::CanProvideStatus;
743 
744 
745 
749 template<typename ValueCalculator_,
750  typename LoggerType_,
751  typename HistogramType_
752  >
753 struct MHRWStatsCollectorStatus<ValueHistogramMHRWStatsCollector<ValueCalculator_, LoggerType_, HistogramType_> >
754 {
756 
757  static constexpr bool CanProvideStatus = true;
758 
759  static inline std::string getStatus(const MHRWStatsCollector * stats)
760  {
761  const int maxbarwidth = 50;
762 
763  typedef typename MHRWStatsCollector::HistogramType HistogramType;
764 
765  return "Histogram: " + histogramShortBar<HistogramType>(stats->histogram(), true, maxbarwidth);
766  }
767 };
768 // static members:
769 template<typename ValueCalculator_,
770  typename LoggerType_,
771  typename HistogramType_
772  >
773 constexpr bool
775 
776 
780 template<typename Params_,
781  typename LoggerType_
782  >
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::BaseHistogramType BaseHistogramType;
794  const BaseHistogramType & histogram = stats->histogram();
795 
796  // calculate the error bars at different levels, to determine convergence status.
797  typedef typename MHRWStatsCollector::BinningAnalysisType BinningAnalysisType;
798  //typedef typename MHRWStatsCollector::CountRealAvgType CountRealAvgType;
799  typedef typename BinningAnalysisType::ValueType ValueType;
800  const auto& binning_analysis = stats->getBinningAnalysis();
801  Eigen::Array<ValueType, Eigen::Dynamic, 1> binmeans(histogram.numBins());
802  binmeans = histogram.bins.template cast<ValueType>() /
803  (ValueType)(histogram.bins.sum() + histogram.off_chart);
804 
805  auto error_levels = binning_analysis.calcErrorLevels(binmeans);
806  auto conv_status = binning_analysis.determineErrorConvergence(error_levels);
807 
808  int n_cnvg = 0;
809  int n_unknown = 0;
810  int n_not_cnvg = 0;
811  for (std::size_t k = 0; k < (std::size_t)histogram.numBins(); ++k) {
812  if (conv_status(k) == BinningAnalysisType::CONVERGED) {
813  ++n_cnvg;
814  } else if (conv_status(k) == BinningAnalysisType::NOT_CONVERGED) {
815  ++n_not_cnvg;
816  } else {
817  ++n_unknown;
818  }
819  }
820 
821  return tomo_internal::histogram_short_bar_fmt<BaseHistogramType>(histogram, "", maxbarwidth)
822  + Tools::fmts(" err: (cnvg/?/fail) %d/%d/%d", n_cnvg, n_unknown, n_not_cnvg);
823  }
824 };
825 // static members:
826 template<typename Params_,
827  typename LoggerType_
828  >
829 constexpr bool
831 
832 
833 } // namespace Tomographer
834 
835 
836 
837 #endif
void dumpConvergenceAnalysis(std::ostream &str) const
Dump values, error bars and convergence status in human-readable form into ostream.
A StatsCollector which builds a histogram of values calculated with a ValueCalculator for each data s...
A Metropolis-Hastings Random Walk.
Definition: mhrw.h:281
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:212
Result type of the corresponding ValueHistogramWithBinningMHRWStatsCollector.
Params::BaseHistogramType BaseHistogramType
See ValueHistogramWithBinningMHRWStatsCollectorParams::BaseHistogramType .
Eigen::Array< CountType, Eigen::Dynamic, 1 > bins
The counts for each bin.
Definition: histogram.h:194
Result(HistogramParams p, const BinningAnalysisType &b)
Constructor which initializes the fields from the histogram and binning analysis type.
void done()
Finalize the data collection. Part of the MHRWStatsCollector Interface.
std::string dumpConvergenceAnalysis() const
Dump values, error bars and convergence status in human-readable form as string.
BinningAnalysis< BinningAnalysisParamsType, LoggerType > BinningAnalysisType
The corresponding BinningAnalysis type for this value histogram stats collector.
Provides correct operator-new implementation for Eigen types via the NeedOwnOperatorNew mechanism...
void done()
Part of the MHRWStatsCollector Interface.
Base namespace for the Tomographer project.
Definition: densellh.h:44
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.
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:109
BinSumSqArray calcErrorLevels(const Eigen::ArrayBase< Derived > &means) const
Calculate the error bars of samples at different binning levels.
Definition: mhrw_bin_err.h:628
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:728
HistogramType::Params HistogramParams
The corresponding histogram params type.
Params::HistogramParams HistogramParams
See ValueHistogramWithBinningMHRWStatsCollectorParams::HistogramParams .
void processNewValues(const Eigen::DenseBase< Derived > &vals)
Process new raw samples.
Definition: mhrw_bin_err.h:456
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:325
void thermalizingDone()
Part of the MHRWStatsCollector Interface. No-op.
Logger that discards all messages.
Definition: loggers.h:1279
Eigen::Array< CountType, Eigen::Dynamic, 1 > delta
The error bars associated with each histogram bin.
Definition: histogram.h:413
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.
const ResultType & getResult() const
Get the histogram data collected. This method is needed for Resultable Interface compliance.
Result()
Simple default constructor (e.g. to use as std::vector<Result>).
HistogramType::Params HistogramParams
Structure which holds the parameters of the histogram we&#39;re recording.
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.
BinningAnalysisParamsType::BinSumSqArray error_levels
Detailed error bars for all binning levels.
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.
Params::ValueType ValueType
See ValueHistogramWithBinningMHRWStatsCollectorParams::ValueType .
const HistogramType & histogram() const
Get the histogram data collected so far. See HistogramType.
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.
T str(T...args)
Params::CountRealAvgType CountRealAvgType
See ValueHistogramWithBinningMHRWStatsCollectorParams::CountRealAvgType .
const ResultType & getResult() const
Get the final histogram data. This method is needed for Resultable Interface compliance.
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:124
Base_::Params Params
Shortcut for our base class&#39; histogram parameters. See UniformBinsHistogram::Params.
Definition: histogram.h:407
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.
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.
Definitions for Histogram Types.
UniformBinsHistogramWithErrorBars< typename ValueCalculator::ValueType, CountRealAvgType > HistogramType
The Final Histogram Type (with error bars).
Long Debug logging level.
Definition: loggers.h:122
Stores a histogram.
Definition: histogram.h:68
Params::Result ResultType
See ValueHistogramWithBinningMHRWStatsCollectorParams::Result .
Binning Analysis in a Metropolis-Hastings random walk.
STL class.
void init()
Part of the MHRWStatsCollector Interface. Initializes the histogram to zeros.
const BaseHistogramType & histogram() const
Get the histogram data collected so far. See BaseHistogramType .
ValueHistogramMHRWStatsCollector< ValueCalculator, LoggerType, BaseHistogramType > ValueHistogramMHRWStatsCollectorType
This is the natural ValueHistogramMHRWStatsCollector type on which we&#39;re adding error bars...
Utilities for logging messages.
auto getBinSqmeans() const
Get the raw average of the squared values observed, for each binning level.
Definition: mhrw_bin_err.h:578
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.