Using a vector as a lower bound of another vector

647 views
Skip to first unread message

sepehr akhavan

unread,
Feb 24, 2016, 3:48:59 PM2/24/16
to Stan users mailing list

Hi,

I'm familiar with the syntax below:
vector<lower = L> myVec;

In the code above, every element of the myVec vector has a lower bound of L. Now, suppose Lvec is a vector of lower bounds where Lvec[i] is the lower bound for the ith element of myVec. I tried:

vector<lower = Lvec> myVec; 

but as I expected, it didn't work. Any easy way to do that?

Thanks very much for your help,

Ben Goodrich

unread,
Feb 24, 2016, 3:58:13 PM2/24/16
to Stan users mailing list

Assuming Lvec is strictly positive, you can do

parameters {
  vector
[K]<lower=1> myPrimitiveVec
}
transformed parameters
  vector
[K] myVec;
  myVec
<- myPrimitiveVec .* Lvec;
}

Ben

Bob Carpenter

unread,
Feb 24, 2016, 5:49:59 PM2/24/16
to stan-...@googlegroups.com
No, you basically have to do the transforms yourself.

data {
int N;
vector[N] L; // lower bounds

parameters {
vector[N] my_vec_raw;


transformed parameters {
vector[N] my_vec;
my_vec <- L + exp(my_vec_raw);

model {
increment_log_prob(sum(my_vec_raw)); // Jacobian

I should at least put this in the manual until I can implement
vectors of lower bounds. I made the lower bound data here, but
it could also be a parameter itself. As long as the parameter
L isn't computed in terms of my_vec_raw, then the Jacobian above
is sufficient for the transform (L, my_vec_raw) -> (L, my_vec).

- Bob
> --
> You received this message because you are subscribed to the Google Groups "Stan users mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+...@googlegroups.com.
> To post to this group, send email to stan-...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Bob Carpenter

unread,
Feb 24, 2016, 8:44:19 PM2/24/16
to stan-...@googlegroups.com
I didn't see Ben's answer before responding. I seem to be
getting lag in the Apple mailer from other's responses. The
approach Ben offered is more straightforward; mine was just
recreating what Stan does internally for bounds.

Ben's is going to work out to

mu_vec <- L .* (exp(my_vec_raw) + 1)
...
increment_log_prob(sum(my_vec_raw));

and mine to

L + exp(my_vec_raw)
...
increment_log_prob(sum(my_vec_raw));

We still haven't studied much about how parameterizations of
various kinds affect sampling.

- Bob

Meng Zhao

unread,
Sep 28, 2016, 9:38:53 PM9/28/16
to Stan users mailing list
What if Lvec is negative? For example if it is negative lower bound distribution, how can I provide lower bound for my vector? Thanks.

Ben Goodrich

unread,
Sep 28, 2016, 10:01:08 PM9/28/16
to Stan users mailing list
On Wednesday, September 28, 2016 at 9:38:53 PM UTC-4, Meng Zhao wrote:
What if Lvec is negative? For example if it is negative lower bound distribution, how can I provide lower bound for my vector? Thanks.

Then you have to do the transformations yourself: exp() to get something non-negative and add Lvec to get something that is >= to Lvec.

Ben

Bob Carpenter

unread,
Sep 29, 2016, 5:41:26 PM9/29/16
to stan-...@googlegroups.com
And then you need the Jacobian if you are putting
a distribution on the transformed parameter.

- Bob
Reply all
Reply to author
Forward
0 new messages