You received this message because you are subscribed to a topic in the Google Groups "Stan users mailing list" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/stan-users/Q7zADp0Ho9E/unsubscribe.
To unsubscribe from this group and all its topics, send an email to stan-users+...@googlegroups.com.
You're right on both counts. There's no element-wise exponentiation of row vectors. And we missed "operator^" in the index. I'll add it to the next release of the manual: https://github.com/stan-dev/stan/issues/786#issuecomment-51396580
You received this message because you are subscribed to a topic in the Google Groups "Stan users mailing list" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/stan-users/Q7zADp0Ho9E/unsubscribe.
To unsubscribe from this group and all its topics, send an email to stan-users+...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
<error.log><rpdf.stan>
Dear all, in my model I need to do an element-wise exponentiation of a row vector and that doesn't seem to be possible in Stan. Here's a snippet of my model code (full model is attached). model { row_vector<lower=0,upper=1>[3] a[maxTrials+1]; // attention weights vector<lower=0,upper=1>[maxTrials] prob; // Prob(chosenAction) ... for (sub in 1:nSubjects) { ... for (t in 1:nTrials) { prob[t] <- dot_product(M[sub,t],a[t]^d[sub]) / ( sum(a[t]^d[sub]) + machine_precision() ); ... } } } a[t] is a trial-specific row_vector that should be raised to the power of d[sub], which is a subject-specific model parameter before taking the dot_product with M[sub,t] (another vector, part of the data) I keep getting this compiler error: TRANSLATING MODEL 'rpdf' FROM Stan CODE TO C++ CODE NOW. Error in stanc(file = file, model_code = model_code, model_name = model_name, : failed to parse Stan model 'rpdf' with error message: EXPECTATION FAILURE - DIAGNOSTIC(S) FROM PARSER: LOCATION OF PARSING ERROR (line = 120, position = 43): PARSED: model { /* Should these declarations be in the transformed_data block? */ row_vector<lower=0,upper=1>[3] a[maxTrials+1]; // attention weights row_vector<lower=0,upper=1>[3] s[maxTrials]; // feedback signal vector<lower=0,upper=1>[maxTrials] prob; // Prob(chosenAction) r_mu ~ beta(A,B); r_prime_kappa ~ beta(A,B); p_mu ~ beta(A,B); p_prime_kappa ~ beta(A,B); d_prime_mu ~ beta(1,1); d_prime_kappa ~ beta(A,B); f_prime_mu ~ beta(A,B); f_prime_kappa ~ beta(A,B); for (sub in 1:nSubjects) { r[sub] ~ beta(r_a,r_b) T[L,U]; p[sub] ~ beta(p_a,p_b) T[L,U]; d_prime[sub] ~ beta(d_a,d_b) T[L,U]; f_prime[sub] ~ beta(f_a,f_b) T[L,U]; a[1] <- initA; for (t in 1:nTrials[sub]) { prob[t] <- dot_product(M[sub,t],a[t] EXPECTED: ")" BUT FOUND: ^d[sub]) / ( sum( I looked through the Stan User Manual (Section Built-in function), but could find the formal definition of the ^ operator. Shouldn't that be in there or did I miss it somewhere along the way? I tried to change the line above to using the pow() function: prob[t] <- dot_product(M[sub,t],pow(a[t],d[sub])) / ( sum(pow(a[t],d[sub])) + machine_precision() ); but found out through a compiler error and the User Manual that pow() only take scalars (real) as inputs Of course, one could break this exponentiation of a vector into it's elements by using a loop, but seem rather clumsy. Does anyone have an idea of how to run a power function on a vector? Thanks a lot, Jan -- 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. For more options, visit https://groups.google.com/d/optout. <rpdf.stan>
Hi Jan,By experience the error message "Rejecting user-specified initialization because of vanishing density" is due to bad initialization values. I triggered this error message in the past by creating starting values that created -inf values on the log scale or on the logit scale.Your model seems to use the beta distribution. I never used the beta distribution with Stan but based on my experience with JAGS and WinBUGS I would guess that your initialization values a probably too close to zero for some parameters. You may want to try starting values that are away from zero to see if you can get the model over the bump.HTHChris----------------------------
--
You received this message because you are subscribed to a topic in the Google Groups "Stan users mailing list" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/stan-users/Q7zADp0Ho9E/unsubscribe.
To unsubscribe from this group and all its topics, send an email to stan-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
<rpdf.stan>
--
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+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
<rpdf_with_exp.stan><error.log>
<rpdf.stan>
--
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+un...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+...@googlegroups.com.
Hi Jan,The only reason I have never used the beta distribution in Stan is because I used the beta distribution to estimate detection in occupancy modelling or abundance modelling and it's impossible to do those kind of model in Stan (for the moment...maybe forever....but I keep dreaming that it will be possible one day).I've never worked with the type of model you are using right now but I think the problem is that your starting values are actually defining the parameters of some of your beta distribution.
For example "r_a" is a parameter for a beta distribution in the model.yet "r_a" is the product itself of "r_mu" and "r_kappa" and r_kappa" itself is defined from "r_prime_kappa".So even if you try to keep your values away from the extreme you could end up with some kind of highly constrained beta distribution (multiplying a lot of values between 0 and 1 is bound to create some problem at some point).Basically I feel like the model will be really tricky to initialize no matter what software you use.I have some really painful memories of trying to initialize models like that in JAGS. In those situation I usually started backward. I created a function that would define the most troublesome values and derive the hyper priors from those values.Chris-------------------
--
You received this message because you are subscribed to a topic in the Google Groups "Stan users mailing list" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/stan-users/Q7zADp0Ho9E/unsubscribe.
To unsubscribe from this group and all its topics, send an email to stan-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hi Jan,
The only reason I have never used the beta distribution in Stan is because I used the beta distribution to estimate detection in occupancy modelling or abundance modelling and it's impossible to do those kind of model in Stan (for the moment...maybe forever....but I keep dreaming that it will be possible one day).
I've never worked with the type of model you are using right now but I think the problem is that your starting values are actually defining the parameters of some of your beta distribution.
For example "r_a" is a parameter for a beta distribution in the model.
yet "r_a" is the product itself of "r_mu" and "r_kappa" and r_kappa" itself is defined from "r_prime_kappa".
So even if you try to keep your values away from the extreme you could end up with some kind of highly constrained beta distribution (multiplying a lot of values between 0 and 1 is bound to create some problem at some point).
To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
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+un...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+...@googlegroups.com.
You can try divide and conquer. Print it once in the middle, and if
it's good, look at the second half and if it's bad look at the first half.
You may also wind up wanting to print out some of the other values
to make sure you're passing legal values into all the functions.
The other problem is that we need to enhance the error messages. There's
also a problem on our side in that the initialization just swallows any
informative message and just gives you the inscrutable "vanishing density"
message at the end.
- Bob
Thanks you both. I do get the "Initialization Failure" error if I let Stan do the inilization. So there must be something wrong with the model.
Bob, should I print lp__ after each line of code or just after each sampling statement? Sorry, I realize these are all beginner's questions ...
- Jan
If the initialization works in JAGS, it should work in Stan.My guess is that there's a bug in your Stan code for the modelthat's causing the log prob to be -infinity. A likely cause isnot having all variables defined.I would very very strongly suggest following my earlier adviceand trying to track down where the model goes bad using print()statements.- Bob
--
You received this message because you are subscribed to a topic in the Google Groups "Stan users mailing list" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/stan-users/Q7zADp0Ho9E/unsubscribe.
To unsubscribe from this group and all its topics, send an email to stan-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hi Chris,
thanks a lot for sharing your experience and the suggestions. I didn't have a lot of trouble initializing this model in JAGS, but I wonder if the initialization would benefit, if I'd sample the parameter of the group distribution in the model block not from an uninformative beta(1,1), but rather a more symmetrical beta(10,10, or beta(20,20) even though this might entail running the sample for a bit longer until convergence is reached. Any thoughts?
Thanks a lot,
Jan
August 8, 2014 at 7:23 PM
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+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
<lp.txt>
[changed subject]I thought the vanishing density was when the densitiesoverflowed or became NaN. I changed the subject to getsome others' attention.You should also try to print out the gradients at your initial
point and make sure they're all finite. I should have suggestedthat first. It's possible that the log probability is OK but thegradients are bad.If those look OK, then someone else is going to have jump in
or I'll have to dig deeper from your data and model.- Bob
Dear Bob,
I added a print statement at the end of the model block and re-compiled the model: the log probability jumps in the range of about -2271 to about -2305. None of these values look bad to me (i.e. not NaN or -inf), but the sampling still stop with the failed initialization message after 100 attempts (see attached file lp.txt). I also tried this in the middle of the model block with the same results. I also had a more comprehensive set of print statements that printed current parameter values, but those also seem to be legal.
In the attached file you'll also see some compiler warnings, which sounded harmless to me (but I don't know much about C++ so I maybe wrong).
Is there anything else that I can try in order to get Stan to sample?
Thanks a lot,
Jan
<postbox-contact.jpg>
Bob Carpenter
August 8, 2014 at 9:46 PM
You can try divide and conquer. Print it once in the middle, and if
it's good, look at the second half and if it's bad look at the first half.
You may also wind up wanting to print out some of the other values
to make sure you're passing legal values into all the functions.
The other problem is that we need to enhance the error messages. There's
also a problem on our side in that the initialization just swallows any
informative message and just gives you the inscrutable "vanishing density"
message at the end.
- Bob
<postbox-contact.jpg>
Jan Glaescher
August 8, 2014 at 9:02 PM
Thanks you both. I do get the "Initialization Failure" error if I let Stan do the inilization. So there must be something wrong with the model.
Bob, should I print lp__ after each line of code or just after each sampling statement? Sorry, I realize these are all beginner's questions ...
- Jan
<postbox-contact.jpg>
Bob Carpenter
August 8, 2014 at 8:41 PM
If the initialization works in JAGS, it should work in Stan.
My guess is that there's a bug in your Stan code for the model
that's causing the log prob to be -infinity. A likely cause is
not having all variables defined.
I would very very strongly suggest following my earlier advice
and trying to track down where the model goes bad using print()
statements.
- Bob
On Aug 8, 2014, at 2:37 PM, Jan Glaescher <glae...@gmail.com> wrote:
--
You received this message because you are subscribed to a topic in the Google Groups "Stan users mailing list" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/stan-users/Q7zADp0Ho9E/unsubscribe.
To unsubscribe from this group and all its topics, send an email to stan-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
<postbox-contact.jpg>
Jan Glaescher
August 8, 2014 at 8:37 PM
Hi Chris,
thanks a lot for sharing your experience and the suggestions. I didn't have a lot of trouble initializing this model in JAGS, but I wonder if the initialization would benefit, if I'd sample the parameter of the group distribution in the model block not from an uninformative beta(1,1), but rather a more symmetrical beta(10,10, or beta(20,20) even though this might entail running the sample for a bit longer until convergence is reached. Any thoughts?
Thanks a lot,
Jan
<compose-unknown-contact.jpg>
Christian Roy
August 8, 2014 at 7:23 PM
Hi Jan,
The only reason I have never used the beta distribution in Stan is because I used the beta distribution to estimate detection in occupancy modelling or abundance modelling and it's impossible to do those kind of model in Stan (for the moment...maybe forever....but I keep dreaming that it will be possible one day).
I've never worked with the type of model you are using right now but I think the problem is that your starting values are actually defining the parameters of some of your beta distribution.
For example "r_a" is a parameter for a beta distribution in the model.
yet "r_a" is the product itself of "r_mu" and "r_kappa" and r_kappa" itself is defined from "r_prime_kappa".
So even if you try to keep your values away from the extreme you could end up with some kind of highly constrained beta distribution (multiplying a lot of values between 0 and 1 is bound to create some problem at some point).
Basically I feel like the model will be really tricky to initialize no matter what software you use.
I have some really painful memories of trying to initialize models like that in JAGS. In those situation I usually started backward. I created a function that would define the most troublesome values and derive the hyper priors from those values.
Chris
-------------------
--
You received this message because you are subscribed to a topic in the Google Groups "Stan users mailing list" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/stan-users/Q7zADp0Ho9E/unsubscribe.
To unsubscribe from this group and all its topics, send an email to stan-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
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+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
<lp.txt>
I couldn't tell if you're using CmdStan or RStan.
Both have different calls.
If it's CmdStan, just use
% ./model-name diagnose
If it's RStan, add
test_grad=TRUE
option to the stan() call and it'll only print the gradients out
and not try to sample.
- Bob
[changed subject]I thought the vanishing density was when the densitiesoverflowed or became NaN. I changed the subject to getsome others' attention.You should also try to print out the gradients at your initial--point and make sure they're all finite. I should have suggestedthat first. It's possible that the log probability is OK but thegradients are bad.If those look OK, then someone else is going to have jump inor I'll have to dig deeper from your data and model.- Bob
You received this message because you are subscribed to a topic in the Google Groups "Stan users mailing list" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/stan-users/Q7zADp0Ho9E/unsubscribe.
To unsubscribe from this group and all its topics, send an email to stan-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
August 8, 2014 at 9:46 PM
You can try divide and conquer. Print it once in the middle, and if
it's good, look at the second half and if it's bad look at the first half.
You may also wind up wanting to print out some of the other values
to make sure you're passing legal values into all the functions.
The other problem is that we need to enhance the error messages. There's
also a problem on our side in that the initialization just swallows any
informative message and just gives you the inscrutable "vanishing density"
message at the end.
- Bob
August 8, 2014 at 9:02 PM
Thanks you both. I do get the "Initialization Failure" error if I let Stan do the inilization. So there must be something wrong with the model.
Bob, should I print lp__ after each line of code or just after each sampling statement? Sorry, I realize these are all beginner's questions ...
- Jan
August 8, 2014 at 8:41 PM
No. I think this may just be an undesirable side-effect of
using multiple initializations. Can you try init=0 and
see what that does?
- Bob
After compilation it says:
TESTING GRADIENT FOR MODEL 'rpdf' NOW (CHAIN 1).
But it never prints out any information about the gradients. It goes right into initialization (and hence prints out the log probability that I put in the print statement (see attachment).
I did the standard rstan setup (R 3.1.1 on Macbook Pro). Do I need to set an additional debug flag or something else during installation to get the gradient information?
Thanks,
Jan
I couldn't tell if you're using CmdStan or RStan.
Both have different calls.
If it's CmdStan, just use
% ./model-name diagnose
If it's RStan, add
test_grad=TRUE
option to the stan() call and it'll only print the gradients out
and not try to sample.
- Bob
Dear Bob,thanks for your comments. Can you quickly tells me what the relevant variables are that I should print when trying to assess the gradients?Thanks,Jan
Hi Jan,
It's definitely a bug and I'm trying to track it down. It's pretty deep in the guts of Stan, so it's taking longer to find than I expected. Nothing to do right now. It's happening in between iterations, so you won't be able to track it with print statements, unfortunately.
Daniel