Skip to content

Commit

Permalink
设置 cores = 1 取消并行计算 loo 值以去掉警告
Browse files Browse the repository at this point in the history
  • Loading branch information
XiangyunHuang committed Dec 10, 2023
1 parent 6477810 commit 9a5683e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions probabilistic-reasoning-framework.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ fit_gaussian$summary(.num_args = list(sigfig = 4, notation = "dec"))
变量的声明没有太多的内涵,就是 C++ 和 Stan 定义的语法,比如整型用 `int` 声明。建模过程中,时常需要将 R 语言环境中的数据传递给 Stan 代码编译出来的模型,而 Stan 是基于 C++ 语言,在变量类型方面有继承有发展。下表给出 Stan 与 R 语言中的变量类型对应关系。值得注意, R 语言的类型检查是不严格的,使用变量也不需要提前声明和初始化。Stan 语言中向量、矩阵的类型都是实数,下标也从 1 开始,元组类型和 R 语言中的列表类似,所有向量默认都是列向量。

| 类型 | Stan 语言 | R 语言 |
|---------------|----------------------|-----------------------------------|
|------|---------------------------------|-------------------------------------------------|
| 整型 | `int x = 1;` | `x = 1L` |
| 实数 | `real x = 3.14;` | `x = 3.14` |
| 向量 | `vector[3] x = [1, 2, 3]';` | `x = c(1L, 2L, 3L)` |
Expand Down Expand Up @@ -440,10 +440,10 @@ fit_logit_lasso$summary(c("alpha", "beta", "lambda", "lp__"))
计算 LOO-CV 比较正态先验和 Lasso 先验

```{r}
fit_logit_normal_loo <- fit_logit_normal$loo(variables = "log_lik", cores = 2)
fit_logit_normal_loo <- fit_logit_normal$loo(variables = "log_lik", cores = 1)
print(fit_logit_normal_loo)
fit_logit_lasso_loo <- fit_logit_lasso$loo(variables = "log_lik", cores = 2)
fit_logit_lasso_loo <- fit_logit_lasso$loo(variables = "log_lik", cores = 1)
print(fit_logit_lasso_loo)
```

Expand Down Expand Up @@ -500,7 +500,7 @@ fit_logit_horseshoe$summary(c("alpha", "beta", "tau", "lambda", "lp__"))
可以看到回归系数小的压缩效果很明显,而回归系数大的几乎没有压缩。

```{r}
fit_logit_horseshoe_loo <- fit_logit_horseshoe$loo(variables = "log_lik", cores = 2)
fit_logit_horseshoe_loo <- fit_logit_horseshoe$loo(variables = "log_lik", cores = 1)
print(fit_logit_horseshoe_loo)
```

Expand Down

1 comment on commit 9a5683e

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.