Skip to content

Commit

Permalink
update control pannel & GSA
Browse files Browse the repository at this point in the history
  • Loading branch information
sdyinzhen committed May 7, 2019
1 parent 2911304 commit 91a867e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 130 deletions.
24 changes: 13 additions & 11 deletions Control_Pannel.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,24 @@
"metadata": {},
"source": [
"##### Prerequisites\n",
"To enable the Auto-BEL, the users need to have the following Python modules installed (most of them should be installed already when installing Python using Anaconda) :\n",
"* numpy\n",
"To enable the Auto-BEL, the users need to have the following Python modules & R modules installed (most of them should be installed already when installing Python using Anaconda) :\n",
"\n",
"* datetime\n",
"* gc\n",
"* matplotlib\n",
"* scipy\n",
"* skfmm\n",
"* sys\n",
"* sklearn\n",
"* numpy\n",
"* os\n",
"* gc\n",
"* seaborn\n",
"* pandas\n",
"* rpy2\n",
"* random\n",
"* R \n",
"* rpy2\n",
"* R library: reshape\n",
"* seaborn\n",
"* scipy\n",
"* skfmm\n",
"* sklearn\n",
"* sys\n",
"* tqdm\n",
"* datetime\n",
"* random\n",
"* tzlocal"
]
},
Expand Down
2 changes: 1 addition & 1 deletion source_code/Auto_BEL.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from grdecl_read_plot import *
from combine_m_sampls import *
from signed_distance_functions import *
#from signed_distance_functions import *
from giip_cal import *
from scree_plot import scree_plot
from evd_fast import *
Expand Down
118 changes: 0 additions & 118 deletions source_code/dgsa/dgsa_rightcolor.R
Original file line number Diff line number Diff line change
@@ -1,81 +1,4 @@
library(reshape)
library(ggplot2)
plotCDFS <- function (.clustering, .X, .code = NULL, .nBins = 3, .ggReturn = "plot",
lwd = 1)
{
.cbbPalette <- c("#E69F00", "#56B4E9", "#009E73", "#F0E442",
"#0072B2", "#D55E00", "#CC79A7")
.order <- order(.clustering)
.clustering = .clustering[.order]
.X = .X[.order,]
if (.code == "all*") {
.ggDATA <- rbind.data.frame(data.frame(.X, clustering = "prior"),
data.frame(.X, clustering = as.character(.clustering)))
.ggDATA$clustering <- factor(.ggDATA$clustering, levels = c(as.character(unique(.clustering)),
"prior"))
.ggDATA <- melt(.ggDATA, id = c("clustering"))
.gg <- ggplot(.ggDATA) + stat_ecdf(aes(x = value, group = clustering,
colour = clustering), lwd = lwd) + ylab("Phi") +
ylim(c(0, 1)) + theme(legend.position = "top") +
xlab("parameter range") + scale_colour_manual(values = c(.cbbPalette[1:length(unique(.clustering))],
"#000000")) + facet_wrap(~variable, scales = "free_x")
}
else {
.params <- strsplit(.code, "|", fixed = TRUE)[[1]]
if (length(.params) == 0 | length(.params) > 2)
stop("\".code\" is invalid!")
.paramIndex <- apply(as.matrix(.params), 1, function(x) which(colnames(.X) %in%
x))
if (length(.paramIndex) != length(.params))
stop("\".code\" is invalid, one or both of the variables were not found!")
if (length(.paramIndex) == 1) {
.ggDATA <- rbind.data.frame(data.frame(parameter = .X[,
.paramIndex], clustering = "prior"), data.frame(parameter = .X[,
.paramIndex], clustering = as.character(.clustering)))
.ggDATA$clustering <- factor(.ggDATA$clustering,
levels = c(as.character(unique(.clustering)),
"prior"))
.gg <- ggplot(.ggDATA) + stat_ecdf(aes(x = parameter,
group = clustering, colour = clustering), lwd = lwd) +
xlab(colnames(.X)[.paramIndex]) + ylab("Phi") +
ylim(c(0, 1)) + theme(legend.position = "top") +
scale_colour_manual(values = c(.cbbPalette[1:length(unique(.clustering))],
"#000000"))
}
else {
.brks = quantile(.X[, .paramIndex[2]], seq(0, 1,
1/.nBins))
if (length(unique(round(.brks, 8))) > 1) {
.binning <- cut(.X[, .paramIndex[2]], breaks = .brks,
include.lowest = TRUE, right = TRUE, labels = FALSE)
}
else {
stop(paste("It appears that something is wrong with parameter: ",
colnames(.X)[.paramIndex[2]]))
}
.ggDATA <- rbind.data.frame(data.frame(parameter = .X[,
.paramIndex[1]], clustering = paste("Cluster_",
.clustering, sep = ""), bin = .binning), data.frame(parameter = .X[,
.paramIndex[1]], clustering = paste("Cluster_",
.clustering, sep = ""), bin = "cluster_prior"))
.ggDATA$bin <- factor(.ggDATA$bin, levels = c(unique(.binning),
"cluster_prior"))
.gg <- ggplot(.ggDATA) + stat_ecdf(aes(x = parameter,
group = bin, colour = bin), lwd = lwd) + xlab(.code) +
ylab("Phi") + ylim(c(0, 1)) + theme(legend.position = "top") +
facet_grid(~clustering) + scale_colour_manual(values = c((scales::hue_pal())(length(unique(.binning))),
"#000000"))
}
}
.gg <- .gg + ggtitle(paste("CDFs for ", .code))
if (.ggReturn == "plot") {
print(.gg)
}
else {
return(.gg)
}
}


