Skip to content

Commit

Permalink
updated main and sensitivity plot by Chiabrando
Browse files Browse the repository at this point in the history
  • Loading branch information
IreneTerrone committed Nov 30, 2023
1 parent 2a3d3bc commit acfcfc9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
12 changes: 6 additions & 6 deletions Main.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ end_time <- Sys.time()-start_time
##############################
source("./Rfunction/SensitivityPlot.R")

pl = SensitivityPlot(folder = "SIR_sensitivity/")
pl = SensitivityPlot(folder = "SIR_sensitivity/", scd_folder = "SIR_analysis/")

pl$TrajS
pl$TrajI
Expand Down Expand Up @@ -85,9 +85,9 @@ source("Rfunction/ModelAnalysisPlot.R")

AnalysisPlot = ModelAnalysisPlot(Stoch = F ,print = F,
trace_path = "./SIR_analysis/SIR-analysis-1.trace")
AnalysisPlot$plI
AnalysisPlot$plAll

model_analysis(solver_fname = "Net/SIR.solver",
model.analysis(solver_fname = "Net/SIR.solver",
parameters_fname = "Input/Functions_list_ModelAnalysis.csv",
solver_type = "SSA",
n_run = 500,
Expand All @@ -98,6 +98,6 @@ model_analysis(solver_fname = "Net/SIR.solver",

AnalysisPlot = ModelAnalysisPlot(Stoch = T ,print = F,
trace_path = "./SIR_analysis/SIR-analysis-1.trace")
AnalysisPlot$plI
AnalysisPlot$HistI
plS

AnalysisPlot$plAll
AnalysisPlot$plAllMean
2 changes: 1 addition & 1 deletion Rfunction/FunctionSensitivity.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ mse<-function(reference, output)
diff.Infect <- 1/length(times_ref)*sum(( Infect - I_ref )^2 )

return(diff.Infect)
}
}
14 changes: 8 additions & 6 deletions Rfunction/SensitivityPlot.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
library(ggplot2)

SensitivityPlot <-function(rank=T,folder){
load(paste0(folder,"SIR-sensitivity.RData"))
SensitivityPlot <-function(rank=T,folder, scd_folder){
#Changed the folder in which is contained the .RData file
load(paste0(scd_folder,"SIR-analysis.RData"))
# Then, we read all the trajectories generated saving them in a list called
# ListTraces. List that will be rewritten as a data frame in order to use ggplot.
# ConfigID represents the initial condition associated to each trajectory,
# which was generated by using the function implemented in the file Functions.R .

listFile<-list.files(folder,
listFile<-list.files(scd_folder,
pattern = ".trace")

configID<-t(sapply(1:length(listFile),
Expand All @@ -32,11 +33,11 @@ SensitivityPlot <-function(rank=T,folder){
ListTraces<-lapply(id.traces,
function(x){
trace.tmp=read.csv(paste0(
folder,"/SIR-sensitivity-",
scd_folder,"SIR-analysis-",
x,
".trace"), sep = "")
trace.tmp=data.frame(trace.tmp,ID= x,
rank = rank[which(rank[,2]==paste0("SIR-sensitivity-",
rank = rank[which(rank[,2]==paste0("SIR-analysis-",
x,
".trace")),1])
return(trace.tmp)
Expand All @@ -46,13 +47,14 @@ SensitivityPlot <-function(rank=T,folder){
function(x){
recovery<-config[[4]][[x]][[3]]
infection<-config[[5]][[x]][[3]]
rnk.tmp=data.frame(ID=x,distance = rank[which(rank[,2]==paste0("SIR-sensitivity-",
rnk.tmp=data.frame(ID=x,distance = rank[which(rank[,2]==paste0("SIR-analysis-",
x,
".trace")),1],
rec_rate=recovery, inf_rate=infection)
return(rnk.tmp)
})


rank2 <- do.call("rbind", rank2)
traces <- do.call("rbind", ListTraces)

Expand Down

0 comments on commit acfcfc9

Please sign in to comment.