Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 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 All @@ -54,7 +54,7 @@ model.calibration(parameters_fname = "Input/Functions_list_Calibration.csv",
lb_v = c(0.01, 0.0001),
ub_v = c(0.05, 0.002),
max.time = 2
)
)

end_time <- Sys.time()-start_time

Expand All @@ -79,15 +79,17 @@ model.analysis(solver_fname = "Net/SIR.solver",
solver_type = "LSODA",
f_time = 7*10, # weeks
s_time = 1
)
)

source("Rfunction/ModelAnalysisPlot.R")

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

model_analysis(solver_fname = "Net/SIR.solver",

AnalysisPlot$plAll

model.analysis(solver_fname = "Net/SIR.solver",
parameters_fname = "Input/Functions_list_ModelAnalysis.csv",
solver_type = "SSA",
n_run = 500,
Expand All @@ -98,6 +100,8 @@ 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


17 changes: 11 additions & 6 deletions ReadME.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,14 @@ the number is located, 3) a second integer that is the index of the column.
on a file which contain a numeric matrix where the first column symbolize
a list of time steps as a list of numbers sorting in ascending order. The
function takes as parameters 1) a string which represents the name
of the file 2) an integer that is the time we are interested in and based on which
of the file 2) An integer representing the index of the
column of the matrix, which goes from 0 to n-2 where n is the total number of columns.
The *i-th* time step representing the index of the row
we are interested in is automatically passed inside the process as an integer; thanks to it
we will extract the index of the row. The exact value of time
may not be present in the first column so the index of the row is
selected as the position of the first value lower than the one passed
as parameter. 3) An integer representing the index of the
column of the matrix.
as parameter.

SIRFile:
3,9,13
Expand All @@ -221,9 +223,12 @@ column of the matrix.
16,90,23
33,44,88

FromTimeTable["SIRFile", 1,1] = 13
FromTimeTable["BSIRFile", 10,1] = 1
FromTimeTable["SIRFile", 50,1] = 88
Time step: 1
FromTimeTable["SIRFile",1] = 13
Time step: 10
FromTimeTable["SIRFile",1] = 1
Time step: 50
FromTimeTable["SIRFile",0] = 44

<img src="./Images/SIR_FromFile_place.png" alt="\label{fig:SIR_PN} Petri Net representation of the SIR model." width="1327" />
<p class="caption">
Expand Down
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)
}
}
15 changes: 8 additions & 7 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 @@ -28,15 +29,15 @@ SensitivityPlot <-function(rank=T,folder){
sep = ""))



#Corrected the names of the .trace file in accord to the new path
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,7 +47,7 @@ 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)
Expand Down