Skip to content
Snippets Groups Projects
Commit 560178f7 authored by Mauricio Zambrano-Bigiarini's avatar Mauricio Zambrano-Bigiarini
Browse files

hydroPSO.R: fixed small bug in 'UpdateLocalBest'

parent 83274887
No related branches found
No related tags found
No related merge requests found
Package: hydroPSO
Type: Package
Title: Model-Independent Particle Swarm Optimisation for Environmental Models
Version: 0.1-58-15
Date: 2012-10-28
Version: 0.1-58-16
Date: 2012-10-29
Authors@R: c(person("Mauricio", "Zambrano-Bigiarini", email="mzb.devel@gmail.com", role=c("aut","cre")), person("Rodrigo", "Rojas", email="Rodrigo.RojasMujica@gmail.com", role=c("ctb")) )
Maintainer: Mauricio Zambrano-Bigiarini <mzb.devel@gmail.com>
Description: This package implements a state-of-the-art version of the Particle Swarm Optimisation (PSO) algorithm (SPSO-2011 and SPSO-2007 capable), with a special focus on the calibration of environmental models. hydroPSO is model-independent, allowing the user to easily interface any model code with the calibration engine (PSO). It includes a series of controlling options and PSO variants to fine-tune the performance of the calibration engine to different calibration problems. An advanced sensitivity analysis function together with user-friendly plotting summaries facilitate the interpretation and assessment of the calibration results. Bugs reports/comments/questions are very welcomed.
......
......@@ -8,7 +8,8 @@ NEWS/ChangeLog for hydroPSO
* new confinement of the velocity ( V[t+1] = -0.5 * V[t], when x[t+1] > x_max | x[t+1] < x_min )
* optional normalisation of parameter values
-) improved performance (~ 33% faster, tested on 10-D benchmark functions with 'write2disk=FALSE')
-) improved performance. ~ 33% faster for 32-bit machines and 38% faster for 64-bit machines.
Tested on 10-, 20- and 30-D benchmark functions with 'write2disk=FALSE'.
-) 'fn' argument now can be any R function or a character. In the latter case, it can be "hydromod" or the name of a
valid R function. In previous versions of 'hydroPSO' only a character type was accepted.
-) now it handles models with sub-daily time step and with sub-daily observations (thanks to O. Rakovec !).
......
......@@ -246,8 +246,6 @@ compute.veloc <- function(x, v, w, c1, c2, CF, Pbest, part.index, gbest,
} else Gr <- (x + p) / 2
vn <- CF * (w*v + alea.sphere( G=Gr, radius= enorm(Gr-x) ) - x )
#vn <- CF * (w*v + gx + alea.sphere(G=gx + x, radius=enorm(gx) ) )
} else if ( method %in% c("spso2007", "canonical") ) {
......@@ -983,7 +981,7 @@ InitializateV <- function(npart, param.IDs, x.MinMax, v.ini.type, Xini) {
# Started: 24-Dec-2010 ##
# Updates: 29-Dec-2010 ; ##
# 14-Nov-2011 ; 27-Jan-2011 ##
# 28-Oct-2012 ##
# 28-Oct-2012 ; 29-Oct-2012 ##
################################################################################
# Purpose: Function for computing the best value in the neighbourhood of each
# particle
......@@ -1013,17 +1011,18 @@ UpdateLocalBest <- function(pbest.fit, localBest.pos, localBest.fit, x.neighbour
if(MinMax == "max") {
better.index <- which( pbest.fit[neighs.index] > localBest.fit[i] )
} else better.index <- which( pbest.fit[neighs.index] < localBest.fit[i] )
# if there are some particles that have a better fitness value
if (length(better.index) > 0) #{ ???
if(MinMax == "max") {
localBest.fit[i] <- max( pbest.fit[neighs.index], na.rm=TRUE )
} else localBest.fit[i] <- min( pbest.fit[neighs.index], na.rm=TRUE )
if (length(better.index) > 0) {
if(MinMax == "max") {
localBest.pos[i] <- neighs.index[which.max( pbest.fit[neighs.index] )]
} else localBest.pos[i] <- neighs.index[which.min( pbest.fit[neighs.index] )]
#} ???
if(MinMax == "max") {
localBest.pos[i] <- neighs.index[which.max( pbest.fit[neighs.index] )]
localBest.fit[i] <- pbest.fit[localBest.pos[i]]
} else {
localBest.pos[i] <- neighs.index[which.min( pbest.fit[neighs.index] )]
localBest.fit[i] <- pbest.fit[localBest.pos[i]]
} # ELSE end
} # |IF end
} # FOR end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment