Skip to content

Commit

Permalink
add transform
Browse files Browse the repository at this point in the history
  • Loading branch information
spinkney committed Aug 10, 2024
1 parent ccf7a35 commit db03eca
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
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);
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;
}

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;
}
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);
}

0 comments on commit db03eca

Please sign in to comment.