defaults.hpp
Go to the documentation of this file.
1 #ifndef STAN_SERVICES_OPTIMIZE_DEFAULTS_HPP
2 #define STAN_SERVICES_OPTIMIZE_DEFAULTS_HPP
3 
4 #include <stdexcept>
5 #include <string>
6 
7 namespace stan {
8  namespace services {
9  namespace optimize {
10 
11  /**
12  * Line search step size for first iteration.
13  */
14  struct init_alpha {
15  /**
16  * Return the string description of init_alpha.
17  *
18  * @return description
19  */
21  return "Line search step size for first iteration.";
22  }
23 
24  /**
25  * Validates init_alpha; init_alpha must be greater than 0.
26  *
27  * @param[in] init_alpha argument to validate
28  * @throw std::invalid_argument unless init_alpha is greater than zero
29  */
30  static void validate(double init_alpha) {
31  if (!(init_alpha > 0))
32  throw std::invalid_argument("init_alpha must be greater than 0.");
33  }
34 
35  /**
36  * Return the default init_alpha value.
37  *
38  * @return 0.001
39  */
40  static double default_value() {
41  return 0.001;
42  }
43  };
44 
45  /**
46  * Convergence tolerance on absolute changes in objective function value.
47  */
48  struct tol_obj {
49  /**
50  * Return the string description of tol_obj.
51  *
52  * @return description
53  */
55  return "Convergence tolerance on absolute changes in objective"
56  " function value.";
57  }
58 
59  /**
60  * Validates tol_obj; tol_obj must be greater than or equal to 0.
61  *
62  * @param[in] tol_obj argument to validate
63  * @throw std::invalid_argument unless tol_obj is greater than or equal
64  * to zero
65  */
66  static void validate(double tol_obj) {
67  if (!(tol_obj >= 0))
68  throw std::invalid_argument("tol_obj must be greater"
69  " than or equal to 0.");
70  }
71 
72  /**
73  * Return the default tol_obj value.
74  *
75  * @return 1e-12
76  */
77  static double default_value() {
78  return 1e-12;
79  }
80  };
81 
82  /**
83  * Convergence tolerance on relative changes in objective function value.
84  */
85  struct tol_rel_obj {
86  /**
87  * Return the string description of tol_rel_obj.
88  *
89  * @return description
90  */
92  return "Convergence tolerance on relative changes in"
93  " objective function value.";
94  }
95 
96  /**
97  * Validates tol_rel_obj; tol_rel_obj must be greater than or equal
98  * to 0.
99  *
100  * @param[in] tol_rel_obj argument to validate
101  * @throw std::invalid_argument unless tol_rel_obj is greater than or
102  * equal to zero
103  */
104  static void validate(double tol_rel_obj) {
105  if (!(tol_rel_obj >= 0))
106  throw std::invalid_argument("tol_rel_obj must be greater"
107  " than or equal to 0");
108  }
109 
110  /**
111  * Return the default tol_rel_obj value.
112  *
113  * @return 10000
114  */
115  static double default_value() {
116  return 10000;
117  }
118  };
119 
120  /**
121  * Convergence tolerance on the norm of the gradient.
122  */
123  struct tol_grad {
124  /**
125  * Return the string description of tol_grad.
126  *
127  * @return description
128  */
130  return "Convergence tolerance on the norm of the gradient.";
131  }
132 
133  /**
134  * Validates tol_grad; tol_grad must be greater than or equal to 0.
135  *
136  * @param[in] tol_grad argument to validate
137  * @throw std::invalid_argument unless tol_grad is greater than or
138  * equal to zero
139  */
140  static void validate(double tol_grad) {
141  if (!(tol_grad >= 0))
142  throw std::invalid_argument("tol_grad must be greater"
143  " than or equal to 0");
144  }
145 
146  /**
147  * Return the default tol_grad value.
148  *
149  * @return 1e-8
150  */
151  static double default_value() {
152  return 1e-8;
153  }
154  };
155 
156 
157  /**
158  * Convergence tolerance on the relative norm of the gradient.
159  */
160  struct tol_rel_grad {
161  /**
162  * Return the string description of tol_rel_grad.
163  *
164  * @return description
165  */
167  return "Convergence tolerance on the relative norm of the gradient.";
168  }
169 
170  /**
171  * Validates tol_rel_grad; tol_rel_grad must be greater than
172  * or equal to 0.
173  *
174  * @param[in] tol_rel_grad argument to validate
175  * @throw std::invalid_argument unless tol_rel_grad is greater than or
176  * equal to zero
177  */
178  static void validate(double tol_rel_grad) {
179  if (!(tol_rel_grad >= 0))
180  throw std::invalid_argument("tol_rel_grad must be greater"
181  " than or equal to 0.");
182  }
183 
184  /**
185  * Return the default tol_rel_grad value.
186  *
187  * @return 10000000
188  */
189  static double default_value() {
190  return 10000000;
191  }
192  };
193 
194  /**
195  * Convergence tolerance on changes in parameter value.
196  */
197  struct tol_param {
198  /**
199  * Return the string description of tol_param.
200  *
201  * @return description
202  */
204  return "Convergence tolerance on changes in parameter value.";
205  }
206 
207  /**
208  * Validates tol_param; tol_param must be greater than or equal to 0.
209  *
210  * @param[in] tol_param argument to validate
211  * @throw std::invalid_argument unless tol_param is greater than or
212  * equal to zero
213  */
214  static void validate(double tol_param) {
215  if (!(tol_param >= 0))
216  throw std::invalid_argument("tol_param");
217  }
218 
219  /**
220  * Return the default tol_param.
221  *
222  * @return 1e-08
223  */
224  static double default_value() {
225  return 1e-08;
226  }
227  };
228 
229  /**
230  * Amount of history to keep for L-BFGS.
231  */
232  struct history_size {
233  /**
234  * Return the string description of history_size.
235  *
236  * @return description
237  */
239  return "Amount of history to keep for L-BFGS.";
240  }
241 
242  /**
243  * Validates history_size; history_size must be greater than 0.
244  *
245  * @param[in] history_size argument to validate
246  * @throw std::invalid_argument unless history_size is greater than
247  * zero
248  */
249  static void validate(int history_size) {
250  if (!(history_size > 0))
251  throw std::invalid_argument("history_size must be greater than 0.");
252  }
253 
254  /**
255  * Return the default history_size value.
256  *
257  * @return 5
258  */
259  static int default_value() {
260  return 5;
261  }
262  };
263 
264  /**
265  * Total number of iterations.
266  */
267  struct iter {
268  /**
269  * Return the string description of iter.
270  *
271  * @return description
272  */
274  return "Total number of iterations.";
275  }
276 
277  /**
278  * Validates iter; iter must be greater than 0.
279  *
280  * @param[in] iter argument to validate
281  * @throw std::invalid_argument unless iter is greater than zero
282  */
283  static void validate(int iter) {
284  if (!(iter > 0))
285  throw std::invalid_argument("iter must be greater than 0.");
286  }
287 
288  /**
289  * Return the default iter value.
290  *
291  * @return 2000
292  */
293  static int default_value() {
294  return 2000;
295  }
296  };
297 
298  /**
299  * Save optimization interations to output.
300  */
302  /**
303  * Return the string description of save_iterations.
304  *
305  * @return description
306  */
308  return "Save optimization interations to output.";
309  }
310 
311  /**
312  * Validates save_iterations. This is a no-op.
313  *
314  * @param[in] save_iterations argument to validate
315  */
316  static void validate(bool save_iterations) {
317  }
318 
319  /**
320  * Return the default save_iterations value.
321  *
322  * @return false
323  */
324  static bool default_value() {
325  return false;
326  }
327  };
328 
329  }
330  }
331 }
332 #endif
static void validate(double tol_param)
Definition: defaults.hpp:214
static std::string description()
Definition: defaults.hpp:203
static void validate(double tol_grad)
Definition: defaults.hpp:140
static void validate(bool save_iterations)
Definition: defaults.hpp:316
static void validate(double init_alpha)
Definition: defaults.hpp:30
static std::string description()
Definition: defaults.hpp:54
static std::string description()
Definition: defaults.hpp:20
static void validate(int iter)
Definition: defaults.hpp:283
static void validate(double tol_rel_obj)
Definition: defaults.hpp:104
static std::string description()
Definition: defaults.hpp:91
static void validate(double tol_obj)
Definition: defaults.hpp:66
void invalid_argument(const char *function, const char *name, const T &y, const char *msg1, const char *msg2)
static void validate(int history_size)
Definition: defaults.hpp:249
static std::string description()
Definition: defaults.hpp:129
Float_t e
Definition: plot.C:35
static void validate(double tol_rel_grad)
Definition: defaults.hpp:178
static std::string description()
Definition: defaults.hpp:273
enum BeamMode string