Stan  2.14.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.hpp>
7 #include <cmath>
8 #include <iomanip>
9 #include <iostream>
10 #include <string>
11 
12 namespace stan {
13  namespace services {
14  namespace variational {
15 
28  void print_progress(int m,
29  int start,
30  int finish,
31  int refresh,
32  bool tune,
33  const std::string& prefix,
34  const std::string& suffix,
36  static const char* function =
37  "stan::services::variational::print_progress";
38 
39  stan::math::check_positive(function,
40  "Total number of iterations",
41  m);
42  stan::math::check_nonnegative(function,
43  "Starting iteration",
44  start);
45  stan::math::check_positive(function,
46  "Final iteration",
47  finish);
48  stan::math::check_positive(function,
49  "Refresh rate",
50  refresh);
51 
52  int it_print_width = std::ceil(std::log10(static_cast<double>(finish)));
53  if (io::do_print(m - 1, (start + m == finish), refresh)) {
54  std::stringstream ss;
55  ss << prefix;
56  ss << "Iteration: ";
57  ss << std::setw(it_print_width) << m + start
58  << " / " << finish;
59  ss << " [" << std::setw(3)
60  << (100 * (start + m)) / finish
61  << "%] ";
62  ss << (tune ? " (Adaptation)" : " (Variational Inference)");
63  ss << suffix;
64  writer(ss.str());
65  }
66  }
67 
68  }
69  }
70 }
71 #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.