-
Notifications
You must be signed in to change notification settings - Fork 1
/
run-cv.r
91 lines (70 loc) · 2.88 KB
/
run-cv.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
### Run de cross-validation on the whole set of subjects
### This program is part of RoLDSIS
###
### Copyright (C) 2020 Rafael Laboissière
### Copyright (C) 2020 Adrielle de Carvalho Santana
### Copyright (C) 2020 Hani Camille Yehia
###
### This program is free software: you can redistribute it and/or modify it
### under the terms of the GNU General Public License as published by the
### Free Software Foundation, either version 3 of the License, or (at your
### option) any later version.
###
### This program is distributed in the hope that it will be useful, but
### WITHOUT ANY WARRANTY; without even the implied warranty of
### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
### General Public License for more details.
###
### You should have received a copy of the GNU General Public License along
### with this program. If not, see <http://www.gnu.org/licenses/>.
### * Load the local libraries
source ("paths.r")
source ("compare-methods.r")
source ("dwt-parameters.r")
outputs <- c ("phy", "psy")
### * Loop over output types
for (out in outputs) {
## ** Initialize output variables
cv.df <- data.frame (method = c (), subject = c (), nb.folds = c (),
sse.train = c (), sse.test = c ())
cv.results <- list ()
## ** Loop over the cohort
for (subj in cohort) {
## *** Initialize subject slot
cv.results [[subj]] <- list ()
## *** Load data for that subject
load (cv.filename (cv.exp.feature, cv.exp.type, subj))
## *** Loop over the required numbers of folds
for (i in seq (1, length (cv.nb.folds))) {
## *** Get number of folds
n <- cv.nb.folds [i]
cat (sprintf ("subject: %02d nb.folds: %d\n", subj, n))
## *** Get the AER and the output values
x <- dwt.coefs.cv$response
if (out == "phy")
Y <- phy.out [subj, ] / 200
else
Y <- psy.out
y <- Y [dwt.coefs.cv$stimulus]
## ** Run cross-validations
r <- compare.methods (x, y, n)
cat ("\n")
## ** Store the results
cv.results [[subj]] [[i]] <- r
## ** Compose the output data frame
for (j in names (r))
cv.df <- rbind (cv.df,
data.frame (method = j,
subject = subj,
nb.folds = n,
sse.train = r [[j]]$sse.train,
sse.test = mean (r [[j]]$sse.test)))
## ** Flush the progress meter
flush (stdout ())
}
} # subj
## ** Save results
save (file = file.path (results.dir,
sprintf ("cross-validation-%s.dat", out)),
cv.results, cv.df)
} # resp