-
Notifications
You must be signed in to change notification settings - Fork 0
/
ebisu3_binomial.stan
53 lines (49 loc) · 1.15 KB
/
ebisu3_binomial.stan
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
functions {
real clampLerp(real x1, real x2, real y1, real y2, real x) {
real mu = (x - x1) / (x2 - x1);
real y = (y1 * (1 - mu) + y2 * mu);
return fmin(y2, fmax(y1, y));
}
int success(int nSuccess, int nTotal) {
return 2 * nSuccess >= nTotal;
}
}
data {
// quiz history
int<lower=0> T;
array[T] int successes;
array[T] int totals;
array[T] real<lower=0> t;
// algorithm parameters
real left;
real right;
real<lower=0> alphaHl;
real<lower=0> betaHl;
real<lower=0> alphaBoost;
real<lower=0> betaBoost;
}
parameters {
real<lower=0> hl0;
real<lower=0> boost;
}
transformed parameters {
array[T] real<lower=0> hl;
hl[1] = hl0; // halflife for quiz 1
for (n in 2:T) {
real thisBoost = success(successes[n-1], totals[n-1])
? clampLerp(left * hl[n-1], right * hl[n-1], 1.0, fmax(boost, 1.0), t[n-1])
: 1.0;
hl[n] = thisBoost * hl[n-1];
}
array[T] real<lower=0, upper=1> prob;
for (n in 1:T) {
prob[n] = exp(-t[n] / hl[n] * log2());
}
}
model {
hl0 ~ gamma(alphaHl, betaHl);
boost ~ gamma(alphaBoost, betaBoost);
for (n in 1:T) {
successes[n] ~ binomial(totals[n], prob[n]);
}
}