-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLocomotive.R
74 lines (56 loc) · 1.61 KB
/
Locomotive.R
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
Train <- R6::R6Class("Train",
inherit = Suite,
public = list(
Likelihood = function(data, hypo){
ifelse(hypo < data, 0, 1 / hypo)
}
))
hypos <- 1:1000
suite <- Train$new(hypos)
suite$Update(60)
#df <- data.frame(suite)
plot(suite$Items(),type="l")
suite$Mean()
#Different upper bounds and more data
data <- c(60, 30, 90)
upperBounds <- c(500, 1000, 2000)
for(bound in upperBounds){
suite <- Train$new(1:bound)
for(dat in data){
suite$Update(dat)
}
cat(bound, suite$Mean(),"\n")
}
Train <- R6::R6Class("Train",
inherit = Suite,
public = list(
InitSequence = function(values){
#values <- as.character(values)
for (value in values)
self$Set(value, value ^ -1)
},
Likelihood = function(data, hypo){
ifelse(hypo < data, 0, 1 / hypo)
}
))
hypos <- 1:1000
suite <- Train$new(hypos)
suite$Update(60)
plot(suite$Items(),type="l")
suite$Mean()
data <- c(60, 30, 90)
upperBounds <- c(500, 1000, 2000)
for(bound in upperBounds){
suite <- Train$new(1:bound)
for(dat in data){
suite$Update(dat)
}
cat(bound, suite$Mean(),"\n")
}
## Credible interval
data <- c(60, 30, 90)
suite <- Train$new(1:1000)
for(dat in data){
suite$Update(dat)
}
cat(Percentile(suite,5), ",",Percentile(suite,95))