Add lower and upper bounds to ordered vector
Open
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 839
- Forks
- 220
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 14
Description
The proposal is to have the following
ordered<lower = a>[N] x1;
ordered<upper = b>[N] x2;
ordered<lower = a, upper = b>[N] x3;
For scalar a, b this is straightforward. When a, b are vectors they have to be ordered vectors themselves. In the case of having both a lb and ub then each element of a must be less than each element of b.
Here is Stan code for the scalar case
vector ordered_lb_lp (vector y, real lb) {
int N = rows(y);
vector[N] x;
x[1] = exp(y[1]) + lb;
target += y[1];
for (i in 2:N) {
x[i] = exp(y[i]) + x[i - 1];
target += y[i];
}
return x;
}
vector ordered_ub_lp (vector y, real ub) {
int N = rows(y);
vector[N] x;
x[1] = ub - exp(y[1]);
target += y[1];
for (i in 2:N) {
x[i] = x[i - 1] - exp(y[i]);
target += y[i];
}
return x;
}
vector ordered_lb_ub_lp (vector y, real lb, real ub) {
int N = rows(y);
vector[N] x;
x[1] = lb + (ub - lb) * inv_logit(y[1]);
target += log(ub - lb) + log_inv_logit(y[1]) + log1m_inv_logit(y[1]);
for (i in 2:N) {
x[i] = x[i - 1] + (ub - x[i - 1]) * inv_logit(y[i]);
target += log(ub - x[i - 1]) + log_inv_logit(y[i]) + log1m_inv_logit(y[i]);
}
return x;
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the scalar transformations shown in the issue and the requirements for scalar and vector bounds. Done means supporting lower-bounded, upper-bounded, and doubly bounded ordered vectors, including the stated ordering constraints for vector bounds.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100