add multiplier keyword to unit vector
Mantenedores costumam responder em até 1 dia
@SteveBronder já está trabalhando nisso.
Desde 20/9/2024.
Avaliação
Esta issue ainda não foi avaliada.
Descrição
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
)
- Linguagem predominante
- C++
- Estrelas
- 845
- Forks
- 225
- Merge médio
- 4d 21h
- PRs com merge (30d)
- 13
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de stan-dev/math
-
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 54/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 54/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 35/100
Mantenedores costumam responder em até 1 dia
-
numerics performance
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 35/100
stan-dev/math#3481 · 1 reação ·
Mantenedores costumam responder em até 1 dia
-
`eigendecompose_sym`, `eigenvalues_sym` and `eigenvectors_sym` do not compile for complex matrices of `fvar<var>` or `fvar<fvar<double>>`Talvez livre de novo Um pull request para esta issue foi fechado sem ser mesclado. Abertabug
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 55/100
stan-dev/math#3477 · 5 comentários ·
Mantenedores costumam responder em até 1 dia
Todas as issues de stan-dev/math
Issues semelhantes
-
mlir
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
llvm/llvm-project#241070 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
Page request: clang-replAbertahelp wanted new command
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
tldr-pages/tldr#25111 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 88/100
Mantenedores costumam responder em até 1 dia
-
Ask the `ServerHelper` for fresh headers on every poll in `Future::get`, as is done for cookiesAbertaenhancement
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 77/100
NVIDIA/cuda-quantum#5886 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 66/100
Mantenedores costumam responder em até 1 dia