Comments (10)
Yes until I update the model code, you need to edit it so it uses the new array syntax. More details: https://mc-stan.org/cmdstanr/articles/deprecations.html
from rethinking.
Do you take pull requests? I'd like to try my hand at fixing it... Would you like the fix to check what version of Stan people are using?
from rethinking.
I do sometimes yes. I actually have a draft fix in my local branch. I will see if I can find time to review it and push up later today.
from rethinking.
Okay I just committed and push it up to Experimental. It runs for me, but still with one warning that I'd like to fix. 0c15281
from rethinking.
Okay I just committed and push it up to Experimental. It runs for me, but still with one warning that I'd like to fix. 0c15281
Thanks!
For anyone else that's interested, this particular commit can be obtained using
remotes::install_github("rmcelreath/rethinking@0c15281e9452e335fc73eba368f39cafde3ef131")
Also, I'm not sure if this was intentional, but when I re-ran the code, it seemed to require rstan
this time around even though ulam_options$use_cmdstan <- TRUE
.
from rethinking.
Re rstan, I couldn't repeat that issue. I don't have rstan installed, and it seemed to work. Any more details that might help me figure out the issue?
from rethinking.
Re rstan, I couldn't repeat that issue. I don't have rstan installed, and it seemed to work. Any more details that might help me figure out the issue?
Looking at it more carefully, I guess it's not a serious issue -- see the very bottom of this reprex regarding the error.
library(reprex)
library(rethinking)
#> Loading required package: cmdstanr
#> This is cmdstanr version 0.6.1
#> - CmdStanR documentation and vignettes: mc-stan.org/cmdstanr
#> - CmdStan path: /home/mtruong/.cmdstan/cmdstan-2.33.1
#> - CmdStan version: 2.33.1
#> Loading required package: posterior
#> This is posterior version 1.5.0
#>
#> Attaching package: 'posterior'
#> The following objects are masked from 'package:stats':
#>
#> mad, sd, var
#> The following objects are masked from 'package:base':
#>
#> %in%, match
#> Loading required package: parallel
#> rethinking (Version 2.41)
#>
#> Attaching package: 'rethinking'
#> The following object is masked from 'package:stats':
#>
#> rstudent
# library(rstan)
data("Lynx_Hare")
data("Lynx_Hare_model")
dat_list <- list(N=nrow(Lynx_Hare),
pelts= Lynx_Hare[,2:3])
# ulam_options$use_cmdstan <- TRUE
paste("My ulam_options is", ulam_options$use_cmdstan)
#> [1] "My ulam_options is TRUE"
m16.5 <- rethinking::stan(
model_code = Lynx_Hare_model,
data = dat_list,
chains = 3,
cores = 3,
control = list(adapt_delta = 0.95)
)
#> Warning in '/tmp/RtmpxyKElk/model-6a844fa15eb9.stan', line 39, column 22: integrate_ode_rk45
#> is deprecated and will be removed in Stan 3.0. Use ode_rk45 instead.
#> The new interface is slightly different, see:
#> https://mc-stan.org/users/documentation/case-studies/convert_odes.html
#> Running MCMC with 3 parallel chains...
#>
#> Chain 1 Iteration: 1 / 1000 [ 0%] (Warmup)
#> Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
#> Chain 1 Exception: lognormal_lpdf: Scale parameter is inf, but must be positive finite! (in '/tmp/RtmpxyKElk/model-6a844fa15eb9.stan', line 55, column 6 to column 63)
#> Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
#> Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
#> Chain 1
#> Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
#> Chain 1 Exception: lognormal_lpdf: Scale parameter is inf, but must be positive finite! (in '/tmp/RtmpxyKElk/model-6a844fa15eb9.stan', line 55, column 6 to column 63)
#> Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
#> Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
#> Chain 1
#> Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
#> Chain 1 Exception: lognormal_lpdf: Location parameter is -nan, but must be finite! (in '/tmp/RtmpxyKElk/model-6a844fa15eb9.stan', line 55, column 6 to column 63)
#> Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
#> Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
#> Chain 1
#> Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
#> Chain 1 Exception: integrate_ode_rk45: Failed to integrate to next output time (2) in less than max_num_steps steps (in '/tmp/RtmpxyKElk/model-6a844fa15eb9.stan', line 39, column 2 to line 42, column 65)
#> Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
#> Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
#> Chain 1
#> Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
#> Chain 1 Exception: lognormal_lpdf: Location parameter is -nan, but must be finite! (in '/tmp/RtmpxyKElk/model-6a844fa15eb9.stan', line 55, column 6 to column 63)
#> Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
#> Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
#> Chain 1
#> Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
#> Chain 1 Exception: lognormal_lpdf: Location parameter is -nan, but must be finite! (in '/tmp/RtmpxyKElk/model-6a844fa15eb9.stan', line 55, column 6 to column 63)
#> Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
#> Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
#> Chain 1
#> Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
#> Chain 1 Exception: integrate_ode_rk45: initial state[1] is inf, but must be finite! (in '/tmp/RtmpxyKElk/model-6a844fa15eb9.stan', line 39, column 2 to line 42, column 65)
#> Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
#> Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
#> Chain 1
#> Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
#> Chain 1 Exception: lognormal_lpdf: Scale parameter is inf, but must be positive finite! (in '/tmp/RtmpxyKElk/model-6a844fa15eb9.stan', line 55, column 6 to column 63)
#> Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
#> Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
#> Chain 1
#> Chain 2 Iteration: 1 / 1000 [ 0%] (Warmup)
#> Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
#> Chain 2 Exception: lognormal_lpdf: Scale parameter is inf, but must be positive finite! (in '/tmp/RtmpxyKElk/model-6a844fa15eb9.stan', line 55, column 6 to column 63)
#> Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
#> Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
#> Chain 2
#> Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
#> Chain 2 Exception: lognormal_lpdf: Scale parameter is inf, but must be positive finite! (in '/tmp/RtmpxyKElk/model-6a844fa15eb9.stan', line 55, column 6 to column 63)
#> Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
#> Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
#> Chain 2
#> Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
#> Chain 2 Exception: integrate_ode_rk45: Failed to integrate to next output time (2) in less than max_num_steps steps (in '/tmp/RtmpxyKElk/model-6a844fa15eb9.stan', line 39, column 2 to line 42, column 65)
#> Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
#> Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
#> Chain 2
#> Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
#> Chain 2 Exception: integrate_ode_rk45: Failed to integrate to next output time (2) in less than max_num_steps steps (in '/tmp/RtmpxyKElk/model-6a844fa15eb9.stan', line 39, column 2 to line 42, column 65)
#> Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
#> Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
#> Chain 2
#> Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
#> Chain 2 Exception: integrate_ode_rk45: Failed to integrate to next output time (5) in less than max_num_steps steps (in '/tmp/RtmpxyKElk/model-6a844fa15eb9.stan', line 39, column 2 to line 42, column 65)
#> Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
#> Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
#> Chain 2
#> Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
#> Chain 2 Exception: integrate_ode_rk45: initial state[1] is inf, but must be finite! (in '/tmp/RtmpxyKElk/model-6a844fa15eb9.stan', line 39, column 2 to line 42, column 65)
#> Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
#> Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
#> Chain 2
#> Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
#> Chain 2 Exception: integrate_ode_rk45: Failed to integrate to next output time (2) in less than max_num_steps steps (in '/tmp/RtmpxyKElk/model-6a844fa15eb9.stan', line 39, column 2 to line 42, column 65)
#> Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
#> Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
#> Chain 2
#> Chain 3 Rejecting initial value:
#> Chain 3 Error evaluating the log probability at the initial value.
#> Chain 3 Exception: lognormal_lpdf: Location parameter is -nan, but must be finite! (in '/tmp/RtmpxyKElk/model-6a844fa15eb9.stan', line 55, column 6 to column 63)
#> Chain 3 Exception: lognormal_lpdf: Location parameter is -nan, but must be finite! (in '/tmp/RtmpxyKElk/model-6a844fa15eb9.stan', line 55, column 6 to column 63)
#> Chain 3 Iteration: 1 / 1000 [ 0%] (Warmup)
#> Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
#> Chain 3 Exception: lognormal_lpdf: Location parameter is -nan, but must be finite! (in '/tmp/RtmpxyKElk/model-6a844fa15eb9.stan', line 55, column 6 to column 63)
#> Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
#> Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
#> Chain 3
#> Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
#> Chain 3 Exception: lognormal_lpdf: Location parameter is -nan, but must be finite! (in '/tmp/RtmpxyKElk/model-6a844fa15eb9.stan', line 55, column 6 to column 63)
#> Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
#> Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
#> Chain 3
#> Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
#> Chain 3 Exception: integrate_ode_rk45: Failed to integrate to next output time (2) in less than max_num_steps steps (in '/tmp/RtmpxyKElk/model-6a844fa15eb9.stan', line 39, column 2 to line 42, column 65)
#> Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
#> Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
#> Chain 3
#> Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
#> Chain 3 Exception: integrate_ode_rk45: Failed to integrate to next output time (2) in less than max_num_steps steps (in '/tmp/RtmpxyKElk/model-6a844fa15eb9.stan', line 39, column 2 to line 42, column 65)
#> Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
#> Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
#> Chain 3
#> Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
#> Chain 3 Exception: lognormal_lpdf: Location parameter is -nan, but must be finite! (in '/tmp/RtmpxyKElk/model-6a844fa15eb9.stan', line 55, column 6 to column 63)
#> Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
#> Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
#> Chain 3
#> Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
#> Chain 3 Exception: integrate_ode_rk45: initial state[2] is inf, but must be finite! (in '/tmp/RtmpxyKElk/model-6a844fa15eb9.stan', line 39, column 2 to line 42, column 65)
#> Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
#> Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
#> Chain 3
#> Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
#> Chain 3 Exception: integrate_ode_rk45: Failed to integrate to next output time (2) in less than max_num_steps steps (in '/tmp/RtmpxyKElk/model-6a844fa15eb9.stan', line 39, column 2 to line 42, column 65)
#> Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
#> Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
#> Chain 3
#> Chain 1 Iteration: 100 / 1000 [ 10%] (Warmup)
#> Chain 2 Iteration: 100 / 1000 [ 10%] (Warmup)
#> Chain 3 Iteration: 100 / 1000 [ 10%] (Warmup)
#> Chain 1 Iteration: 200 / 1000 [ 20%] (Warmup)
#> Chain 3 Iteration: 200 / 1000 [ 20%] (Warmup)
#> Chain 2 Iteration: 200 / 1000 [ 20%] (Warmup)
#> Chain 1 Iteration: 300 / 1000 [ 30%] (Warmup)
#> Chain 3 Iteration: 300 / 1000 [ 30%] (Warmup)
#> Chain 1 Iteration: 400 / 1000 [ 40%] (Warmup)
#> Chain 2 Iteration: 300 / 1000 [ 30%] (Warmup)
#> Chain 3 Iteration: 400 / 1000 [ 40%] (Warmup)
#> Chain 1 Iteration: 500 / 1000 [ 50%] (Warmup)
#> Chain 1 Iteration: 501 / 1000 [ 50%] (Sampling)
#> Chain 2 Iteration: 400 / 1000 [ 40%] (Warmup)
#> Chain 3 Iteration: 500 / 1000 [ 50%] (Warmup)
#> Chain 3 Iteration: 501 / 1000 [ 50%] (Sampling)
#> Chain 1 Iteration: 600 / 1000 [ 60%] (Sampling)
#> Chain 3 Iteration: 600 / 1000 [ 60%] (Sampling)
#> Chain 2 Iteration: 500 / 1000 [ 50%] (Warmup)
#> Chain 2 Iteration: 501 / 1000 [ 50%] (Sampling)
#> Chain 3 Iteration: 700 / 1000 [ 70%] (Sampling)
#> Chain 1 Iteration: 700 / 1000 [ 70%] (Sampling)
#> Chain 2 Iteration: 600 / 1000 [ 60%] (Sampling)
#> Chain 3 Iteration: 800 / 1000 [ 80%] (Sampling)
#> Chain 1 Iteration: 800 / 1000 [ 80%] (Sampling)
#> Chain 3 Iteration: 900 / 1000 [ 90%] (Sampling)
#> Chain 2 Iteration: 700 / 1000 [ 70%] (Sampling)
#> Chain 3 Iteration: 1000 / 1000 [100%] (Sampling)
#> Chain 3 finished in 4.6 seconds.
#> Chain 1 Iteration: 900 / 1000 [ 90%] (Sampling)
#> Chain 2 Iteration: 800 / 1000 [ 80%] (Sampling)
#> Chain 1 Iteration: 1000 / 1000 [100%] (Sampling)
#> Chain 1 finished in 5.5 seconds.
#> Chain 2 Iteration: 900 / 1000 [ 90%] (Sampling)
#> Chain 2 Iteration: 1000 / 1000 [100%] (Sampling)
#> Chain 2 finished in 6.3 seconds.
#>
#> All 3 chains finished successfully.
#> Mean chain execution time: 5.5 seconds.
#> Total execution time: 6.5 seconds.
#> Error in loadNamespace(x): there is no package called 'rstan'
Created on 2023-11-27 with reprex v2.0.2
from rethinking.
Also, here's an updated string for the Boxes_model
Boxed_model <-"data{
int N;
array[N] int y;
array[N] int majority_first;
}
parameters{
simplex[5] p;
}
model{
vector[5] phi;
// prior
p ~ dirichlet( rep_vector(4,5) );
// probability of data
for ( i in 1:N ) {
if ( y[i]==2 ) phi[1]=1; else phi[1]=0; // majority
if ( y[i]==3 ) phi[2]=1; else phi[2]=0; // minority
if ( y[i]==1 ) phi[3]=1; else phi[3]=0; // maverick
phi[4]=1.0/3.0; // random
if ( majority_first[i]==1 ) // follow first
if ( y[i]==2 ) phi[5]=1; else phi[5]=0;
else
if ( y[i]==3 ) phi[5]=1; else phi[5]=0;
// compute log( p_s * Pr(y_i|s )
for ( j in 1:5 ) phi[j] = log(p[j]) + log(phi[j]);
// compute average log-probability of y_i
target += log_sum_exp( phi );
}
}"
I'm curious -- should we prefer RStan or CmdStanR? The Stan website and the rethinking
package seem to imply that we should be using CmdStanR, yet when I make a new Stan file through R-Studio, it seems to require the RStan package...
from rethinking.
Thanks for the model code. I guess that one is deprecated too now.
CmdStanR is the better choice. RStan is many patches behind in the binaries, because the CRAN policies make it hard to update. CmdStanR in contrast doesn't even need to updated when the core cmdstan library is updated. That's why I rewrote rethinking so that RStan is not required.
from rethinking.
Thanks for the model code. I guess that one is deprecated too now.
CmdStanR is the better choice. RStan is many patches behind in the binaries, because the CRAN policies make it hard to update. CmdStanR in contrast doesn't even need to updated when the core cmdstan library is updated. That's why I rewrote rethinking so that RStan is not required.
I see... Well I think that about solves my issue, so I'll go ahead and close it. Thank you for the help
from rethinking.
Related Issues (20)
- How to construct a spline model using ulam() HOT 4
- cannot install rethinking HOT 1
- Error in link(), R code 4.67 HOT 1
- Poisson response imputation compilation error
- Random Effect in Zero-Inflated Model
- Rethink package is NOT getting installed HOT 8
- Sampling issue for the Cat Adoptions Survival model.
- Random walk in ulam HOT 2
- problem in precis command
- Can multiple outcomes be regressed on the same linear model?
- ulam fits missing @stanfit slot? HOT 2
- WAIC not computing from ulam() model, even with log_lik = TRUE HOT 4
- Problem installing cmdstanr HOT 1
- ulam fits giving odd errors HOT 4
- errata 2nd Edition page 130
- log_lik fails with matrices in models fit by ulam HOT 6
- Where is sim_globe, and the rest of the code shown in the videos? HOT 2
- Panda_nuts Nut-Cracking Frequency? HOT 6
- The garden of forking data - 2 blue from 1? HOT 3
- quap allows incorrect(?) definition with categorical variable HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rethinking.