dgsa <- function (.clusters, .X, .normalize = TRUE, .nBoot = 100, .interactions = FALSE,
.nBins = 3, .alpha = 0.95, .parallel = FALSE, .progress = TRUE)
Expand Down Expand Up @@ -156,44 +79,3 @@ dgsa <- function (.clusters, .X, .normalize = TRUE, .nBoot = 100, .interactions
return(ret)
}

plotParetoDGSA <- function (.dgsa, .clusters = FALSE, .interaction = NULL, .hypothesis = TRUE,
.ggReturn = FALSE)
{
.cbbPalette <- c("#E69F00", "#56B4E9", "#009E73", "#F0E442",
"#0072B2", "#D55E00", "#CC79A7")
if (class(.dgsa) != "DGSAstructure")
stop("Passed object is not of class DGSAstructure. Exiting!")
if (!is.null(.interaction)) {
.paramIndex <- which(.dgsa$parameters == .interaction)
if (length(.paramIndex) == 0)
stop("Parameter provided in \".interaction\" not found. Exiting!")
.ggDATA <- t(.dgsa$sensitivityMatrix[, .paramIndex, ])
.plotTitle <- paste("S(\"X\" | ", .dgsa$parameters[.paramIndex],
")", sep = "")
}
else {
.ggDATA <- apply(.dgsa$sensitivityMatrix, 1, diag)
.plotTitle <- "Main Sensitivities (marginal)"
}
colnames(.ggDATA) <- paste("Cluster", 1:ncol(.ggDATA), sep = "_")
.ggDATA[is.nan(.ggDATA)] = 0
.ggDATA <- as.data.frame(.ggDATA)
.ggDATA$mean <- apply(.ggDATA, 1, mean)
.ggDATA$parameters <- .dgsa$parameters
.ggDATA <- .ggDATA[order(.ggDATA$mean), ]
.levels <- .ggDATA$parameters
.ggDATA <- melt(.ggDATA, id = c("parameters"))
.ggDATA$parameters <- factor(.ggDATA$parameters, levels = .levels)
.ggP <- ggplot(.ggDATA, aes(x = parameters, y = value,fill = variable,color = variable)) +
coord_flip() +
geom_bar(stat = "identity", position = "dodge", lwd = 0.2, colour = "black") + theme(legend.position = "bottom") +
geom_hline(yintercept = ifelse(.hypothesis, 1, NULL)) + scale_fill_manual(values=c(.cbbPalette[1:ncol(.ggDATA)],'darkred'))+
scale_color_manual(values=c(.cbbPalette[1:ncol(.ggDATA)],'darkred'))+
ggtitle(.plotTitle)
if (.ggReturn) {
return(.ggP)
}
else {
print(.ggP)
}
}

0 comments on commit 91a867e

Please sign in to comment.