Skip to content

Commit 190a7c3

Browse files
authored
Merge pull request #786 from stan-dev/transforms-and-finite-accuracy
add warning that inverse transforms may fail due to finite accuracy
2 parents 3a69742 + 6fb335c commit 190a7c3

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/reference-manual/transforms.qmd

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,33 @@ parameters defined in the program. The C++ classes also include
2525
code to transform the parameters from unconstrained to constrained and
2626
apply the appropriate Jacobians.
2727

28+
## Limitations due to finite accuracy presentation
29+
30+
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).
2855

2956
## Changes of variables {#change-of-variables.section}
3057

0 commit comments

Comments
 (0)