forked from comp-cogneuro-lang/EARShot_TF2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRSA_Permutation_Test(Fig.5).R
231 lines (198 loc) · 14 KB
/
RSA_Permutation_Test(Fig.5).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
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
# Setup ----
rm(list=ls())
library(lme4) library(afex) library(ggplot2) library(tidyr) library(plyr) library(dplyr)
library(Rmisc) library(reshape) library(car)
base_Dir <- 'D:/Python_Programming/EARShot_TF2/Results'
identifier_List <- c('AGNES')
epoch_List <- c(4000)
index <- 0
for (epoch in epoch_List)
{
for (identifier in identifier_List)
{
work_Dir <- file.path(base_Dir, paste(identifier, '.', 'IDX', index, sep=''), 'Hidden')
theme_set(theme_classic(base_size=20))
# RSA 1 : EARSHOT PSI RDM and Mesgarani PSI RDM ----
rsa01_actual <- read.csv(file.path(work_Dir, 'Map', 'PSI', 'RSA', 'RSA.EARShot_to_Mesgarani.PSI.Actual.csv'),
header = TRUE, sep = ',', na.strings = "#N/A")
rsa01_shuffle <- read.csv(file.path(work_Dir, 'Map', 'PSI', 'RSA', 'RSA.EARShot_to_Mesgarani.PSI.Shuffle.csv'),
header = TRUE, sep = ',', na.strings = "#N/A")
p01_cosine <- 1-sum(rsa01_shuffle$cosine < rsa01_actual$cosine)/length(rsa01_shuffle$cosine)
p01_correlation <- 1-sum(rsa01_shuffle$correlation < rsa01_actual$correlation)/length(rsa01_shuffle$correlation)
p01_euclidean <- 1-sum(rsa01_shuffle$euclidean < rsa01_actual$euclidean)/length(rsa01_shuffle$euclidean)
gpplot <- ggplot(rsa01_shuffle, aes(cosine)) + geom_histogram(binwidth = 0.001, fill = "#B32A23") +
geom_vline(xintercept = rsa01_actual$cosine, linetype="solid", color = "#233DB3", size=1.5) +
coord_cartesian(xlim = c(-0.3, 1)) +
labs(x = "Correlation", y = 'Count',
title = "RSA: EARSHOT PSI and Mesgarani PSI", subtitle = "RDM based on cosine") +
annotate(geom = "text", x = rsa01_actual$cosine + 0.05,
y = max(table(round(rsa01_shuffle$cosine, 3))), hjust = 0, angle = 0, label = paste0("r = ", round(rsa01_actual$cosine,3)),
fontface = 2, size = 5, color = "#233DB3")
ggsave(plot = gpplot,
filename = file.path(work_Dir, 'Map', 'PSI', 'RSA', 'RSA.EARSHOT_to_Mesgarani.PSI.Cosine.png'),
width = 10, height = 5,
bg = "transparent")
gpplot <- ggplot(rsa01_shuffle, aes(correlation)) + geom_histogram(binwidth = 0.001, fill = "#B32A23") +
geom_vline(xintercept = rsa01_actual$correlation, linetype="solid", color = "#233DB3", size=1.5) +
coord_cartesian(xlim = c(-0.3, 1)) +
labs(x = "Correlation", y = 'Count',
title = "RSA: EARSHOT PSI and Mesgarani PSI", subtitle = "RDM based on correlation") +
annotate(geom = "text", x = rsa01_actual$correlation + 0.05,
y = max(table(round(rsa01_shuffle$correlation, 3))), hjust = 0, angle = 0, label = paste0("r = ", round(rsa01_actual$correlation,3)),
fontface = 2, size = 5, color = "#233DB3")
ggsave(plot = gpplot,
filename = file.path(work_Dir, 'Map', 'PSI', 'RSA', 'RSA.EARSHOT_to_Mesgarani.PSI.Correlation.png'),
width = 10, height = 5,
bg = "transparent")
gpplot <- ggplot(rsa01_shuffle, aes(euclidean)) + geom_histogram(binwidth = 0.001, fill = "#B32A23") +
geom_vline(xintercept = rsa01_actual$euclidean, linetype="solid", color = "#233DB3", size=1.5) +
coord_cartesian(xlim = c(-0.3, 1)) +
labs(x = "Correlation", y = 'Count',
title = "RSA: EARSHOT PSI and Mesgarani PSI", subtitle = "RDM based on Euclidean distance") +
annotate(geom = "text", x = rsa01_actual$euclidean + 0.05,
y = max(table(round(rsa01_shuffle$euclidean, 3))), hjust = 0, angle = 0, label = paste0("r = ", round(rsa01_actual$euclidean,3)),
fontface = 2, size = 5, color = "#233DB3")
ggsave(plot = gpplot,
filename = file.path(work_Dir, 'Map', 'PSI', 'RSA', 'RSA.EARSHOT_to_Mesgarani.PSI.Euclidean.png'),
width = 10, height = 5,
bg = "transparent")
# RSA 2 : EARSHOT FSI RDM and Mesgarani FSI RDM ----
rsa02_actual <- read.csv(file.path(work_Dir, 'Map', 'FSI', 'RSA', 'RSA.EARShot_to_Mesgarani.FSI.Actual.csv'),
header = TRUE, sep = ',', na.strings = "#N/A")
rsa02_shuffle <- read.csv(file.path(work_Dir, 'Map', 'FSI', 'RSA', 'RSA.EARShot_to_Mesgarani.FSI.Shuffle.csv'),
header = TRUE, sep = ',', na.strings = "#N/A")
p02_cosine <- 1-sum(rsa02_shuffle$cosine < rsa02_actual$cosine)/length(rsa02_shuffle$cosine)
p02_correlation <- 1-sum(rsa02_shuffle$correlation < rsa02_actual$correlation)/length(rsa02_shuffle$correlation)
p02_euclidean <- 1-sum(rsa02_shuffle$euclidean < rsa02_actual$euclidean)/length(rsa02_shuffle$euclidean)
gpplot <- ggplot(rsa02_shuffle, aes(cosine)) + geom_histogram(binwidth = 0.001, fill = "#B32A23") +
geom_vline(xintercept = rsa02_actual$cosine, linetype="solid", color = "#233DB3", size=1.5) +
coord_cartesian(xlim = c(-0.3, 1)) +
labs(x = "Correlation", y = 'Count',
title = "RSA: EARSHOT FSI and Mesgarani FSI", subtitle = "RDM based on cosine") +
annotate(geom = "text", x = rsa02_actual$cosine - 0.3,
y = max(table(round(rsa02_shuffle$cosine, 3))), hjust = 0, angle = 0, label = paste0("r = ", round(rsa02_actual$cosine,3)),
fontface = 2, size = 5, color = "#233DB3")
ggsave(plot = gpplot,
filename = file.path(work_Dir, 'Map', 'FSI', 'RSA', 'RSA.EARSHOT_to_Mesgarani.FSI.Cosine.png'),
width = 10, height = 5,
bg = "transparent")
gpplot <- ggplot(rsa02_shuffle, aes(correlation)) + geom_histogram(binwidth = 0.001, fill = "#B32A23") +
geom_vline(xintercept = rsa02_actual$correlation, linetype="solid", color = "#233DB3", size=1.5) +
coord_cartesian(xlim = c(-0.3, 1)) +
labs(x = "Correlation", y = 'Count',
title = "RSA: EARSHOT FSI and Mesgarani FSI", subtitle = "RDM based on correlation") +
annotate(geom = "text", x = rsa02_actual$correlation - 0.3,
y = max(table(round(rsa02_shuffle$correlation, 3))), hjust = 0, angle = 0, label = paste0("r = ", round(rsa02_actual$correlation,3)),
fontface = 2, size = 5, color = "#233DB3")
ggsave(plot = gpplot,
filename = file.path(work_Dir, 'Map', 'FSI', 'RSA', 'RSA.EARSHOT_to_Mesgarani.FSI.Correlation.png'),
width = 10, height = 5,
bg = "transparent")
gpplot <- ggplot(rsa02_shuffle, aes(euclidean)) + geom_histogram(binwidth = 0.001, fill = "#B32A23") +
geom_vline(xintercept = rsa02_actual$euclidean, linetype="solid", color = "#233DB3", size=1.5) +
coord_cartesian(xlim = c(-0.3, 1)) +
labs(x = "Correlation", y = 'Count',
title = "RSA: EARSHOT FSI and Mesgarani FSI", subtitle = "RDM based on Euclidean distance") +
annotate(geom = "text", x = rsa02_actual$euclidean - 0.3,
y = max(table(round(rsa02_shuffle$euclidean, 3))), hjust = 0, angle = 0, label = paste0("r = ", round(rsa02_actual$euclidean,3)),
fontface = 2, size = 5, color = "#233DB3")
ggsave(plot = gpplot,
filename = file.path(work_Dir, 'Map', 'FSI', 'RSA', 'RSA.EARSHOT_to_Mesgarani.FSI.Euclidean.png'),
width = 10, height = 5,
bg = "transparent")
# RSA 3 : EARSHOT PSI RDM and Phoneme Feature RDM ----
rsa03_actual <- read.csv(file.path(work_Dir, 'Map', 'PSI', 'RSA', 'RSA.EARShot_to_Phoneme_Feature.PSI.Actual.csv'),
header = TRUE, sep = ',', na.strings = "#N/A")
rsa03_shuffle <- read.csv(file.path(work_Dir, 'Map', 'PSI', 'RSA', 'RSA.EARShot_to_Mesgarani.PSI.Shuffle.csv'),
header = TRUE, sep = ',', na.strings = "#N/A")
p03_cosine <- 1-sum(rsa03_shuffle$cosine < rsa03_actual$cosine)/length(rsa03_shuffle$cosine)
p03_correlation <- 1-sum(rsa03_shuffle$correlation < rsa03_actual$correlation)/length(rsa03_shuffle$correlation)
p03_euclidean <- 1-sum(rsa03_shuffle$euclidean < rsa03_actual$euclidean)/length(rsa03_shuffle$euclidean)
gpplot <- ggplot(rsa03_shuffle, aes(cosine)) + geom_histogram(binwidth = 0.001, fill = "#B32A23") +
geom_vline(xintercept = rsa03_actual$cosine, linetype="solid", color = "#233DB3", size=1.5) +
coord_cartesian(xlim = c(-0.3, 1)) +
labs(x = "Correlation", y = 'Count',
title = "RSA: EARSHOT PSI and Phoneme Feature Vectors",
subtitle = "RDM based on cosine") +
annotate(geom = "text", x = rsa03_actual$cosine + 0.05,
y = max(table(round(rsa03_shuffle$cosine, 3))), hjust = 0, angle = 0, label = paste0("r = ", round(rsa03_actual$cosine,3)),
fontface = 2, size = 5, color = "#233DB3")
ggsave(plot = gpplot,
filename = file.path(work_Dir, 'Map', 'PSI', 'RSA', 'RSA.EARSHOT_to_Phoneme_Feature.PSI.Cosine.png'),
width = 10, height = 5,
bg = "transparent")
gpplot <- ggplot(rsa03_shuffle, aes(correlation)) + geom_histogram(binwidth = 0.001, fill = "#B32A23") +
geom_vline(xintercept = rsa03_actual$correlation, linetype="solid", color = "#233DB3", size=1.5) +
coord_cartesian(xlim = c(-0.3, 1)) +
labs(x = "Correlation", y = 'Count',
title = "RSA: EARSHOT PSI and Phoneme Feature Vectors",
subtitle = "RDM based on correlation") +
annotate(geom = "text", x = rsa03_actual$correlation + 0.05,
y = max(table(round(rsa03_shuffle$correlation, 3))), hjust = 0, angle = 0, label = paste0("r = ", round(rsa03_actual$correlation,3)),
fontface = 2, size = 5, color = "#233DB3")
ggsave(plot = gpplot,
filename = file.path(work_Dir, 'Map', 'PSI', 'RSA', 'RSA.EARSHOT_to_Phoneme_Feature.PSI.Correlation.png'),
width = 10, height = 5,
bg = "transparent")
gpplot <- ggplot(rsa03_shuffle, aes(euclidean)) + geom_histogram(binwidth = 0.001, fill = "#B32A23") +
geom_vline(xintercept = rsa03_actual$euclidean, linetype="solid", color = "#233DB3", size=1.5) +
coord_cartesian(xlim = c(-0.3, 1)) +
labs(x = "Correlation", y = 'Count',
title = "RSA: EARSHOT PSI and Phoneme Feature Vectors",
subtitle = "RDM based on Euclidean distance") +
annotate(geom = "text", x = rsa03_actual$euclidean + 0.05,
y = max(table(round(rsa03_shuffle$euclidean, 3))), hjust = 0, angle = 0, label = paste0("r = ", round(rsa03_actual$euclidean,3)),
fontface = 2, size = 5, color = "#233DB3")
ggsave(plot = gpplot,
filename = file.path(work_Dir, 'Map', 'PSI', 'RSA', 'RSA.EARSHOT_to_Phoneme_Feature.PSI.Euclidean.png'),
width = 10, height = 5,
bg = "transparent")
# RSA 4 : Mesgarani PSI RDM and Phoneme Feature RDM ----
rsa04_actual <- read.csv(file.path(work_Dir, 'Map', 'PSI', 'RSA', 'RSA.Phoneme_Feature_to_Mesgarani.PSI.Actual.csv'),
header = TRUE, sep = ',', na.strings = "#N/A")
rsa04_shuffle <- read.csv(file.path(work_Dir, 'Map', 'PSI', 'RSA', 'RSA.Phoneme_Feature_to_Mesgarani.PSI.Shuffle.csv'),
header = TRUE, sep = ',', na.strings = "#N/A")
p04_cosine <- 1-sum(rsa04_shuffle$cosine < rsa04_actual$cosine)/length(rsa04_shuffle$cosine)
p04_correlation <- 1-sum(rsa04_shuffle$correlation < rsa04_actual$correlation)/length(rsa04_shuffle$correlation)
p04_euclidean <- 1-sum(rsa04_shuffle$euclidean < rsa04_actual$euclidean)/length(rsa04_shuffle$euclidean)
gpplot <- ggplot(rsa04_shuffle, aes(cosine)) + geom_histogram(binwidth = 0.001, fill = "#B32A23") +
geom_vline(xintercept = rsa04_actual$cosine, linetype="solid", color = "#233DB3", size=1.5) +
coord_cartesian(xlim = c(-0.3, 1)) +
labs(x = "Correlation", y = 'Count',
title = "RSA: Mesgarani PSI and Phoneme Feature Vectors",
subtitle = "RDM based on cosine") +
annotate(geom = "text", x = rsa04_actual$cosine + 0.05,
y = max(table(round(rsa04_shuffle$cosine, 3))), hjust = 0, angle = 0, label = paste0("r = ", round(rsa04_actual$cosine,3)),
fontface = 2, size = 5, color = "#233DB3")
ggsave(plot = gpplot,
filename = file.path(work_Dir, 'Map', 'PSI', 'RSA', 'RSA.Phoneme_Feature_to_EARSHOT.PSI.Cosine.png'),
width = 10, height = 5,
bg = "transparent")
gpplot <- ggplot(rsa04_shuffle, aes(correlation)) + geom_histogram(binwidth = 0.001, fill = "#B32A23") +
geom_vline(xintercept = rsa04_actual$correlation, linetype="solid", color = "#233DB3", size=1.5) +
coord_cartesian(xlim = c(-0.3, 1)) +
labs(x = "Correlation", y = 'Count',
title = "RSA: Mesgarani PSI and Phoneme Feature Vectors",
subtitle = "RDM based on correlation") +
annotate(geom = "text", x = rsa04_actual$correlation + 0.05,
y = max(table(round(rsa04_shuffle$correlation, 3))), hjust = 0, angle = 0, label = paste0("r = ", round(rsa04_actual$correlation,3)),
fontface = 2, size = 5, color = "#233DB3")
ggsave(plot = gpplot,
filename = file.path(work_Dir, 'Map', 'PSI', 'RSA', 'RSA.Phoneme_Feature_to_EARSHOT.PSI.Correlation.png'),
width = 10, height = 5,
bg = "transparent")
gpplot <- ggplot(rsa04_shuffle, aes(euclidean)) + geom_histogram(binwidth = 0.001, fill = "#B32A23") +
geom_vline(xintercept = rsa04_actual$euclidean, linetype="solid", color = "#233DB3", size=1.5) +
coord_cartesian(xlim = c(-0.3, 1)) +
labs(x = "Correlation", y = 'Count',
title = "RSA: Mesgarani PSI and Phoneme Feature Vectors",
subtitle = "RDM based on Euclidean distance") +
annotate(geom = "text", x = rsa04_actual$euclidean + 0.05,
y = max(table(round(rsa04_shuffle$euclidean, 3))), hjust = 0, angle = 0, label = paste0("r = ", round(rsa04_actual$euclidean,3)),
fontface = 2, size = 5, color = "#233DB3")
ggsave(plot = gpplot,
filename = file.path(work_Dir, 'Map', 'PSI', 'RSA', 'RSA.Phoneme_Feature_to_EARSHOT.PSI.Euclidean.png'),
width = 10, height = 5,
bg = "transparent")
}
}