Tomographer  v3.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>
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  >
240  : public virtual Tools::NeedOwnOperatorNew<ValueCalculator_, HistogramType_>::ProviderType,
241  public virtual Tools::EigenAlignedOperatorNewProvider // DEBUG:: REDUNDANT???
242 {
243 public:
247  typedef ValueCalculator_ ValueCalculator;
248 
250  typedef typename ValueCalculator::ValueType ValueType;
251 
253  typedef HistogramType_ HistogramType;
254 
256  typedef HistogramType_ ResultType;
257 
259  typedef typename HistogramType::Params HistogramParams;
260 
261 private:
262 
264  HistogramType _histogram;
265 
270  ValueCalculator _vcalc;
271 
272  LoggerType & _logger;
273 
274 public:
276  ValueHistogramMHRWStatsCollector(HistogramParams histogram_params,
277  const ValueCalculator & vcalc,
278  LoggerType & logger)
279  : _histogram(histogram_params),
280  _vcalc(vcalc),
281  _logger(logger)
282  {
283  }
284 
286  inline const HistogramType & histogram() const
287  {
288  return _histogram;
289  }
290 
300  inline const ResultType & getResult() const
301  {
302  return _histogram;
303  }
304 
305  // stats collector part
306 
308  inline void init()
309  {
310  // reset our array
311  _histogram.reset();
312  }
314  inline void thermalizingDone()
315  {
316  }
324  template<bool PrintHistogram = true>
325  inline void done()
326  {
327  if (PrintHistogram) {
328  if (_logger.enabledFor(Logger::LONGDEBUG)) {
329  // _logger.longdebug("ValueHistogramMHRWStatsCollector", "done()");
330  _logger.longdebug("ValueHistogramMHRWStatsCollector",
331  "Done walking & collecting stats. Here's the histogram:\n"
332  + _histogram.prettyPrint());
333  }
334  }
335  }
336 
338  template<typename CountIntType, typename PointType, typename LLHValueType, typename MHRandomWalk>
339  void rawMove(CountIntType k, bool /*is_thermalizing*/, bool /*is_live_iter*/, bool /*accepted*/,
340  double /*a*/, const PointType & /*newpt*/, LLHValueType /*newptval*/,
341  const PointType & /*curpt*/, LLHValueType /*curptval*/, MHRandomWalk & /*mh*/)
342  {
343  _logger.longdebug("ValueHistogramMHRWStatsCollector", [&](std::ostream & stream) {
344  stream << "rawMove(): k=" << k;
345  });
346  }
347 
349  template<typename CountIntType, typename PointType, typename LLHValueType, typename MHRandomWalk>
350  std::size_t processSample(CountIntType k, CountIntType n, const PointType & curpt,
351  LLHValueType /*curptval*/, MHRandomWalk & /*mh*/)
352  {
353  ValueType val = _vcalc.getValue(curpt);
354 
355  _logger.longdebug("ValueHistogramMHRWStatsCollector", [&](std::ostream & stream) {
356  stream << "in processSample(): "
357  << "k=" << k << ", n=" << n << ", val=" << val
358  << " [with ValueType=" << typeid(ValueType).name() << "]" ;
359  });
360 
361  return _histogram.record(val);
362 
363  //_logger.longdebug("ValueHistogramMHRWStatsCollector", "processSample() finished");
364  }
365 
366 
367 };
368 
369 
370 
371 
377 template<typename HistogramType_, typename BinningAnalysisParamsType_>
379  : public virtual Tools::NeedOwnOperatorNew<
380  HistogramType_,
381  typename BinningAnalysisParamsType_::BinSumSqArray
382  >::ProviderType
383 {
384  typedef HistogramType_ HistogramType;
385  typedef typename HistogramType::Params HistogramParams;
386  typedef BinningAnalysisParamsType_ BinningAnalysisParamsType;
387 
390  : hist(), error_levels(), converged_status()
391  {
392  }
393 
395  template<typename EigenDerived1, typename EigenDerived2>
397  const Eigen::DenseBase<EigenDerived1> & error_levels_,
398  const Eigen::DenseBase<EigenDerived2> & converged_status_)
399  : hist(hist_), error_levels(error_levels_), converged_status(converged_status_)
400  {
401  }
402 
404  template<typename BinningAnalysisType>
405  ValueHistogramWithBinningMHRWStatsCollectorResult(HistogramParams p, const BinningAnalysisType & b)
406  : hist(p),
407  error_levels(b.numTrackValues(), b.numLevels()+1),
408  converged_status(Eigen::ArrayXi::Constant(b.numTrackValues(), BinningAnalysisType::UNKNOWN_CONVERGENCE))
409  {
410  tomographer_assert(converged_status.rows() == b.numTrackValues() && converged_status.cols() == 1);
411  }
412 
422  HistogramType hist;
423 
426  typename BinningAnalysisParamsType::BinSumSqArray error_levels;
427 
431  Eigen::ArrayXi converged_status;
432 
434  inline void dumpConvergenceAnalysis(std::ostream & str) const
435  {
436  for (int k = 0; k < converged_status.size(); ++k) {
437  str << "\tval[" << std::setw(3) << k << "] = "
438  << std::setw(12) << hist.bins(k)
439  << " +- " << std::setw(12) << hist.delta(k);
440  if (converged_status(k) == BinningAnalysisParamsType::CONVERGED) {
441  str << " [CONVERGED]";
442  } else if (converged_status(k) == BinningAnalysisParamsType::NOT_CONVERGED) {
443  str << " [NOT CONVERGED]";
444  } else if (converged_status(k) == BinningAnalysisParamsType::UNKNOWN_CONVERGENCE) {
445  str << " [UNKNOWN]";
446  } else {
447  str << " [UNKNOWN CONVERGENCE STATUS: " << converged_status(k) << "]";
448  }
449  str << "\n";
450  }
451  }
452 
455  {
457  dumpConvergenceAnalysis(ss);
458  return ss.str();
459  }
460 
461 };
462 
463 
464 
465 
473 template<typename ValueCalculator_,
474  typename CountIntType_ = int,
475  typename CountRealAvgType_ = double,
476  int NumTrackValues_ = Eigen::Dynamic,
477  int NumLevels_ = Eigen::Dynamic
478  >
480 {
483  typedef ValueCalculator_ ValueCalculator;
485  typedef CountIntType_ CountIntType;
487  typedef CountRealAvgType_ CountRealAvgType;
488 
490  static constexpr int NumTrackValues = NumTrackValues_;
492  static constexpr int NumLevels = NumLevels_;
493 
495  typedef typename ValueCalculator::ValueType ValueType;
496 
498  typedef BinningAnalysisParams<ValueType,NumTrackValues,NumLevels,false/*StoreBinSums*/,CountIntType>
500 
514 
518 
519 };
520 
528 template<typename Params,
529  typename LoggerType_ = Logger::VacuumLogger
530  >
532  : public virtual Tools::NeedOwnOperatorNew<ValueHistogramMHRWStatsCollector<
533  typename Params::ValueCalculator,
534  LoggerType_,
535  typename Params::BaseHistogramType
536  >,
537  BinningAnalysis<typename Params::BinningAnalysisParamsType, LoggerType_>,
538  typename Params::Result
539  >::ProviderType
540 {
541 public:
542 
544  typedef typename Params::ValueCalculator ValueCalculator;
546  typedef typename Params::CountIntType CountIntType;
548  typedef typename Params::CountRealAvgType CountRealAvgType;
549 
551  typedef LoggerType_ LoggerType;
552 
554  typedef typename Params::BaseHistogramType BaseHistogramType;
556  typedef typename Params::HistogramParams HistogramParams;
557 
559  typedef typename Params::ValueType ValueType;
560 
562  typedef typename Params::BinningAnalysisParamsType BinningAnalysisParamsType;
565 
567  static constexpr int NumTrackValuesCTime = Params::NumTrackValues;
569  static constexpr int NumLevelsCTime = Params::NumLevels;
570 
572  typedef typename Params::Result ResultType;
573 
578  ValueCalculator,
579  LoggerType,
580  BaseHistogramType
582 
583 private:
584 
585  ValueHistogramMHRWStatsCollectorType value_histogram;
586 
587  BinningAnalysisType binning_analysis;
588 
589  LoggerType & logger;
590 
591  ResultType result;
592 
593 public:
594 
595  ValueHistogramWithBinningMHRWStatsCollector(HistogramParams histogram_params,
596  const ValueCalculator & vcalc,
597  int num_levels,
598  LoggerType & logger_)
599  : value_histogram(histogram_params, vcalc, logger_),
600  binning_analysis(histogram_params.num_bins, num_levels, logger_),
601  logger(logger_),
602  result(histogram_params, binning_analysis)
603  {
604  logger.longdebug("ValueHistogramWithBinningMHRWStatsCollector", "constructor()");
605  }
606 
608  inline const BaseHistogramType & histogram() const
609  {
610  return value_histogram.histogram();
611  }
612 
613  inline const BinningAnalysisType & getBinningAnalysis() const
614  {
615  return binning_analysis;
616  }
617 
624  inline const ResultType & getResult() const
625  {
626  return result;
627  }
628 
629  // stats collector part
630 
632  inline void init()
633  {
634  value_histogram.init();
635  }
637  inline void thermalizingDone()
638  {
639  value_histogram.thermalizingDone();
640  }
642  inline void done()
643  {
644  logger.longdebug("ValueHistogramWithBinningMHRWStatsCollector::done()", "finishing up ...");
645 
646  value_histogram.template done<false>();
647 
648  //
649  // Determine the error bars from the binning analysis. Remember, the binning analysis was
650  // applied to each of the indicator functions "chi(value) = (value in bin # i) ? 1 : 0"
651  //
652  // The total number of samples is simply h.bins.sum()+h.off_chart; this is the relevant
653  // coefficient to calculate the bin means needed by binning_analysis.calcErrorLevels(). Indeed,
654  // in this way we really get the averaged observed value of each indicator function for each
655  // value interval.
656  //
657  const BaseHistogramType & h = value_histogram.histogram();
658  result.hist.params = h.params;
659  CountRealAvgType numsamples = h.bins.sum() + h.off_chart;
660  result.hist.bins = h.bins.template cast<CountRealAvgType>() / numsamples;
661  result.error_levels = binning_analysis.calcErrorLevels(result.hist.bins);
662  result.hist.delta = result.error_levels.col(binning_analysis.numLevels()).template cast<CountRealAvgType>();
663  result.hist.off_chart = h.off_chart / numsamples;
664 
665  result.converged_status = binning_analysis.determineErrorConvergence(result.error_levels);
666 
667  logger.debug("ValueHistogramWithBinningMHRWStatsCollector", [&,this](std::ostream & str) {
668  str << "Binning analysis: bin sqmeans at different binning levels are:\n"
669  << binning_analysis.getBinSqmeans() << "\n"
670  << "\t-> so the error bars at different binning levels are:\n"
671  << result.error_levels << "\n"
672  << "\t-> convergence analysis: \n";
673  result.dumpConvergenceAnalysis(str);
674  str << "\t... and just for you, here is the final histogram:\n" << result.hist.prettyPrint() << "\n";
675  });
676  }
677 
679  template<typename CountIntType2, typename PointType, typename LLHValueType, typename MHRandomWalk>
680  inline void rawMove(CountIntType2 k, bool is_thermalizing, bool is_live_iter, bool accepted,
681  double a, const PointType & newpt, LLHValueType newptval,
682  const PointType & curpt, LLHValueType curptval, MHRandomWalk & mh)
683  {
684  value_histogram.rawMove(k, is_thermalizing, is_live_iter, accepted, a, newpt, newptval, curpt, curptval, mh);
685  }
686 
688  template<typename CountIntType2, typename PointType, typename LLHValueType, typename MHRandomWalk>
689  inline void processSample(CountIntType2 k, CountIntType2 n, const PointType & curpt,
690  LLHValueType curptval, MHRandomWalk & mh)
691  {
692  std::size_t histindex = value_histogram.processSample(k, n, curpt, curptval, mh);
693  binning_analysis.processNewValues(
695  histindex,
696  value_histogram.histogram().numBins()
697  )
698  );
699  }
700 
701 };
702 
703 
704 
705 
706 
707 
714 template<typename MHRWStatsCollector_>
716 {
717  typedef MHRWStatsCollector_ MHRWStatsCollector;
718 
719  static constexpr bool CanProvideStatus = false;
720 
725  static inline std::string getStatus(const MHRWStatsCollector * /*stats*/)
726  {
727  return std::string();
728  }
729 };
730 // static members:
731 template<typename MHRWStatsCollector_>
733 
734 
735 
739 template<typename... Args>
741 {
743 
744  static constexpr int NumStatColl = MHRWStatsCollector::NumStatColl;
745 
746  static constexpr bool CanProvideStatus = true;
747 
748  template<int I = 0, typename std::enable_if<(I < NumStatColl), bool>::type dummy = true>
749  static inline std::string getStatus(const MHRWStatsCollector * stats)
750  {
751  typedef typename std::tuple_element<I, typename MHRWStatsCollector::MHRWStatsCollectorsTupleType>::type
752  ThisStatsCollector;
753  return
755  ? (MHRWStatsCollectorStatus<ThisStatsCollector>::getStatus(& stats->template getStatsCollector<I>())
756  + ((I < (NumStatColl-1)) ? std::string("\n") : std::string()))
757  : std::string())
758  + getStatus<I+1>(stats);
759  };
760 
761  template<int I = 0, typename std::enable_if<(I == NumStatColl), bool>::type dummy = true>
762  static inline std::string getStatus(const MHRWStatsCollector * stats)
763  {
764  (void)stats;
765  return std::string();
766  }
767 
768 };
769 // static members:
770 template<typename... Args>
772 template<typename... Args>
773 constexpr bool MHRWStatsCollectorStatus<MultipleMHRWStatsCollectors<Args... > >::CanProvideStatus;
774 
775 
776 
780 template<typename ValueCalculator_,
781  typename LoggerType_,
782  typename HistogramType_
783  >
784 struct MHRWStatsCollectorStatus<ValueHistogramMHRWStatsCollector<ValueCalculator_, LoggerType_, HistogramType_> >
785 {
787 
788  static constexpr bool CanProvideStatus = true;
789 
790  static inline std::string getStatus(const MHRWStatsCollector * stats)
791  {
792  const int maxbarwidth = 50;
793 
794  typedef typename MHRWStatsCollector::HistogramType HistogramType;
795 
796  return "Histogram: " + histogramShortBar<HistogramType>(stats->histogram(), true, maxbarwidth);
797  }
798 };
799 // static members:
800 template<typename ValueCalculator_,
801  typename LoggerType_,
802  typename HistogramType_
803  >
804 constexpr bool
806 
807 
811 template<typename Params_,
812  typename LoggerType_
813  >
815 {
817 
818  static constexpr bool CanProvideStatus = true;
819 
820  static inline std::string getStatus(const MHRWStatsCollector * stats)
821  {
822  const int maxbarwidth = 50;
823 
824  typedef typename MHRWStatsCollector::BaseHistogramType BaseHistogramType;
825  const BaseHistogramType & histogram = stats->histogram();
826 
827  // calculate the error bars at different levels, to determine convergence status.
828  typedef typename MHRWStatsCollector::BinningAnalysisType BinningAnalysisType;
829  //typedef typename MHRWStatsCollector::CountRealAvgType CountRealAvgType;
830  typedef typename BinningAnalysisType::ValueType ValueType;
831  const auto& binning_analysis = stats->getBinningAnalysis();
832  Eigen::Array<ValueType, Eigen::Dynamic, 1> binmeans(histogram.numBins());
833  binmeans = histogram.bins.template cast<ValueType>() /
834  (ValueType)(histogram.bins.sum() + histogram.off_chart);
835 
836  auto error_levels = binning_analysis.calcErrorLevels(binmeans);
837  auto conv_status = binning_analysis.determineErrorConvergence(error_levels);
838 
839  int n_cnvg = 0;
840  int n_unknown = 0;
841  int n_not_cnvg = 0;
842  for (std::size_t k = 0; k < (std::size_t)histogram.numBins(); ++k) {
843  if (conv_status(k) == BinningAnalysisType::CONVERGED) {
844  ++n_cnvg;
845  } else if (conv_status(k) == BinningAnalysisType::NOT_CONVERGED) {
846  ++n_not_cnvg;
847  } else {
848  ++n_unknown;
849  }
850  }
851 
852  return tomo_internal::histogram_short_bar_fmt<BaseHistogramType>(histogram, "", maxbarwidth)
853  + Tools::fmts(" err: (cnvg/?/fail) %d/%d/%d", n_cnvg, n_unknown, n_not_cnvg);
854  }
855 };
856 // static members:
857 template<typename Params_,
858  typename LoggerType_
859  >
860 constexpr bool
862 
863 
864 } // namespace Tomographer
865 
866 
867 
868 #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
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: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:474
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.
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.