-
Notifications
You must be signed in to change notification settings - Fork 0
/
gpeTest_leaveAllOut_rawpred_compareavg_allThreeDataSet_FINAL-NoDupes-afterlooxv.Rmd
245 lines (190 loc) · 8.31 KB
/
gpeTest_leaveAllOut_rawpred_compareavg_allThreeDataSet_FINAL-NoDupes-afterlooxv.Rmd
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
---
title: "gpeTest"
author: "Noelle"
date: "12/3/2019"
output: html_document
---
```{r}
#This file takes in all data collected, separated by PV and Lhx6, shuffled and duration not logged
#The data also have a column of the averages of the duplicate responses
#These input files from
#"Regressions_LeaveOutCopies_all3DataSets_PredictOnRaw_CompareToAvg-Testing-NoDupes-afterlooxv.ipynb"
```
```{r setup, include=FALSE}
library(kernlab)
library(ggplot2)
#Read in the PV file, replace the path below with your own path to the file
PVFile <- "~/Documents/original_data/allThreeDataPV_shuffled_withAverages_notLogged.csv"
PVData <- data.frame(read.csv(PVFile,stringsAsFactors=F))
#separate data into X and Y dataframes
XTrainPV <- data.frame(log2(PVData$Duration),PVData$Frequency,PVData$AmpMult)
XTrainPVLogged <- data.frame(log2(PVData$Duration),PVData$Frequency,PVData$AmpMult)
YTrainPV <- data.frame("ModIn"=PVData$ModIn)
colnamesPV <- c("Duration","Frequency","AmpMult")
colnames(XTrainPV) <- colnamesPV
colnames(XTrainPVLogged) <- colnamesPV
colnames(YTrainPV) <- c("ModIn")
predsVsActualPV <- data.frame(matrix(ncol=2,nrow=0),stringsAsFactors = F)
x <- c("Predictions","Actual")
colnames(predsVsActualPV) <- x
#Begin LOOXV with Gaussian Process Regression, linear kernel
count = 0
for (row in 1:nrow(XTrainPV)) {
print(count)
XTest <- data.frame(XTrainPV[row,]$Duration,XTrainPV[row,]$Frequency,XTrainPV[row,]$AmpMult)
YTest <- data.frame(YTrainPV[row,])
XTestLogged <- data.frame(XTrainPVLogged[row,]$Duration,XTrainPVLogged[row,]$Frequency,XTrainPVLogged[row,]$AmpMult)
colnames(XTest) <- c("Duration","Frequency","AmpMult")
colnames(XTestLogged) <- c("Duration","Frequency","AmpMult")
curDur = XTest$Duration
curFreq = XTest$Frequency
curAmpMult = XTest$AmpMult
#Hold out all duplicate parameter settings
delIndices = which((XTrainPV$Frequency==curFreq)&
(XTrainPV$Duration==curDur)&
(XTrainPV$AmpMult==curAmpMult))
print(delIndices)
curXTrain <- XTrainPVLogged[-c(delIndices),]
curYTrain <- YTrainPV[-c(delIndices),]
#Set GPR settings
polyVarL <- vector("list",0);
polyVarL[["degree"]] <- 1;
polyVarL[["scale"]] <- 1;
polyVarL[["offset"]] <- 1;
curSingleTestGp <- gausspr(x=curXTrain,
y=curYTrain,
type="regression",
variance.model=TRUE,
kernel=polydot,
kpar=polyVarL)
curSingleTestGp
testPrediction <- predict(curSingleTestGp,XTest)
#Store the prediction on the left out point
predsVsActualPV <- rbind(predsVsActualPV,list(testPrediction[1,1],YTest[1,1]))
count = count+1
}
#Store the predictions as aother columns
PVData$singleGPpreds = predsVsActualPV[,1]
#Repeat above, except now with a polynomial kernel
predsVsActualPV_GP2 <- data.frame(matrix(ncol=2,nrow=0),stringsAsFactors = F)
x <- c("Predictions","Actual")
colnames(predsVsActualPV_GP2) <- x
count = 0
for (row in 1:nrow(XTrainPV)) {
print(count)
XTest <- data.frame(XTrainPV[row,]$Duration,XTrainPV[row,]$Frequency,XTrainPV[row,]$AmpMult)
YTest <- data.frame(YTrainPV[row,])
XTestLogged <- data.frame(XTrainPVLogged[row,]$Duration,XTrainPVLogged[row,]$Frequency,XTrainPVLogged[row,]$AmpMult)
colnames(XTest) <- c("Duration","Frequency","AmpMult")
colnames(XTestLogged) <- c("Duration","Frequency","AmpMult")
curDur = XTest$Duration
curFreq = XTest$Frequency
curAmpMult = XTest$AmpMult
delIndices = which((XTrainPV$Frequency==curFreq)&
(XTrainPV$Duration==curDur)&
(XTrainPV$AmpMult==curAmpMult))
print(delIndices)
curXTrain <- XTrainPVLogged[-c(delIndices),]
curYTrain <- YTrainPV[-c(delIndices),]
#The kernel is polynomial this time
polyVarL <- vector("list",0);
polyVarL[["degree"]] <- 2;
polyVarL[["scale"]] <- 1;
polyVarL[["offset"]] <- 1;
curSingleTestGp <- gausspr(x=curXTrain,
y=curYTrain,
type="regression",
variance.model=TRUE,
kernel=polydot,
kpar=polyVarL)
curSingleTestGp
testPrediction <- predict(curSingleTestGp,XTest)
predsVsActualPV_GP2 <- rbind(predsVsActualPV_GP2,list(testPrediction[1,1],YTest[1,1]))
count = count+1
}
#Store predictions as a column
PVData$doubleGPpreds = predsVsActualPV_GP2[,1]
```
```{r}
#Write out the GPR predictions into a CSV file for analysis in Python
write.csv(PVData,file="PVData_wGPpredictions_allThreeDataSets.csv",row.names=FALSE)
```
```{r setup, include=FALSE}
#########
#Repeat the above steps, now for Lhx6 data, replace the path below with your path to the data
Lhx6File <- "~/Documents/original_data/allThreeDataLhx6_shuffled_withAverages_notLogged.csv"
Lhx6Data <- read.csv(Lhx6File,stringsAsFactors=F)
XTrainLhx6 <- data.frame(Lhx6Data$Duration,Lhx6Data$Frequency,Lhx6Data$AmpMult)
XTrainLhx6Logged <- data.frame(log2(Lhx6Data$Duration),Lhx6Data$Frequency,Lhx6Data$AmpMult)
YTrainLhx6 <- data.frame("ModIn"=Lhx6Data$ModIn)
colnames(XTrainLhx6) <- c("Duration","Frequency","AmpMult")
colnames(XTrainLhx6Logged) <- c("Duration","Frequency","AmpMult")
colnames(YTrainLhx6) <- c("ModIn")
predsVsActualLhx6 <- data.frame(matrix(ncol=2,nrow=0),stringsAsFactors = F)
x <- c("Predictions","Actual")
colnames(predsVsActualLhx6) <- x
for (row in 1:nrow(XTrainLhx6)) {
XTest <- data.frame(XTrainLhx6[row,]$Duration,XTrainLhx6[row,]$Frequency,XTrainLhx6[row,]$AmpMult)
XTestLogged <- data.frame(XTrainLhx6Logged[row,]$Duration,XTrainLhx6Logged[row,]$Frequency,XTrainLhx6Logged[row,]$AmpMult)
YTest <- data.frame(YTrainLhx6[row,])
colnames(XTest) <- c("Duration","Frequency","AmpMult")
colnames(XTestLogged) <- c("Duration","Frequency","AmpMult")
curDur = XTest$Duration
curFreq = XTest$Frequency
curAmpMult = XTest$AmpMult
delIndices = which((XTrainLhx6$Frequency==curFreq)&
(XTrainLhx6$Duration==curDur)&
(XTrainLhx6$AmpMult==curAmpMult))
print(delIndices)
curXTrain <- XTrainLhx6Logged[-c(delIndices),]
curYTrain <- YTrainLhx6[-c(delIndices),]
polyVarL <- vector("list",0);
polyVarL[["degree"]] <- 1;
polyVarL[["scale"]] <- 1;
polyVarL[["offset"]] <- 1;
curSingleTestGp <- gausspr(x=curXTrain,
y=curYTrain,
type="regression",
variance.model=TRUE,
kernel=polydot,
kpar=polyVarL)
curSingleTestGp
testPrediction <- predict(curSingleTestGp,XTestLogged)
predsVsActualLhx6 <- rbind(predsVsActualLhx6,list(testPrediction[1,1],YTest[1,1]))
}
Lhx6Data$singleGPpreds = predsVsActualLhx6[,1]
predsVsActualLhx6_GP2 <- data.frame(matrix(ncol=2,nrow=0),stringsAsFactors = F)
x <- c("Predictions","Actual")
colnames(predsVsActualLhx6_GP2) <- x
for (row in 1:nrow(XTrainLhx6)) {
XTest <- data.frame(XTrainLhx6[row,]$Duration,XTrainLhx6[row,]$Frequency,XTrainLhx6[row,]$AmpMult)
XTestLogged <- data.frame(XTrainLhx6Logged[row,]$Duration,XTrainLhx6Logged[row,]$Frequency,XTrainLhx6Logged[row,]$AmpMult)
YTest <- data.frame(YTrainLhx6[row,])
colnames(XTest) <- c("Duration","Frequency","AmpMult")
colnames(XTestLogged) <- c("Duration","Frequency","AmpMult")
curDur = XTest$Duration
curFreq = XTest$Frequency
curAmpMult = XTest$AmpMult
delIndices = which((XTrainLhx6$Frequency==curFreq)&
(XTrainLhx6$Duration==curDur)&
(XTrainLhx6$AmpMult==curAmpMult))
print(delIndices)
curXTrain <- XTrainLhx6Logged[-c(delIndices),]
curYTrain <- YTrainLhx6[-c(delIndices),]
polyVarL <- vector("list",0);
polyVarL[["degree"]] <- 2;
polyVarL[["scale"]] <- 1;
polyVarL[["offset"]] <- 1;
curSingleTestGp <- gausspr(x=curXTrain,
y=curYTrain,
type="regression",
variance.model=TRUE,
kernel=polydot,
kpar=polyVarL)
curSingleTestGp
testPrediction <- predict(curSingleTestGp,XTestLogged)
predsVsActualLhx6_GP2 <- rbind(predsVsActualLhx6_GP2,list(testPrediction[1,1],YTest[1,1]))
}
Lhx6Data$doubleGPpreds = predsVsActualLhx6_GP2[,1]
write.csv(Lhx6Data,file="Lhx6Data_wGPpredictions_allThreeDataSets.csv",row.names=FALSE)
```