Skip to content

Instantly share code, notes, and snippets.

@yiyuezhuo
Last active July 4, 2020 03:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yiyuezhuo/280520b47670b7a06ad9940a6f2211ac to your computer and use it in GitHub Desktop.
Save yiyuezhuo/280520b47670b7a06ad9940a6f2211ac to your computer and use it in GitHub Desktop.
basic stan fire model
data {
int<lower=0> N;
real HP_loss_raw[N];
real Org_loss_raw[N];
real evade;
real eps;
}
transformed data{
real HP_dice_size=2;
real Org_dice_size=4;
real evade_hit = evade / 10;
}
parameters {
real<lower=0> firepower;
// real<lower=0> fire_heavy;
// real<lower=0> fire_light;
// real<lower=0> hit_heavy;
// real<lower=0> hit_light;
real<lower=0> hit_heavy_z;
real<lower=0> hit_light_z;
}
transformed parameters{
real fire_hit = firepower / 10;
real fire_heavy = max([fire_hit - evade_hit, 0.]);
real fire_light = min([fire_hit, evade_hit]);
real hit_heavy = fire_heavy * 0.4 + hit_heavy_z * (sqrt(fire_heavy*0.4*0.6) + eps);
real hit_light = fire_light * 0.1 + hit_heavy_z * (sqrt(fire_light*0.1*0.9) + eps);
real hit = hit_light + hit_heavy;
}
model{
// hit_heavy ~ normal(fire_heavy * 0.4, sqrt(fire_heavy*0.4*0.6) + eps);
// hit_light ~ normal(fire_light * 0.1, sqrt(fire_light*0.1*0.9) + eps);
hit_heavy_z ~ normal(0, 1);
hit_light_z ~ normal(0, 1);
HP_loss_raw ~ normal(hit * (1 + HP_dice_size)/2,
sqrt(hit * (HP_dice_size*HP_dice_size - 1)/12 ));
Org_loss_raw ~ normal(hit * (1 + Org_dice_size)/2,
sqrt(hit * (Org_dice_size*Org_dice_size - 1)/12 ));
}
data5 = {
"N": 10,
"HP_loss_raw": [1., 0., 0., 4., 1., 0., 0., 1., 0., 0.],
"Org_loss_raw": [3., 0., 0., 4., 1., 0., 0., 1., 0., 0.],
"evade": 106,
"eps": 1e-6,
}
fit5 = sm5.sampling(data=data5, iter=1000, chains=4)
fit5
"""
WARNING:pystan:n_eff / iter below 0.001 indicates that the effective sample size has likely been overestimated
WARNING:pystan:Rhat above 1.1 or below 0.9 indicates that the chains very likely have not mixed
Inference for Stan model: anon_model_de61fa4ba36aec97a90942d72fb6e60c.
4 chains, each with iter=1000; warmup=500; thin=1;
post-warmup draws per chain=500, total post-warmup draws=2000.
mean se_mean sd 2.5% 25% 50% 75% 97.5% n_eff Rhat
firepower 45.98 0.87 18.65 12.79 31.29 46.17 60.95 80.27 460 1.01
hit_heavy_z 0.61 0.02 0.49 0.03 0.22 0.48 0.87 1.91 453 1.01
hit_light_z 0.82 0.02 0.61 0.04 0.33 0.71 1.2 2.24 878 1.0
fire_hit 4.6 0.09 1.87 1.28 3.13 4.62 6.1 8.03 460 1.01
fire_heavy 0.0 nan 0.0 0.0 0.0 0.0 0.0 0.0 nan nan
fire_light 4.6 0.09 1.87 1.28 3.13 4.62 6.1 8.03 460 1.01
hit_heavy 6.1e-7 2.3e-8 4.9e-7 2.9e-8 2.2e-7 4.8e-7 8.7e-7 1.9e-6 453 1.01
hit_light 0.78 1.6e-3 0.07 0.65 0.73 0.77 0.82 0.93 2134 1.0
hit 0.78 1.6e-3 0.07 0.65 0.73 0.77 0.82 0.93 2134 1.0
lp__ -47.98 0.05 1.26 -51.15 -48.6 -47.69 -47.01 -46.45 656 1.0
Samples were drawn using NUTS at Fri Jul 3 22:57:55 2020.
For each parameter, n_eff is a crude measure of effective sample size,
and Rhat is the potential scale reduction factor on split chains (at
convergence, Rhat=1).
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment