-
Notifications
You must be signed in to change notification settings - Fork 0
/
lesson5.Rmd
62 lines (48 loc) · 1.39 KB
/
lesson5.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
---
title: "Lesson 5"
output: html_document
---
## Brms internals
Core brms abstraction: one row of data -> one target increment
```{r, include=FALSE}
library(brms)
df <- data.frame(y = rnorm(100), x = rnorm(100), g = sample(LETTERS[1:3], size = 100, replace = TRUE))
```
```
make_stancode(y ~ x, df)
```
```{r, results = "asis", echo=FALSE}
cat("```stan\n")
cat(make_stancode(y ~ x, df))
cat("```")
```
```
make_stancode(y ~ x + (1 | g), df)
```
```{r, results = "asis", echo=FALSE}
cat("```stan\n")
cat(make_stancode(y ~ x + (1 | g), df))
cat("```")
```
```
make_stancode(y ~ x + (1 | g), df)
```
```{r, results = "asis", echo=FALSE}
cat("```stan\n")
cat(make_stancode(y ~ (1 + x | g), df))
cat("```")
```
Stanvars!
## Basics of numerical mathematics
- [IEEE 754 Floating point](https://en.wikipedia.org/wiki/IEEE_754)
- The worst possible way to represent reals (except all the others we tried)
- Sign, exponent, Mantissa
- Special values: +/-Inf, NaN
- Signed zero
$x = y \centernot\implies \frac{1}{x} = \frac{1}{y}$
- [Subnormal/Denormals](https://en.wikipedia.org/wiki/Subnormal_number)
- The subnormal floats are a linearly spaced set of values, which span the gap between the negative and positive normal floats.
- Small value + large value -> lost precision
- Much more precision around 0 than around 1
- Special functions
- `log1p`, `log1p_exp`, `log_sum_exp`, `log_diff_exp`