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

ordered vector abs #48

Open
spinkney opened this issue Jul 27, 2022 · 1 comment
Open

ordered vector abs #48

spinkney opened this issue Jul 27, 2022 · 1 comment

Comments

@spinkney
Copy link
Collaborator

spinkney commented Jul 27, 2022

I'm finding that using the absolute value to increment is more stable than $\exp(\cdot)$. The jacobian adjustment
is constant.

I have to put a prior on x or else it's improper. When I compare to the built-in I notice the built-in has 1 or 2 divergences with a normal prior (N(0, 10)) and this one doesn't.

data {
 int<lower=0> N;
 vector<lower=0>[N] alpha;
}
parameters {
 vector[N] y;
}
transformed parameters {
 ordered[N] x ;

  x[1] = y[1];
  for(i in 2:N) {
    x[i] = x[i - 1] + abs(y[i]);
  }
}
model {
 target += target_density_lp(x, alpha);
}
@spinkney
Copy link
Collaborator Author

spinkney commented Jul 27, 2022

Why can't we just sort_asc on the unordered vector and then which ever density the user chooses will be ordered on that?

Because of the joint density of ordered statistics? Take $Z$ to be the vector of order statistics $X_{(1)}, \ldots, X_{(n)}$ then the joint density is

$$ f_{Z}(z) = n! \prod_{i = 1}^n f_{X}(z_i). $$

The Jacobian in this case is exactly the density chosen. We don't need to compute $n!$ unless the density is normalized _lpdf.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant