Skip to content

Commit b90e91f

Browse files
author
nguyenta
committed
feat: remove visualization, show objective function of each variable
1 parent 900bab8 commit b90e91f

File tree

14 files changed

+241
-1625
lines changed

14 files changed

+241
-1625
lines changed

R/displayOutput.R

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,3 +459,54 @@ findSoilGroupSWATPlus <- function(TxtInOut){
459459

460460
return(soilGroup)
461461
}
462+
463+
464+
# ------------------------------------------------------------------------------
465+
# Display objective function value for each variable
466+
# ------------------------------------------------------------------------------
467+
objFunctionEachVar <- function(perCriteria, caliOrValid){
468+
pc <- list()
469+
# Convert list of vector to list of data frame
470+
for (i in 1:length(perCriteria)){
471+
for (j in 1:length(perCriteria[[1]])){
472+
if (j == 1){
473+
pc[[i]] <- perCriteria[[i]][[j]]
474+
} else {
475+
pc[[i]] <- rbind(pc[[i]],perCriteria[[i]][[j]] )
476+
}
477+
}
478+
479+
colnames(pc[[i]]) <- paste0(caliOrValid, "var_", i, "_", colnames(pc[[i]]))
480+
}
481+
482+
# Convert list of data frame to data frame
483+
if (length(pc) > 1){
484+
485+
pcDataFrame <- pc[[1]]
486+
for (i in 2:length(pc)){
487+
pcDataFrame <- cbind(pcDataFrame, pc[[i]])
488+
}
489+
} else {
490+
pcDataFrame <- pc[[1]]
491+
}
492+
493+
# round up to 3 digits
494+
pcDataFrame <- round(pcDataFrame, digits = 3)
495+
496+
# Return result
497+
return(pcDataFrame)
498+
}
499+
500+
# ------------------------------------------------------------------------------
501+
# Display objective function value for each variable
502+
# ------------------------------------------------------------------------------
503+
objFunctionEachVarCaliValid <- function(perCriteriaCali, perCriteriaValid){
504+
505+
pcDataFrameCali <- objFunctionEachVar(perCriteriaCali, "cali_")
506+
pcDataFrameValid <- objFunctionEachVar(perCriteriaValid, "valid_")
507+
simNr <- data.frame(SimNr = c(1:nrow(pcDataFrameCali)))
508+
509+
# Return result
510+
return(cbind(simNr, pcDataFrameCali, pcDataFrameValid))
511+
512+
}

R/hruFunctions.R

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
1-
2-
# Install and load required packages
3-
# install.packages("raster")
4-
# install.packages("rgdal")
5-
6-
library(raster)
7-
library(rgdal)
8-
library(plotly)
9-
library(shinydashboard)
10-
library(shinyFiles)
11-
121
# ------------------------------------------------------------------------------
132
getDate <- function(TxtInOut){
143
file_cio <- readLines(paste(TxtInOut, "/file.cio", sep = ""), 60)

R/hruUI.R

Lines changed: 0 additions & 134 deletions
This file was deleted.

R/loadPackages.R

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ requiredPackages <- c('foreach', # version >= 1.5.2
1010
'doParallel', # version >= 1.0.17
1111
'lhs', # version >= 1.1.4
1212
'plotly', # version >= 4.10.0
13-
'ggplot2', # version >= 3.3.5
14-
'rgdal', # version >= 1.5-28
15-
'raster', # version >= 3.5-15
13+
'ggplot2', # version >= 3.5-15
1614
'shiny', # version >= 1.7.1
1715
'shinyjs',
1816
'shinydashboard', # version >= 0.7.2
@@ -24,11 +22,10 @@ requiredPackages <- c('foreach', # version >= 1.5.2
2422
'optimization', # version >= 1.0-9
2523
'hydroPSO', # version >= 0.5-1
2624
'nloptr', # version >= 2.0.0
27-
'spsComps' # version >= 0.3.2.1
28-
)
25+
'spsComps') # version >= 0.3.2.1)
2926

3027
# Check and install only missing packages
31-
install.packages(setdiff(requiredPackages,rownames(installed.packages())), dependencies = TRUE)
28+
install.packages(setdiff(requiredPackages, rownames(installed.packages())), dependencies = TRUE)
3229

3330
# Update these packages if it has not been updated
3431
update.packages(requiredPackages, ask = FALSE)

R/objFunction.R

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,6 @@ calObjFunction <- function(parameterValue, ncores,
312312
output$objValueValid[counter[j]] <- output$objValueValid[counter[j]] +
313313
output$perCriteriaValid[[j]][[counter[j]]][perIndex]
314314
}
315-
316315
}
317316
}
318317
}
@@ -324,23 +323,34 @@ calObjFunction <- function(parameterValue, ncores,
324323

325324
# Select calibration data with flag "C" or "c"
326325
flag <- c("C", "c")
327-
output$objValueCali[count] <- userObjFunction(observedToList(observedData, flag),
328-
simToList(simData, count, flag))
329-
326+
temp <- userObjFunction(observedToList(observedData, flag),
327+
simToList(simData, count, observedData, flag))
328+
output$objValueCali[count] <- temp$overalPerCriteria
329+
330+
for (j in 1:nOutputVar){
331+
output$perCriteriaCali[[j]][[count]] <- temp$perCriteria[[j]]
332+
}
333+
334+
330335
# Select validation data with flag "V" or "v"
331-
flag <- c("V", "v")
332-
output$objValueCali[count] <- userObjFunction(observedToList(observedData, flag),
333-
simToList(simData, count, observedData, flag))
336+
flag <- c("V", "v")
337+
temp <- userObjFunction(observedToList(observedData, flag),
338+
simToList(simData, count, observedData, flag))
339+
output$objValueValid[count] <- temp$overalPerCriteria
340+
for (j in 1:nOutputVar){
341+
output$perCriteriaValid[[j]][[count]] <- temp$perCriteria[[j]]
342+
}
334343
}
335-
}
336-
344+
}
337345
}
338346

339347
if (index != 'userObjFunction'){
340348
output$objValueCali <- output$objValueCali/nOutputVar
341349
output$objValueValid <- output$objValueValid/nOutputVar
342350
}
343351

352+
353+
344354
return(output)
345355
}
346356

R/rchUI.R

Lines changed: 0 additions & 78 deletions
This file was deleted.

0 commit comments

Comments
 (0)