Skip to content

Commit c360c60

Browse files
Merge pull request #862 from stan-dev/sig-figs-changes
Update docs for new sig_figs default in CmdStan
2 parents fcb676a + 9bbd75d commit c360c60

9 files changed

Lines changed: 30 additions & 47 deletions

src/cmdstan-guide/command_line_options.qmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ The keyword value pair `sig_figs=<int>` specifies the
7979
number of significant digits for all numerical values in the output files.
8080
Allowable values are between 1 and 18, which is the maximum amount of precision
8181
available for 64-bit floating point arithmetic.
82-
The default value is 6. &nbsp;
82+
The default value is 8. &nbsp;
8383
***Note:*** increasing `sig_figs` above the default will increase the size of
8484
the output CSV files accordingly.
8585

src/cmdstan-guide/laplace_sample_config.qmd

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,6 @@ In comparison, running the NUTS-HMC sampler results in mean 2.6 and standard dev
9393
The header and first few data rows of the output sample are shown below.
9494

9595
```
96-
# stan_version_major = 2
97-
# stan_version_minor = 35
98-
# stan_version_patch = 0
99-
# model = bernoulli_model
100-
# start_datetime = 2022-12-20 01:01:14 UTC
10196
# method = laplace
10297
# laplace
10398
# mode = bernoulli_lbfgs.csv
@@ -114,11 +109,9 @@ The header and first few data rows of the output sample are shown below.
114109
# file = output.csv (Default)
115110
# diagnostic_file = (Default)
116111
# refresh = 100 (Default)
117-
# sig_figs = -1 (Default)
112+
# sig_figs = 8 (Default)
118113
# profile_file = profile.csv (Default)
119114
# num_threads = 1 (Default)
120-
# stanc_version = stanc3 v2.31.0-7-g20444266
121-
# stancflags =
122115
log_p__,log_q__,theta
123116
-9.4562,-2.33997,0.0498545
124117
-6.9144,-0.0117349,0.182898

src/cmdstan-guide/log_prob_config.qmd

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,6 @@ This yields
7272

7373

7474
```
75-
# stan_version_major = 2
76-
# stan_version_minor = 31
77-
# stan_version_patch = 0
78-
# model = bernoulli_model
79-
# start_datetime = 2022-11-17 20:46:06 UTC
8075
# method = log_prob
8176
# log_prob
8277
# unconstrained_params = (Default)
@@ -92,11 +87,9 @@ This yields
9287
# file = output.csv (Default)
9388
# diagnostic_file = (Default)
9489
# refresh = 100 (Default)
95-
# sig_figs = -1 (Default)
90+
# sig_figs = 8 (Default)
9691
# profile_file = profile.csv (Default)
9792
# num_threads = 1 (Default)
98-
# stanc_version = stanc3 2.31.0 (Linux)
99-
# stancflags =
10093
lp_,theta
10194
-7.856,1.8
10295
```

src/cmdstan-guide/optimize_config.qmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ output
5858
file = output.csv (Default)
5959
diagnostic_file = (Default)
6060
refresh = 100 (Default)
61-
sig_figs = -1 (Default)
61+
sig_figs = 8 (Default)
6262
profile_file = profile.csv (Default)
6363
save_cmdstan_config = false (Default)
6464
num_threads = 1 (Default)

src/cmdstan-guide/pathfinder_config.qmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ output
6262
file = output.csv (Default)
6363
diagnostic_file = (Default)
6464
refresh = 100 (Default)
65-
sig_figs = -1 (Default)
65+
sig_figs = 8 (Default)
6666
profile_file = profile.csv (Default)
6767
save_cmdstan_config = false (Default)
6868
num_threads = 1 (Default)

src/cmdstan-guide/stan_csv_apdx.qmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ however, possible values include both positive and negative
1414
infinity and "Not-a-Number" which are represented as
1515
the strings `NaN`, `inf`, `+inf`, `-inf`.
1616
All other values are written in decimal notation by default with
17-
at most 6 digits of precision. The number of significant digits
18-
written can be controlled with argument `sig_figs=<int>`. See more
17+
at most 8 digits of precision. The number of significant digits
18+
written can be controlled with argument `sig_figs=<int>`. See more
1919
in [Output control arguments section](command_line_options.qmd#output-control.section).
2020

2121
Stan CSV files have a header row containing the column names.

src/cmdstan-guide/stansummary.qmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,5 +186,5 @@ results in no percentiles being displayed in the output of the command.
186186
The amount of precision
187187
in the sampler output limits the amount of real precision in the summary report.
188188
CmdStan's command line interface also has output argument `sig_figs`.
189-
The default sampler output precision is 6.
189+
The default sampler output precision is 8.
190190
The `--sig_figs` argument to the stansummary program should not exceed the `sig_figs` argument to the sampler.

src/cmdstan-guide/variational_config.qmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ output
6666
file = output.csv (Default)
6767
diagnostic_file = (Default)
6868
refresh = 100 (Default)
69-
sig_figs = -1 (Default)
69+
sig_figs = 8 (Default)
7070
profile_file = profile.csv (Default)
7171
save_cmdstan_config = false (Default)
7272
num_threads = 1 (Default)

src/reference-manual/transforms.qmd

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,30 +28,27 @@ apply the appropriate Jacobians.
2828
## Limitations due to finite accuracy presentation
2929

3030
In this section the transformations are described mathematically.
31-
There are two cases where the observed behavior can be different from
32-
the exact arithmetic:
33-
- Stan’s arithmetic is implemented using double-precision
34-
floating-point arithmetic, which may cause computation to behave
35-
differently than mathematics. For example, lower bound constraint
36-
is defined with logarithm constraint which mathematically excludes
37-
the lower bound, but if the closest floating-point number for the
38-
inverse transformed value is the boundary, then the value is
39-
rounded to the boundary. This may cause unexpected warnings or
40-
errors, if in other parts of the code the boundary value is
41-
invalid. For example, we may observe floating-point value 0 for
42-
a variance parameter that has been declared to be larger than 0.
43-
See more about [Floating point Arithmetic in Stan user's guide](../stan-users-guide/floating-point.qmd)).
44-
- CmdStan stores the output to CSV files with 6 significant digits
45-
accuracy by default, but the constraints are checked with 8
46-
decimal digit accuracy. Due to this, there can be errors if CSV
47-
output is further used, for example, to run generated
48-
quantities. For example, simplex constraint requires the values to
49-
sum up to 1, but when writing the values to CSV they are rounded
50-
to 6 significant digits and the sum of those rounded values can be
51-
smaller or larger than 1 by more than 8 decimal digits. The
52-
solution for CmdStan is to increase the number of significant
53-
digits stored as discussed in [CmdStan Command-Line Interface
54-
Overview](../cmdstan-guide/command_line_options.qmd).
31+
However, observed behavior can be different from the exact arithmetic.
32+
33+
Stan’s arithmetic is implemented using double-precision
34+
floating-point numbers, which may cause computation to behave
35+
differently than mathematics. For example, the lower bound constraint
36+
is defined above by an exponential inverse transform which mathematically excludes
37+
the lower bound, but if the closest floating-point number for the
38+
inverse transformed value is the boundary, then the value is
39+
rounded to the boundary. This may cause unexpected warnings or
40+
errors, if in other parts of the code the boundary value is
41+
invalid. For example, we may observe floating-point value 0 for
42+
a variance parameter that has been declared with `lower=0`.
43+
In general, double-precision floating-point numbers cannot reliably store
44+
more than 16 digits of a number in decimal.
45+
See more about [floating point arithmetic](../stan-users-guide/floating-point.qmd)
46+
in the *Stan User's Guide*.
47+
48+
These issues are exacerbated by the fact that CmdStan stores the output to
49+
CSV files with 8 digits precision by default. More digits can be requested by the user
50+
at the cost of additional disk usage, as discussed in the
51+
[CmdStan Command-Line Interface Overview](../cmdstan-guide/command_line_options.qmd).
5552

5653
## Changes of variables {#change-of-variables.section}
5754

0 commit comments

Comments
 (0)