# Positive_ordered with a minimal separation

I’m trying to create a positive_ordered vector where all components are at least \alpha from each other, such that it plays nicely with NUTS (i.e. it needs to be continuous). Could anyone suggest a way to elegantly do this preferably in a vectorised form?

An example solution:

parameters {
real<lower=0> p1;
real<lower=p1+alpha> p2;
real<lower=p2+alpha> p3;
}

1 Like

Hey! Idk if this is particularly elegant or even efficient, but this would be my attempt:

transformed data{
int N = 10;
real alpha = 0.5;
}
parameters {
vector[N] p_raw;
}
transformed parameters{
vector[N] p = cumulative_sum(exp(p_raw));
p[2:N] += alpha;
}
model {
p_raw ~ std_normal();
}



Does this do the trick?

2 Likes

Hmmm. Say we pass c=(0,alpha,alpha) as data. Then I guess an equivalent to your solution would be:

parameters {
positive_ordered v0;
}
transformed parameters {
vector v = v0+c;
}


Thinking about it; it seems to do everything I asked for, doesn’t it? It’s elegant and it spans the whole space. Thanks @max_mantei!

1 Like

Good point! Well, but v would have to be a vector, not real, right?

Yes absolutely ; was typing on my phone :-)

1 Like

Edited.

1 Like

Careful there, if c=(0,alpha,alpha) then it needs to be v0+cumulative_sum(c). Adding alpha to both v and v doesn’t separate them.

2 Likes

Serves me right for answering on my phone :-) you’re absolutely right. I guess most importantly c is an additive constant and v is just ordered positive so the solution should both be continuous and span the whole space of possible solutions.