Stan  2.10.0
probability, sampling & optimization
print_progress.hpp
Go to the documentation of this file.
1 #ifndef STAN_SERVICES_VARIATIONAL_PRINT_PROGRESS_HPP
2 #define STAN_SERVICES_VARIATIONAL_PRINT_PROGRESS_HPP
3 
5 #include <stan/math/prim/scal/err/check_positive.hpp>
6 #include <stan/math/prim/scal/err/check_nonnegative.hpp>
8 #include <cmath>
9 #include <iomanip>
10 #include <iostream>
11 #include <string>
12 
13 namespace stan {
14  namespace services {
15  namespace variational {
16 
29  void print_progress(int m,
30  int start,
31  int finish,
32  int refresh,
33  bool tune,
34  const std::string& prefix,
35  const std::string& suffix,
37  static const char* function =
38  "stan::services::variational::print_progress";
39 
40  stan::math::check_positive(function,
41  "Total number of iterations",
42  m);
43  stan::math::check_nonnegative(function,
44  "Starting iteration",
45  start);
46  stan::math::check_positive(function,
47  "Final iteration",
48  finish);
49  stan::math::check_positive(function,
50  "Refresh rate",
51  refresh);
52 
53  int it_print_width = std::ceil(std::log10(static_cast<double>(finish)));
54  if (io::do_print(m - 1, (start + m == finish), refresh)) {
55  std::stringstream ss;
56  ss << prefix;
57  ss << "Iteration: ";
58  ss << std::setw(it_print_width) << m + start
59  << " / " << finish;
60  ss << " [" << std::setw(3)
61  << (100 * (start + m)) / finish
62  << "%] ";
63  ss << (tune ? " (Adaptation)" : " (Variational Inference)");
64  ss << suffix;
65  writer(ss.str());
66  }
67  }
68 
69  }
70  }
71 }
72 #endif
Probability, optimization and sampling library.
bool do_print(const int n, const bool special, const int refresh)
Indicates whether it should print on the current iteration.
Definition: do_print.hpp:25
base_writer is an abstract base class defining the interface for Stan writer callbacks.
Definition: base_writer.hpp:20
void print_progress(int m, int start, int finish, int refresh, bool tune, const std::string &prefix, const std::string &suffix, interface_callbacks::writer::base_writer &writer)
Helper function for printing progress for variational inference.

     [ Stan Home Page ] © 2011–2016, Stan Development Team.