-
Notifications
You must be signed in to change notification settings - Fork 1
/
figure-trials-observation.r
108 lines (80 loc) · 2.77 KB
/
figure-trials-observation.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
### * Load local library
source ("paths.r")
### * Load the system packages
load.pkgs ("limSolve")
fold <- function (x, n) {
ret <- c ()
i <- 1
x <- x [sample (seq (1, nrow (x))), ]
while (i <= nrow (x)) {
idx <- seq (i, min (nrow (x), i + n - 1))
if (length (idx) == 1)
ret <- rbind (ret, x [idx, ])
else
ret <- rbind (ret, colMeans (x [idx,]))
i <- i + n
}
return (ret)
}
### Output types
outputs <- c ("phy", "psy")
title <- list (phy = "Φ", psy = "Ψ")
cairo_pdf (file = file.path (figures.dir,"trials-observation.pdf"),
width = 8, height = 4)
par(mfrow=c(1,2))
for (out in outputs) {
results <- data.frame (subject = integer (),
fold.size = integer (),
nb.points = integer (),
rms = numeric ())
for (subj in cohort) {
load (cv.filename ("VOT", "Ativo", subj))
s <- dwt.coefs.cv$stimulus
r <- dwt.coefs.cv$response
if (out == "phy")
## FIXME : the value 68 (= 16 - (-52)) is hardcoded below, but
## should be obtained programatically
Y <- 68 * phy.out [subj, ] / 200
else
Y <- psy.out
n <- 1
while (TRUE) {
s2 <- r2 <- c ()
for (i in seq (1, 5)) {
idx <- which (s == i)
ri <- fold (r [idx,], n)
s2 <- c (s2, rep (i, nrow (ri)))
r2 <- rbind (r2, ri)
}
if (length (s2) < ncol (r2))
break
x <- cbind (r2, rep (1, nrow (r2)))
y <- Y [s2]
b <- Solve (x, y)
results <- rbind (results,
data.frame (subject = subj,
fold.size = n,
nb.points = length (s2),
rms = sqrt (mean ((y - x %*% b)^2))))
n <- n + 1
}
}
m <- aggregate (rms ~ fold.size, results, mean)
std <- aggregate (rms ~ fold.size, results, sd)
par (mar = c (5, 4, 0, 1) + 0.1)
ylm = c (0, max (m$rms + std$rms))
xlm = c (0.5, 6.5)
plot (m$fold.size [1 : 6], m$rms [1 : 6], pch = 16, cex = 2,
ylim = ylm,
xlim = xlm, bty = "n", las = 1,
ylab = paste ("RMS prediction error",
ifelse (out == "phy", " (ms)", ""),
sep = ""),
xlab = "trials per observation")
for (i in seq (1, 6))
lines (rep (std$fold.size [i], 2), m$rms [i] + c (-1, 1) * std$rms [i],
lwd = 3)
text (0.8 * max (xlm), 0.9 * max (ylm), title [[out]], adj = c (1, 1),
cex = 2)
}
dummy <- dev.off ()