diff --git a/DESCRIPTION b/DESCRIPTION index 8aa3d04df8814028f52a59a1cb4cc90d87fdbac7..aaddf6e367f2e97bc0b634ec3f50f744e8ed0b2d 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,7 +2,7 @@ Package: hydroPSO Type: Package Title: Model-Independent Particle Swarm Optimisation for Environmental Models Version: 0.1-56 -Date: 2012-06-12 +Date: 2012-06-13 Author: Mauricio Zambrano-Bigiarini [aut, cre] and Rodrigo Rojas [ctb] Author@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> diff --git a/NEWS b/NEWS index b1b9da413ffa009e0feaca51024d0f61d1b1bde1..1f70c0c6f718cb9b5bf9ee5bc75c73218d7b6dc5 100755 --- a/NEWS +++ b/NEWS @@ -2,10 +2,10 @@ NEWS/ChangeLog for hydroPSO -------------------------- -0.1-56 12-Jun-2012 +0.1-56 13-Jun-2012 o 'hydroPSO' : -) much less memory consumption for large values of 'maxit' and/or 'npart'. - The files 'BestParamPerIter.txt', 'PbestPerIter.txt', and 'LocalBestPerIter.txt' are now written at the end of - each iteration, and not at the end of the main algorithm + The files 'BestParamPerIter.txt', 'PbestPerIter.txt', 'LocalBestPerIter.txt', 'Velocities.txt' are now written at the end of + each iteration, and not at the end of the main algorithm (so the corresponding local variables were removed) -) the convergence of the algorithm controlled by 'reltol' is now defined by : reltol <= normalised swarm radius, instead of reltol <= [ gbest(iter) / ( gbest(iter-1) +reltol ) ] -) 'PbestPerIter.txt' output file: now it has an additional first column labelled "Iter", with the iteration number diff --git a/R/PSO_v2012.R b/R/PSO_v2012.R index 272e697d8b937d65f672b09b0fa4a47fcaec83a7..f11c143afcf3453fa896e51453eea0b73d59edca 100755 --- a/R/PSO_v2012.R +++ b/R/PSO_v2012.R @@ -1104,7 +1104,7 @@ Random.Topology.Generation <- function(npart, K, # Updates: Dec-2010 # # May-2011 ; 28-Oct-2011 ; 14-Nov-2011 ; 23-Nov-2011 ; # # 15-Jan-2012 ; 23-Jan-2012 ; 30-Jan-2012 ; 23-Feb-2012 ; 23-Mar-2012 # -# 12-Jun-2012 # +# 13-Jun-2012 # ################################################################################ # 'lower' : minimum possible value for each parameter # 'upper' : maximum possible value for each parameter @@ -1725,14 +1725,11 @@ hydroPSO <- function( Xt.fitness <- matrix(rep(fn.worst.value, maxit*npart), ncol=npart, nrow=maxit, byrow=TRUE) colnames(Xt.fitness) <- paste("Part", 1:npart, sep="") - rownames(Xt.fitness) <- paste("iter.", 1:maxit, sep="") - - velocities <- matrix(rep(NA, (n+2)*maxit*npart), ncol=(n+2), nrow=maxit*npart, byrow=TRUE) - colnames(velocities) <- c("Iter", "Part", param.IDs) + rownames(Xt.fitness) <- paste("iter.", 1:maxit, sep="") if (topology != "random") { nc <- K - ifelse(trunc(K/2) != ceiling(K/2), N <- (K-1)/2, N <- K/2) + ifelse(trunc(K/2) != ceiling(K/2), N <- (K-1)/2, N <- K/2) ifelse(trunc(K/2) != ceiling(K/2), NN <- 1, NN <- 0) X.neighbours <- matrix(rep(-NA, nc*npart), ncol=nc, nrow=npart, byrow=TRUE) @@ -2063,10 +2060,6 @@ hydroPSO <- function( Xt.fitness[iter, 1:npart] <- apply(X, fn, MARGIN=1) GoF <- Xt.fitness[iter, 1:npart] - velocities[(npart*(iter-1)+1):(npart*iter), 1] <- iter - velocities[(npart*(iter-1)+1):(npart*iter), 2] <- 1:npart - velocities[(npart*(iter-1)+1):(npart*iter), 3:(2+n)] <- V - nfn <- nfn + npart if (write2disk) { @@ -2101,10 +2094,6 @@ hydroPSO <- function( GoF <- as.numeric(hydromod.out[["GoF"]]) Xt.fitness[iter, part] <- GoF - velocities[npart*(iter-1)+part, 1] <- iter - velocities[npart*(iter-1)+part, 2] <- part - velocities[npart*(iter-1)+part, 3:(2+n)] <- V[part,] - if(is.finite(GoF)) nfn <- nfn + 1 if (write2disk) { @@ -2133,33 +2122,6 @@ hydroPSO <- function( } # ELSE end - - if (write2disk) { - for ( part in (1:npart) ) { - # File 'Particles.txt' # - if(is.finite(Xt.fitness[iter, part])) { - writeLines(as.character( c(iter, part, - formatC(Xt.fitness[iter, part], format="E", digits=digits, flag=" "), #GoF - formatC(X[part, ], format="E", digits=digits, flag=" ") - ) ), Particles.TextFile, sep=" ") - } else writeLines(as.character( c(iter, part, "NA", - formatC(X[part, ], format="E", digits=digits, flag=" ") - ) ), Particles.TextFile, sep=" ") - writeLines("", Particles.TextFile) - - # File 'Velocities.txt' # - if(is.finite(Xt.fitness[iter, part])) { - writeLines( as.character( c(iter, part, - formatC(Xt.fitness[iter, part], format="E", digits=digits, flag=" "), # GoF - formatC(V[part, ], format="E", digits=digits, flag=" ") - ) ), Velocities.TextFile, sep=" ") - } else writeLines( as.character( c(iter, part, "NA", - formatC(V[part, ], format="E", digits=digits, flag=" ") - ) ), Velocities.TextFile, sep=" ") - writeLines("", Velocities.TextFile) - } # FOR end - } # IF end - if ( plot ) { ifelse(MinMax == "max", lgof <- max(GoF, na.rm=TRUE), lgof <- min(GoF, na.rm=TRUE)) colorRamp= colorRampPalette(c("darkred", "red", "orange", "yellow", "green", "darkgreen", "cyan")) @@ -2246,6 +2208,33 @@ hydroPSO <- function( ################### Particles Loop (j) - Start ######################## ########################################################################## for (j in 1:npart) { + + if (write2disk) { + + # File 'Particles.txt' # + if(is.finite(Xt.fitness[iter, part])) { + writeLines(as.character( c(iter, j, + formatC(Xt.fitness[iter, j], format="E", digits=digits, flag=" "), #GoF + formatC(X[j, ], format="E", digits=digits, flag=" ") + ) ), Particles.TextFile, sep=" ") + } else writeLines(as.character( c(iter, j, "NA", + formatC(X[j, ], format="E", digits=digits, flag=" ") + ) ), Particles.TextFile, sep=" ") + writeLines("", Particles.TextFile) + + # File 'Velocities.txt' # + if(is.finite(Xt.fitness[iter, j])) { + writeLines( as.character( c(iter, j, + formatC(Xt.fitness[iter, j], format="E", digits=digits, flag=" "), # GoF + formatC(V[j, ], format="E", digits=digits, flag=" ") + ) ), Velocities.TextFile, sep=" ") + } else writeLines( as.character( c(iter, j, "NA", + formatC(V[j, ], format="E", digits=digits, flag=" ") + ) ), Velocities.TextFile, sep=" ") + writeLines("", Velocities.TextFile) + + } # IF end + if ( best.update == "async" ) { tmp <- async.update.pgbests(x=X[j,],