add multiplier keyword to unit vector
维护者通常 1 天内回复
@SteveBronder 已经在做这个了。
开始于 2024年9月20日。
评估
这个 Issue 还没有评估数据。
描述
In https://discourse.mc-stan.org/t/a-better-unit-vector/26989/30 Seth Axen lays out the reasoning for adding an additional parameter which repels values away from 0.
The current implementation is equivalent to
data {
int<lower=0> N;
}
parameters {
vector[N] u_raw;
}
transformed parameters {
real r = dot_self(u_raw);
vector[N] u = u_raw / sqrt(r);
}
model {
target += -0.5 * r;
}
The proposal is to parameterize the unit vector as
data {
int<lower=0> N;
}
parameters {
vector[N] u_raw;
}
transformed parameters {
real r = dot_self(u_raw);
vector[N] u = u_raw / sqrt(r);
}
model {
target += 0.5 * (a * log(r) - r);
}
where a >= 0 and is given as a multiplier keyword. As Seth notes in the post, it corresponds to the chi distribution with a + 1 degrees of freedom. The user would see:
unit_vector<multiplier=a>[N] u;
Setting a = 0 is equivalent to what is currently in Stan and will still be the default when the multiplier keyword is not used.
How to select a?
From the same thread the issue manifests with smaller dimension sizes of the unit vector. Heuristically, I'm finding that setting a = N^(6/N) where N is the dimension of the unit-vector works well.
N a
[1,] 1 1.000000
[2,] 2 8.000000
[3,] 3 9.000000
[4,] 4 8.000000
[5,] 5 6.898648
[6,] 6 6.000000
[7,] 7 5.301146
[8,] 8 4.756828
[9,] 9 4.326749
[10,] 10 3.981072
Here's a test model for 2d unit vectors where divergences occur in the current parameterization. When the data size, M, is small there are fewer divergences then when it's larger (M > 50).
data {
int<lower=0> M;
vector<lower=-pi(), upper=pi()>[M] y;
real a;
}
parameters {
vector[2] u_raw;
real<lower=0> kappa;
}
transformed parameters {
real r = dot_self(u_raw);
vector[2] u = u_raw / sqrt(r);
real mu = atan2(u[2], u[1]);
}
model {
target += 0.5 * (a * log(r) - r);
kappa ~ exponential(1);
y ~ von_mises(mu, kappa);
}
The data for this can be created as
M <- 100
y <- runif(M, min = -pi/4, max = pi/4)
true_mean <- 0
mod_unit <- cmdstan_model("unit.stan")
mod_unit_out <- mod_unit$sample(
data = list(M = M,
y = y,
a = 2^(6/2),
seed = 2309423,
parallel_chains = 4
)
- 主要语言
- C++
- 星标
- 845
- 派生
- 225
- 平均合并
- 3 天 9 小时
- 30 天内合并 PR
- 12
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
stan-dev/math 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 54/100
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 54/100
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 35/100
维护者通常 1 天内回复
-
numerics performance
难度 5/5 一周以上 新手友好度 35/100
stan-dev/math#3481 · 1 个 reaction ·
维护者通常 1 天内回复
-
`eigendecompose_sym`, `eigenvalues_sym` and `eigenvectors_sym` do not compile for complex matrices of `fvar<var>` or `fvar<fvar<double>>`可能重新可做 关联的 PR 已关闭且未合并。 未关闭bug
难度 3/5 1-2 天 新手友好度 55/100
维护者通常 1 天内回复
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 72/100
rhalbersma/xstd-ints#395 ·
维护者通常 1 天内回复
-
[Bug] Root filesystem scope (/) incorrectly rejects all descendant paths可能已有人在做 @mugenkyou 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
neutralinojs/neutralino.js#304 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
FuSa
难度 2/5 1-3 小时 新手友好度 76/100
tenstorrent/tt-umd#3851 ·
维护者通常 3 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 73/100
mattgodbolt/zindex#67 ·
维护者通常 1 天内回复