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

'velocities' variable removed. Writing of 'Velocities.txt' and 'Particles.txt'...

'velocities' variable removed. Writing of 'Velocities.txt' and 'Particles.txt' files moved to the begining of the 'Particles Loop (j)' loop
parent 69f14b33
No related branches found
No related tags found
No related merge requests found
...@@ -2,7 +2,7 @@ Package: hydroPSO ...@@ -2,7 +2,7 @@ Package: hydroPSO
Type: Package Type: Package
Title: Model-Independent Particle Swarm Optimisation for Environmental Models Title: Model-Independent Particle Swarm Optimisation for Environmental Models
Version: 0.1-56 Version: 0.1-56
Date: 2012-06-12 Date: 2012-06-13
Author: Mauricio Zambrano-Bigiarini [aut, cre] and Rodrigo Rojas [ctb] 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") ) ) 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> Maintainer: Mauricio Zambrano-Bigiarini <mzb.devel@gmail.com>
......
...@@ -2,10 +2,10 @@ NEWS/ChangeLog for hydroPSO ...@@ -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'. 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 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 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, -) 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 ) ] 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 -) 'PbestPerIter.txt' output file: now it has an additional first column labelled "Iter", with the iteration number
......
...@@ -1104,7 +1104,7 @@ Random.Topology.Generation <- function(npart, K, ...@@ -1104,7 +1104,7 @@ Random.Topology.Generation <- function(npart, K,
# Updates: Dec-2010 # # Updates: Dec-2010 #
# May-2011 ; 28-Oct-2011 ; 14-Nov-2011 ; 23-Nov-2011 ; # # 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 # # 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 # 'lower' : minimum possible value for each parameter
# 'upper' : maximum possible value for each parameter # 'upper' : maximum possible value for each parameter
...@@ -1725,14 +1725,11 @@ hydroPSO <- function( ...@@ -1725,14 +1725,11 @@ hydroPSO <- function(
Xt.fitness <- matrix(rep(fn.worst.value, maxit*npart), ncol=npart, nrow=maxit, byrow=TRUE) Xt.fitness <- matrix(rep(fn.worst.value, maxit*npart), ncol=npart, nrow=maxit, byrow=TRUE)
colnames(Xt.fitness) <- paste("Part", 1:npart, sep="") colnames(Xt.fitness) <- paste("Part", 1:npart, sep="")
rownames(Xt.fitness) <- paste("iter.", 1:maxit, 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)
if (topology != "random") { if (topology != "random") {
nc <- K 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) ifelse(trunc(K/2) != ceiling(K/2), NN <- 1, NN <- 0)
X.neighbours <- matrix(rep(-NA, nc*npart), ncol=nc, nrow=npart, byrow=TRUE) X.neighbours <- matrix(rep(-NA, nc*npart), ncol=nc, nrow=npart, byrow=TRUE)
...@@ -2063,10 +2060,6 @@ hydroPSO <- function( ...@@ -2063,10 +2060,6 @@ hydroPSO <- function(
Xt.fitness[iter, 1:npart] <- apply(X, fn, MARGIN=1) Xt.fitness[iter, 1:npart] <- apply(X, fn, MARGIN=1)
GoF <- Xt.fitness[iter, 1:npart] 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 nfn <- nfn + npart
if (write2disk) { if (write2disk) {
...@@ -2101,10 +2094,6 @@ hydroPSO <- function( ...@@ -2101,10 +2094,6 @@ hydroPSO <- function(
GoF <- as.numeric(hydromod.out[["GoF"]]) GoF <- as.numeric(hydromod.out[["GoF"]])
Xt.fitness[iter, part] <- 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(is.finite(GoF)) nfn <- nfn + 1
if (write2disk) { if (write2disk) {
...@@ -2133,33 +2122,6 @@ hydroPSO <- function( ...@@ -2133,33 +2122,6 @@ hydroPSO <- function(
} # ELSE end } # 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 ) { if ( plot ) {
ifelse(MinMax == "max", lgof <- max(GoF, na.rm=TRUE), lgof <- min(GoF, na.rm=TRUE)) 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")) colorRamp= colorRampPalette(c("darkred", "red", "orange", "yellow", "green", "darkgreen", "cyan"))
...@@ -2246,6 +2208,33 @@ hydroPSO <- function( ...@@ -2246,6 +2208,33 @@ hydroPSO <- function(
################### Particles Loop (j) - Start ######################## ################### Particles Loop (j) - Start ########################
########################################################################## ##########################################################################
for (j in 1:npart) { 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" ) { if ( best.update == "async" ) {
tmp <- async.update.pgbests(x=X[j,], tmp <- async.update.pgbests(x=X[j,],
......
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