mjhajharia / transforms

2 stars 1 forks source link

ordered vector abs #48

Open spinkney opened 2 years ago

spinkney commented 2 years ago

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 commented 2 years ago

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.