You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Create `PosteriorSample` object for downstream analysis.
57
+
58
+
44
59
## CmdStanPy API
45
60
46
61
The CmdStanPy interface is implemented as a Python package
47
-
with the following classes and functions.
62
+
with the following functions and classes.
63
+
64
+
## Functions
65
+
66
+
### compile_file
67
+
68
+
Compile Stan model, returning immutable instance of a compiled model.
69
+
This is done in two steps:
70
+
71
+
* call the `stanc` compiler which translates the Stan program to c++
72
+
* call c++ to compile and link the generated c++ code
73
+
74
+
The `compile_file` function must allow the user to specify
75
+
default settings to the c++ compiler and ways to override those setting.
76
+
77
+
```
78
+
model = compile_file(path = None,
79
+
optimization_flag = 3,
80
+
...)
81
+
```
82
+
83
+
In case of compilation failure, this function returns `None`
84
+
and the `compile_file` function reports the compiler error messages.
85
+
86
+
87
+
#### parameters
88
+
89
+
*`path` = - string, must be valid pathname to Stan program file
90
+
*`optimization_flag` = optimization level, the value of the `-o` flag for the c++ compiler, default value is `3`
91
+
* additional flags for the c++ compiler
92
+
93
+
94
+
### sample (using HMC/NUTS)
95
+
96
+
Condition the model on the data using HMC/NUTS with diagonal metric: `stan::services::sample::hmc_nuts_diag_e_adapt`
97
+
and run one or more chains, producing a set of samples from the posterior.
98
+
Returns a `RunSet` object which contains information on all runs for all chains.
99
+
100
+
```
101
+
RunSet = sample(model,
102
+
chains = 4,
103
+
cores = 1,
104
+
seed = None,
105
+
data_file = None,
106
+
init_param_values = None,
107
+
csv_output_file = None,
108
+
console_output_file = None,
109
+
refresh = None,
110
+
post_warmup_draws_per_chain = None,
111
+
warmup_draws_per_chain = None,
112
+
save_warmup = False,
113
+
thin = None,
114
+
do_adaptation = True,
115
+
adapt_gamma = None,
116
+
adapt_delta = None,
117
+
adapt_kappa = None,
118
+
adapt_t0 = None,
119
+
nuts_max_depth = None,
120
+
hmc_metric_file = None,
121
+
hmc_stepsize = None)
122
+
```
123
+
The `model` and `output_file` parameter are required, all other parameters are optional.
124
+
125
+
The `sample` command runs one or more sampler chains (argument `num_chains`), in parallel or sequentially.
126
+
The `num_cores` argument specifies the maximum number of processes which can be run in parallel.
127
+
128
+
#### parameters
129
+
130
+
*`model` - required - CmdStanPy model object
131
+
*`num_chains` - positive integer, default 4
132
+
*`num_cores` - positive integer, default 1
133
+
*`seed` - integer - random seed
134
+
*`data_file` - string - full pathname of input data file in JSON or Rdump format
135
+
*`init_param_values` - string - full pathname of file of initial values for some or all parameters in JSON or Rdump format
136
+
*`csv_output_file` - string - full pathname of the sampler output file, in stan-csv format, , each chain's output is written to its own file '<csv-output>-<chain_id>.csv'
137
+
*`console_output_file` - string - full pathname of file of sampler messages to stdout and/or stderr, each chain's output is written to its own file '<console-output>-<chain_id>.txt'
138
+
*`refresh` - integer - the number of iterations between progress message updates. When `refresh = -1`, the progress message is suppressed but not warning messages.
139
+
*`post_warmup_draws_per_chain` non-negative integer - number of post-warmup draws for each chain
140
+
*`warmup_draws_per_chain` non-negative integer - number of warmup draws for each chain
141
+
*`save_warmup` - boolean, default False - whether or not warmup draws are written to output file
142
+
*`thin` - non-negative integer - period between saved draws
143
+
*`nuts_max_treedepth` - integer - NUTS maximum tree depth
144
+
*`do_adaptation` - boolean, default True - whether or not NUTS algorithm updates sampler stepsize and metric during warmup, True implies num warmup draws > 0
0 commit comments