From 997bb90223ace59d97adecee06e7b731946cd991 Mon Sep 17 00:00:00 2001 From: Mauricio Zambrano-Bigiarini <hzambran@users.noreply.github.com> Date: Tue, 20 Nov 2012 00:28:40 +0000 Subject: [PATCH] plot\_particles.R: aarguments 'beh.thr', 'MinMax' and 'gofs' are now passed to 'params2ecdf' --- NEWS | 1 + R/params2ecdf.R | 47 ++++++++++++++++++++++++++++++++++++++++++---- R/plot_params.R | 2 +- R/plot_particles.R | 5 ++++- 4 files changed, 49 insertions(+), 6 deletions(-) diff --git a/NEWS b/NEWS index c58ff79..2c313f5 100755 --- a/NEWS +++ b/NEWS @@ -101,6 +101,7 @@ NEWS/ChangeLog for hydroPSO o 'plot_particles' : -) new argument 'do.pairs' (by default 'do.pairs=FALSE'), to control if the correlation matrix among parameters has to be plotted or not (up to hydroPSO <=0.1.58 it was always plotted) -) arguments 'MinMax' and 'beh.thr' are now passed to 'plot_NparOF' + -) arguments 'gofs', 'MinMax' and 'beh.thr' are now passed to 'params2ecdf' o 'plot_results' : -) new argument 'do.pairs' (by default 'do.pairs=FALSE'), to control if the correlation matrix among parameters has to be plotted or not (up to hydroPSO <=0.1.58 it was always plotted) diff --git a/R/params2ecdf.R b/R/params2ecdf.R index c7791a1..4a3594b 100755 --- a/R/params2ecdf.R +++ b/R/params2ecdf.R @@ -68,17 +68,34 @@ params2ecdf.default <- function(params, # number of parameters nparam <- NCOL(params) - - if (nparam==1) params <- matrix(params, ncol=1) + + # Number of parameter sets + n <- NROW(params) # Checking 'param.names' if (length(param.names) != nparam) stop("Invalid argument: 'length(param.names) = ", length(param.names), " != ", nparam, " = nparam'") + + # Checking 'beh.thr' + if ( !is.na(beh.thr) ) { + if ( is.null(MinMax) ) + stop("Missing argument: 'MinMax' has to be provided before using 'beh.thr' !!") + if ( missing(gofs) ) { + stop("Missing argument: 'gofs' has to be provided before using 'beh.thr' !!") + } else if (length(gofs) != n) + stop("Invalid argument: 'length(gofs) != nrow(params)' (", length(gofs), "!=", n, ") !!" ) + } # IF end + + # Checking 'MinMax' + if ( !is.null(MinMax) ) { + if ( !(MinMax %in% c("min", "max")) ) + stop("Invalid argument: 'MinMax' must be in c('min', 'max')") + } # IF end # checking that the user provided 1 weight for each behavioural parameter set if ( !is.null(weights) ) { - if (length(weights) != NROW(params) ) - stop("Invalid argument: 'length(w) != nrow(params)' (", length(weights), "!=", nrow(params), ")" ) + if (length(weights) != n ) + stop("Invalid argument: 'length(w) != nrow(params)' (", length(weights), "!=", n, ")" ) } # IF end # creating the final output, a list with the ECDFs @@ -87,6 +104,28 @@ params2ecdf.default <- function(params, # Checking 'do.png' and 'plot' if (do.png==TRUE & plot==FALSE) stop("Invalid argument: 'plot=FALSE' & 'do.png=TRUE' is not possible !!") + + if (nparam==1) params <- matrix(params, ncol=1) + + # Filtering out those parameter sets above/below a certain threshold + if (!is.na(beh.thr)) { + # Checking 'beh.thr' + mx <- max(gofs, na.rm=TRUE) + if (beh.thr > mx) + stop("Invalid argument: 'beh.thr' must be lower than ", mx ,"!!") + + # Computing the row index of the behavioural parameter sets + ifelse(MinMax=="min", beh.row.index <- which(gofs <= beh.thr), + beh.row.index <- which(gofs >= beh.thr) ) + + # Removing non-behavioural parameter sets & gofs + params <- params[beh.row.index, ] + gofs <- gofs[beh.row.index] + + # Amount of behavioural parameter sets + nbeh <- nrow(params) + if (verbose) message( "[ Number of behavioural parameter sets: ", nbeh, " ]" ) + } # IF end ######################## Plotting Preliminars ######################## # If there are too many parameters to plot,more than 1 plot is produced diff --git a/R/plot_params.R b/R/plot_params.R index 592e56c..7bd7916 100755 --- a/R/plot_params.R +++ b/R/plot_params.R @@ -133,7 +133,7 @@ plot_params.default <- function(params, params <- params[, param.cols] # computing the number of parameters - nparams <- ncol(params) + nparams <- NCOL(params) # Filtering out those parameter sets above/below a certain threshold if (!is.na(beh.thr)) { diff --git a/R/plot_particles.R b/R/plot_particles.R index c4bde5d..75ea98d 100755 --- a/R/plot_particles.R +++ b/R/plot_particles.R @@ -278,7 +278,10 @@ plot_particles <- function(##################################################### if (!do.png) x11() params2ecdf(params=params, - param.names=param.names, + param.names=param.names, + gofs= gofs, + MinMax=MinMax, + beh.thr=beh.thr, weights=weights, byrow=byrow, plot=TRUE, -- GitLab