-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFigures - MSE plot.R
More file actions
105 lines (85 loc) · 3.27 KB
/
Copy pathFigures - MSE plot.R
File metadata and controls
105 lines (85 loc) · 3.27 KB
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
############################################################################
## Script that plots and saves the MSE simulation boxplots as eps files.
## Author: Pablo Morala
###########################################################################
library(ggplot2)
library(cowplot)
library(ggsci)
library(patchwork)
IEEE_width_inches <- 3.5
my_width <- IEEE_width_inches
####################################
# 2 - Define needed functions
####################################
reshapingMSESimulations=function(simulation,h_l,L){
rownames(simulation)=c("tanh", "softplus", "sigmoid")
n_sim=dim(simulation)[2]
df=as.data.frame(t(simulation))
df$Layers=as.factor(rep(L,n_sim))
df$Neurons_per_layer=as.factor(rep(h_l,n_sim))
df=reshape::melt(df,id.vars=c("Layers","Neurons_per_layer"))
names(df)[c(3,4)]=c("Act.Function","MSE")
return(df)
}
####################################
# 3 - Plot the simulations:
####################################
# Load the data
h_neurons_at_each_layer_vector <- c(50,100)
the_3_chosen_af <- c("tanh","softplus","sigmoid")
n_hidden_layers <- c(1,3,5,7)
simulation_NN_vs_poly <- vector(mode = "list", length = 0L)
simulation_NN_vs_original <- vector(mode = "list", length = 0L)
i <- 1
for (h_l in h_neurons_at_each_layer_vector){
for (L in n_hidden_layers){
aux <- readRDS(paste0("data/Simulation_NN_vs_poly_adam_Hidden_per_layer_",
h_l,
"_number_layers_",
L))
simulation_NN_vs_poly[[i]] <- reshapingMSESimulations(aux, paste0("h_l = ",h_l) , L)
aux <- readRDS(paste0("data/Simulation_NN_vs_original_adam_Hidden_per_layer_",
h_l,
"_number_layers_",
L))
simulation_NN_vs_original[[i]] <- reshapingMSESimulations(aux, paste0("h_l = ",h_l), L)
i <- i+1
}
}
df_NN_vs_poly <- NULL
df_NN_vs_original <- NULL
for (j in 1: length(simulation_NN_vs_poly)){
df_NN_vs_poly <- rbind(df_NN_vs_poly, simulation_NN_vs_poly[[j]])
df_NN_vs_original <- rbind(df_NN_vs_original, simulation_NN_vs_original[[j]])
}
# Y axis breakpoints
# my_breaks <- 10^c(-5,-3,-1,1,3,5,7,9,11)
df_NN_vs_poly <- na.omit(df_NN_vs_poly)
# Create the plot
plot1 <- ggplot(df_NN_vs_poly, aes(x = Layers, y = MSE, fill = Act.Function)) +
geom_boxplot() +
facet_grid(Neurons_per_layer ~ .) +
labs(fill = "Activation\n Function") +
xlab("Number of hidden layers") +
scale_y_continuous("MSE between NN and obtained PR", trans = "log10")+
scale_fill_jco() +
theme_half_open() +
background_grid(major = "y")
plot1
# Create the plot
plot2 <- ggplot(df_NN_vs_original, aes(x = Layers, y = MSE, fill = Act.Function)) +
geom_boxplot() +
facet_grid(Neurons_per_layer ~ .) +
labs(fill = "Activation\n Function") +
xlab("Number of hidden layers") +
scale_y_continuous("MSE between NN and original Y", trans = "log10")+
scale_fill_jco() +
theme_half_open() +
background_grid(major = "y")
plot2
plotfinal <- plot1 + plot2 + plot_layout(guides = 'collect')
plotfinal
# Save as pdf as to avoid problems in arxiv
pdf(file="temporal/fig_MSE.pdf", width = 4*my_width, height = 1.5*my_width)
plotfinal
dev.off()