add multiplier keyword to unit vector
Maintainer thường phản hồi trong vòng 1 ngày
@SteveBronder đang làm issue này rồi.
Từ ngày 20/9/2024.
Đánh giá
Issue này chưa được đánh giá.
Mô tả
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
)
- Ngôn ngữ chính
- C++
- Star
- 845
- Fork
- 225
- Merge trung bình
- 3 ngày 9 giờ
- Pull request đã merge (30 ngày)
- 12
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của stan-dev/math
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 54/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 54/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
Maintainer thường phản hồi trong vòng 1 ngày
-
numerics performance
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
stan-dev/math#3481 · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
`eigendecompose_sym`, `eigenvalues_sym` and `eigenvectors_sym` do not compile for complex matrices of `fvar<var>` or `fvar<fvar<double>>`Có thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mởbug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 55/100
stan-dev/math#3477 · 5 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của stan-dev/math
Issue tương tự
-
Upstream changes to reviewĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
rhalbersma/xstd-ints#395 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug] Root filesystem scope (/) incorrectly rejects all descendant pathsCó thể đã có người làm @mugenkyou đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
neutralinojs/neutralino.js#304 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
FuSa
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
tenstorrent/tt-umd#3851 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
zq prints a raw SQL 'no such table: index_default' error when the index has no default indexĐang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
mattgodbolt/zindex#67 ·
Maintainer thường phản hồi trong vòng 1 ngày