/* Formulate c1[i,d] and c2[i,d], mean of latent response or multi-variate trait in ordered_logistic model */
print("Delta= ", Delta[teacher1[1]][1,1]);
print("Phi= ", Phi[section1[1]][1,1]);
print("Theta= ", Theta[session1[1]][1,1]);
print("Zeta= ", Zeta[session_rater1[1]][1,1]);
print("Beta_mean= ", Beta_mean[rater1[1]][1,1]);
for( i in 1:N1 ) for( d in 1:D ) c1[i,d] <- Delta[teacher1[i]][d,1] + Phi[section1[i]][d,1] + Theta[session1[i]][d,1] + Zeta[session_rater1[i]][d,1] + Beta_mean[rater1[i]][d,1];
for( i in 1:N2 ) for( d in 1:D ) c2[i,d] <- Delta[teacher2[i]][d,2] + Phi[section2[i]][d,2] + Theta[session2[i]][d,2] + Zeta[session_rater2[i]][d,2] + Beta_mean[rater2[i]][d,2];
goodrich@CYBERPOWERPC:/tmp/Terrance$ gdb --args ./modelFAcum_lkj --data=datstan.Rdump
GNU gdb (GDB) 7.4.1-debian
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /tmp/Terrance/modelFAcum_lkj...done.
(gdb) catch throw
Catchpoint 1 (throw)
(gdb) run
Starting program: /tmp/Terrance/modelFAcum_lkj --data=datstan.Rdump
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Delta= 1.04147
Phi= -1.2006
Theta= 1.17
Zeta= 1.49939
Beta_mean= nan
Catchpoint 1 (exception thrown), 0x00007ffff791db90 in __cxa_throw () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
goodrich@CYBERPOWERPC:/tmp/Terrance$ grep -n Beta_mean modelFAcum_lkj.stan
79: matrix[D,M] Beta_mean[Rr];
97: print("Beta_mean= ", Beta_mean[rater1[1]][1,1]);
98: for( i in 1:N1 ) for( d in 1:D ) c1[i,d] <- Delta[teacher1[i]][d,1] + Phi[section1[i]][d,1] + Theta[session1[i]][d,1] + Zeta[session_rater1[i]][d,1] + Beta_mean[rater1[i]][d,1];
99: for( i in 1:N2 ) for( d in 1:D ) c2[i,d] <- Delta[teacher2[i]][d,2] + Phi[section2[i]][d,2] + Theta[session2[i]][d,2] + Zeta[session_rater2[i]][d,2] + Beta_mean[rater2[i]][d,2];
118: for( r in 1:Rr ) Beta_mean[r] <- Beta[r] + mean_Beta;
228: /* functions of multivariate hierarchical parameters, Delta, Phi, Theta, Zeta, Beta_mean */
Bob has written it into the latest version of the manual. Section 5 starting on page 29.
For anyone that hasn't downloaded the latest versions of the manual or the software, please do. There have been many improvements to both.
Daniel
I now have my opportunity to try using gdb and print as I fixed the point you noted and now receive:SAMPLING FOR MODEL 'modelFAcum_lkj' NOW (CHAIN 1).Error in sampler$call_sampler(args_list[[i]]) :Error in function stan_fit15383be23b0c_modelFAcum_lkj_namespace::write_array(d): y is not positive definite. y(0,0) is 0.27558073566315999.That seems like something really bad. I will come back to the list, if necessary, after performing a debugging.
Ben, Thanks a lot for the coaching and sorry for just dropping the problem on you. To tell the truth, I've struggled with how to use gdb for debugging C++ code in an R environment. I typically use Rcpp and wind up debugging through inputting C++ code files with inline. Your points help me to get started with gdb. Thanks for taking the time with this and getting back to me so quickly.
I guess the print output does not migrate to the R layer if executing using rstan. one has to run from the command line??
goodrich@CYBERPOWERPC:/tmp/Terrance$ ./modelFAcum_lkj --data=datstan.Rdump
Delta= 0.371263
Phi= 0.803654
Theta= -0.220654
Zeta= 0.873778
Beta_mean= nan
Exception: Error in function stan::prob::ordered_logistic(N4stan5agrad3varE): Location parameter is nan:0, but must be finite!
Diagnostic information:
Throw location unknown (consider using BOOST_THROW_EXCEPTION)
Dynamic exception type: boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<std::domain_error> >
std::exception::what: Error in function stan::prob::ordered_logistic(N4stan5agrad3varE): Location parameter is nan:0, but must be finite!
goodrich@CYBERPOWERPC:/tmp/Terrance$
1. working from windows 7, i'm unable to compile the c++ code file generated from stanc from the command line. the compiler is unable to find module_header.hpp, despite my changing the subdirectory in the #include statement to the correct location (as noted in an earlier post). so i'm unable to get launched with gdb, just now.
# execute this in R to find out where rstan lives to utilize below
file.path(dirname(system.file(package = "rstan")), "rstan", "include", "stanlib")
// download Stan and change this line in STAN_HOME/makefile from
BOOST ?= lib/boost_1.51.0
// to
BOOST ?= /path/to/rstan/include/stanlib/boost_1.51.0
2. you note that the print statements appear under command line runs - either with or without gdb. that says they should also appear in R to the extent that the Rcpp command is used to migrate the output. The print outputs don't appear in R for me. Do they for you?
3. so i fixed the syntax error where a parameter was used before defined that you helpfully uncovered by just moving the statement. now i receive 2 error alternating error messages. one notes that some variable is not positive definite. the other error message (that replaces this one) is that the sampler is unable to find a sufficiently small leapfrog step size. although my model looks complicated, it's actually a relatively straightforward parametric multivariate sampler wrapped in a glm of a type i've successfuly implemented in JAGS. it looks complicated because i've employed tips learned from the stan team to deliver better speed and memory management under automated differentiation by taking inverses once and directly updating lp__.i hope to eventually sort out how to compile from the command line so that i may view the print statements for further debugging, but i wonder whether NUTS breaks down under multivariate hierarchical models specified with relatively non-informative priors.
tar -xzf --no-same-owner stan-src-1.0.2.tgz
Thanks a lot, Ben, for running gdb on my code. I attach 2 stan script files. The first, "...lkj.stan" is my focus. The second, "...lkj2.stan" is the same as the first, except that for specification of the sets of cutpoints used in the ordinal_logistic distribution. lkj.stan fixes one member of each vector to 0 for identifiabiilty; lkj2.stan does not. the multivariate latent trait, c, of the ordinal logistic model is composed from from the addition of multivariate nested objects. So there are exchangeable multivariate draws at each level. The structures are identical, except for the highest / first level where a factor analytic construction is employed for one of the two covariances. this may be where the issue arises. I have also tried increasing the informativeness of the lkj priors on correlation matrices by increasing the value of the shape parameter, but no change.
Thanks, too, for your tips on configuring my windows set-up to help the compiler find the dependent libraries. since i know exactly where stan is loaded with the R/libraries/rstan folder structure, I hoped pointing the #include statement in the generated stanc c++ code to the location of module_header.hpp i would make everything go, but the compiler still couldn't find module_header.hpp. Anyway, I was trying to save harddisk space, but i'm not that desperate. So I'm using rstan 1.0.2, which I want to keep using, in general. Currently, the only installation of stan i have is stan 1.0.2 through rstan, so i don't think i need to delete anything. if i separately download stan, is there a potential conflict with the stan load that comes with the rstan folders? It just seemed logical to me that to use the stan installation made with rstan since i will most frequently interact with stan via the R layer. Maybe since you've provided me such detailed instructions, I'll just stick with the stan 1.0.2 that loads with rstan. I attach another file, "mystanmodel.cpp", so that you may see the code returned by running stanc() within in an R environment.
what computational set-up do most stan developers use?
On 9/30/12 5:58 PM, Ben Goodrich wrote:
> On Sunday, September 30, 2012 4:48:26 PM UTC-4, tds151 wrote:
> what computational set-up do most stan developers use?
>
>
> Mac, except for me.
I believe Marcus Brubaker is also on linux (must have something
to do with Ben and Marcus having coded most of the intense
linear algebra and multivariate distribution code).
On Sunday, September 30, 2012 4:48:26 PM UTC-4, tds151 wrote:Thanks a lot, Ben, for running gdb on my code. I attach 2 stan script files. The first, "...lkj.stan" is my focus. The second, "...lkj2.stan" is the same as the first, except that for specification of the sets of cutpoints used in the ordinal_logistic distribution. lkj.stan fixes one member of each vector to 0 for identifiabiilty; lkj2.stan does not. the multivariate latent trait, c, of the ordinal logistic model is composed from from the addition of multivariate nested objects. So there are exchangeable multivariate draws at each level. The structures are identical, except for the highest / first level where a factor analytic construction is employed for one of the two covariances. this may be where the issue arises. I have also tried increasing the informativeness of the lkj priors on correlation matrices by increasing the value of the shape parameter, but no change.
There is a problem before it really gets into the model. The elements of Lambda_s start out reasonable but become nan for some reason that I don't understand, because it is just a matrix of parameters. But there seems to be a problem with Stan also because --test_grad seems to hang. Bob will have to look into this whenever he gets back. Original attachments are at:
https://groups.google.com/d/msg/stan-users/MYdrB11_S5g/lKVzTcPjRtwJ
#include <fenv.h>
to the includes and addfeenableexcept(-1);
to main(), then in gdb you can do
(gdb) handle SIGFPE stop nopass
(gdb) run
then it should stop when something goes NaN. However, when I do that, I get
Exception: std::bad_alloc
Diagnostic information:
Dynamic exception type: std::bad_alloc
std::exception::what: std::bad_alloc
And when I do(gdb) catch throw(gdb) run
then I don't make it to the bad_alloc and instead hit the check_nan() failure.
So, something is very, very wrong, but I don't know what.
Ben
% make bin/stanc
generate_uniform_real()goodrich@CYBERPOWERPC:/tmp/Terrance$ gdb --args ./modelFAcum_lkj --data=datstan.Rdump
GNU gdb (GDB) 7.4.1-debian
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /tmp/Terrance/modelFAcum_lkj...done.
(gdb) run
Starting program: /tmp/Terrance/modelFAcum_lkj --data=datstan.Rdump
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Program received signal SIGFPE, Arithmetic exception.
0x0000000000476a5e in boost::random::detail::generate_uniform_real<boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014u, 0u, 2147483563u>, boost::random::linear_congruential_engine<unsigned int, 40692u, 0u, 2147483399u> >, double> (eng=..., min_value=-2, max_value=2)
at lib/boost_1.51.0/boost/random/uniform_real_distribution.hpp:61
61 T result = numerator / divisor * (max_value - min_value) + min_value;
(gdb) bt
#0 0x0000000000476a5e in boost::random::detail::generate_uniform_real<boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014u, 0u, 2147483563u>, boost::random::linear_congruential_engine<unsigned int, 40692u, 0u, 2147483399u> >, double> (eng=..., min_value=-2, max_value=2)
at lib/boost_1.51.0/boost/random/uniform_real_distribution.hpp:61
#1 0x000000000046d0d1 in boost::random::detail::generate_uniform_real<boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014u, 0u, 2147483563u>, boost::random::linear_congruential_engine<unsigned int, 40692u, 0u, 2147483399u> >, double> (eng=..., min_value=-2, max_value=2)
at lib/boost_1.51.0/boost/random/uniform_real_distribution.hpp:71
#2 0x0000000000458227 in boost::random::uniform_real_distribution<double>::operator()<boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014u, 0u, 2147483563u>, boost::random::linear_congruential_engine<unsigned int, 40692u, 0u, 2147483399u> > > (this=0x7fffffffdda8, eng=...)
at lib/boost_1.51.0/boost/random/uniform_real_distribution.hpp:191
#3 0x0000000000447143 in boost::random::variate_generator<boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014u, 0u, 2147483563u>, boost::random::linear_congruential_engine<unsigned int, 40692u, 0u, 2147483399u> >&, boost::random::uniform_real_distribution<double> >::operator() (this=0x7fffffffdda0)
at lib/boost_1.51.0/boost/random/variate_generator.hpp:73
#4 0x000000000043911e in stan::gm::nuts_command<modelFAcum_lkj_model_namespace::modelFAcum_lkj_model> (argc=2, argv=0x7fffffffe2c8) at src/stan/gm/command.hpp:351
#5 0x000000000040f31e in main (argc=2, argv=0x7fffffffe2c8) at /tmp/Terrance/modelFAcum_lkj.cpp:1575
(gdb) frame 0
#0 0x0000000000476a5e in boost::random::detail::generate_uniform_real<boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014u, 0u, 2147483563u>, boost::random::linear_congruential_engine<unsigned int, 40692u, 0u, 2147483399u> >, double> (eng=..., min_value=-2, max_value=2)
at lib/boost_1.51.0/boost/random/uniform_real_distribution.hpp:61
61 T result = numerator / divisor * (max_value - min_value) + min_value;
(gdb) print numerator
$1 = 402877394
(gdb) print divisor
$2 = 2147483562
(gdb) print max_value
$3 = 2
(gdb) print min_value
$4 = -2
(gdb) print numerator / divisor
$5 = 0.18760441343019693
Symmetry should be under your direct control if
you construct the covariance matrix.
One option is to copy one side into the other:
for (m in 1:rows(S_d))
for (n in (m+1):cols(S_d))
S_d[m,n] = S_d[n,m];
though I don't see how defining
S_d = Lambda * Lambda' + diag(the_del)
is going to break symmetry.
samples <- read.csv("samples.csv", comment.char="#")
> unique(samples[,1])
[1] -130083
> nrow(unique(samples))
[1] 1
One is there appears to be a bug with the step size selection code.
I'm not sure what's going on exactly, but turning it off (setting a
fixed step size with epsilon=0.0001 for instance) allows sampling to
proceed. (I'm not sure if this is exposed through the R interface or
not.) Matt, do you have time to check whats happening with the
stepsize adaption in this case? The fixed epsilon works just fine.