Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add exponential simplex transform #2

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
vector exponential_simplex_constrain_lp(vector y) {
int N = rows(y);
vector[N] x_pos = y - log1p_exp(-y);
spinkney marked this conversation as resolved.
Show resolved Hide resolved
real r = log_sum_exp(x_pos);
vector[N] x = exp(x_pos - r);
target += x_pos;
target += std_normal_lpdf(r - log(N));
target += sum(y) - N * r;
return x;
spinkney marked this conversation as resolved.
Show resolved Hide resolved
}

vector exponential_log_simplex_constrain_lp(vector y) {
int N = rows(y);
vector[N] x = y - log1p_exp(-y);
real r = log_sum_exp(x);
vector[N] log_x = x - r;
target += x;
target += std_normal_lpdf(r - log(N));
target += log_x[N];
return log_x;
spinkney marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
parameters {
vector[N] y;
}
transformed parameters {
vector<upper=0>[N] log_x = exponential_log_simplex_constrain_lp(y);
simplex[N] x = exp(log_x);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters {
vector[N] y;
}
transformed parameters {
simplex[N] x = exponential_simplex_constrain_lp(y);
}
Loading