Skip to content

Commit 7b49bfc

Browse files
committed
Take defaults and checks from #25
1 parent 91ccd28 commit 7b49bfc

File tree

1 file changed

+36
-21
lines changed

1 file changed

+36
-21
lines changed

examples/stan_cli.cpp

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <chrono>
1010
#include <cmath>
1111
#include <iostream>
12+
#include <limits>
1213
#include <random>
1314
#include <string>
1415
#include <vector>
@@ -176,19 +177,19 @@ Vector initialize(DynamicStanModel& model, RNG& rng, double init_range,
176177
int main(int argc, char** argv) {
177178
srand(std::chrono::system_clock::now().time_since_epoch().count());
178179
unsigned int seed = rand();
179-
int64_t warmup = 1000;
180-
int64_t samples = 1000;
180+
int64_t warmup = 128;
181+
int64_t samples = 128;
181182
int64_t max_nuts_depth = 10;
182183
int64_t max_step_depth = 8;
183184
double max_error = 0.5;
184185
double init = 2.0;
185186
double init_count = 1.1;
186187
double mass_iteration_offset = 1.1;
187-
double additive_smoothing = 0.1;
188-
double step_size_init = 0.5;
189-
double accept_rate_target = 2.0 / 3.0;
190-
double step_iteration_offset = 2.0;
191-
double learning_rate = 0.95;
188+
double additive_smoothing = 1e-5;
189+
double step_size_init = 1.0;
190+
double accept_rate_target = 0.8;
191+
double step_iteration_offset = 5.0;
192+
double learning_rate = 1.5;
192193
double decay_rate = 0.05;
193194

194195
std::string lib;
@@ -202,58 +203,72 @@ int main(int argc, char** argv) {
202203
app.add_option("--seed", seed, "Random seed")->default_val(seed);
203204

204205
app.add_option("--warmup", warmup, "Number of warmup iterations")
205-
->default_val(warmup);
206+
->default_val(warmup)
207+
->check(CLI::NonNegativeNumber);
206208

207209
app.add_option("--samples", samples, "Number of samples to draw")
208-
->default_val(samples);
210+
->default_val(samples)
211+
->check(CLI::PositiveNumber);
209212

210213
app.add_option("--max-depth", max_nuts_depth,
211214
"Maximum depth for NUTS trajectory doublings")
212-
->default_val(max_nuts_depth);
215+
->default_val(max_nuts_depth)
216+
->check(CLI::PositiveNumber);
213217

214218
app.add_option("--max-step-depth", max_step_depth,
215219
"Maximum depth for the step size adaptation")
216-
->default_val(max_step_depth);
220+
->default_val(max_step_depth)
221+
->check(CLI::PositiveNumber);
217222

218223
app.add_option("--max-error", max_error,
219224
"Maximum error allowed in joint densities")
220-
->default_val(max_error);
225+
->default_val(max_error)
226+
->check(CLI::PositiveNumber);
221227

222228
app.add_option("--init", init,
223229
"Range [-init,init] for the parameters initial values")
224-
->default_val(init);
230+
->default_val(init)
231+
->check(CLI::NonNegativeNumber);
225232

226233
app.add_option("--mass-init-count", init_count,
227234
"Initial count for the mass matrix adaptation")
228-
->default_val(init_count);
235+
->default_val(init_count)
236+
->check(CLI::Range(1.0, std::numeric_limits<double>::max()));
229237

230238
app.add_option("--mass-iteration-offset", mass_iteration_offset,
231239
"Offset for the mass matrix adaptation iterations")
232-
->default_val(mass_iteration_offset);
240+
->default_val(mass_iteration_offset)
241+
->check(CLI::Range(1.0, std::numeric_limits<double>::max()));
233242

234243
app.add_option("--mass-additive-smoothing", additive_smoothing,
235244
"Additive smoothing for the mass matrix adaptation")
236-
->default_val(additive_smoothing);
245+
->default_val(additive_smoothing)
246+
->check(CLI::PositiveNumber);
237247

238248
app.add_option("--step-size-init", step_size_init,
239249
"Initial step size for the step size adaptation")
240-
->default_val(step_size_init);
250+
->default_val(step_size_init)
251+
->check(CLI::PositiveNumber);
241252

242253
app.add_option("--step-accept-rate-target", accept_rate_target,
243254
"Target acceptance rate for the step size adaptation")
244-
->default_val(accept_rate_target);
255+
->default_val(accept_rate_target)
256+
->check(CLI::Range(std::numeric_limits<double>::min(), 1.0));
245257

246258
app.add_option("--step-iteration-offset", step_iteration_offset,
247259
"Offset for the step size adaptation iterations")
248-
->default_val(step_iteration_offset);
260+
->default_val(step_iteration_offset)
261+
->check(CLI::Range(1.0, std::numeric_limits<double>::max()));
249262

250263
app.add_option("--step-learning-rate", learning_rate,
251264
"Learning rate for the step size adaptation")
252-
->default_val(learning_rate);
265+
->default_val(learning_rate)
266+
->check(CLI::PositiveNumber);
253267

254268
app.add_option("--step-decay-rate", decay_rate,
255269
"Decay rate for the step size adaptation")
256-
->default_val(decay_rate);
270+
->default_val(decay_rate)
271+
->check(CLI::PositiveNumber);
257272

258273
app.add_option("model", lib, "Path to the Stan model library")
259274
->required()

0 commit comments

Comments
 (0)