From 7c1ad60019e010fe09cc0991bf66a132e7eefb0e Mon Sep 17 00:00:00 2001
From: Mauricio Zambrano-Bigiarini <hzambran@users.noreply.github.com>
Date: Wed, 31 Oct 2012 16:20:12 +0000
Subject: [PATCH] hydroPSO.R: fixed velocity equation for 'method=canonical'.

---
 R/PSO_v2012.R   | 12 ++++++++----
 man/hydroPSO.Rd |  7 ++++++-
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/R/PSO_v2012.R b/R/PSO_v2012.R
index 9deb4d1..5171e3d 100755
--- a/R/PSO_v2012.R
+++ b/R/PSO_v2012.R
@@ -215,7 +215,7 @@ compute.CF <- function(c1, c2) {
 ################################################################################
 # Created: 2008                                                                #
 # Updates: Oct-2011 ; Nov-2011                                                 #
-#          19-Sep-2012 ; 20-Sep-2012 ; 28-Oct-2012                             #
+#          19-Sep-2012 ; 20-Sep-2012 ; 28-Oct-2012 ; 31-Oct-2012               #
 ################################################################################
 compute.veloc <- function(x, v, w, c1, c2, CF, Pbest, part.index, gbest, 
                           topology, method, MinMax, neighs.index, 
@@ -241,7 +241,7 @@ compute.veloc <- function(x, v, w, c1, c2, CF, Pbest, part.index, gbest,
      
       vn <- CF * (w*v + alea.sphere( G=Gr, radius= enorm(Gr-x) ) - x )
   
-  } else if ( method %in% c("spso2007", "canonical") ) {
+  } else if ( method == "spso2007" ) {
   
            if( part.index != localBest.pos) {
                   vn <- CF * ( w*v + r1*c1*(pbest-x) + r2*c2*(localBest-x) )
@@ -292,8 +292,12 @@ compute.veloc <- function(x, v, w, c1, c2, CF, Pbest, part.index, gbest,
                          wght <- (1/lpbest.fit)/sum(1/lpbest.fit)
                        } else wght <- lpbest.fit/sum(lpbest.fit) 
                    
-                       vn  <-  CF * ( w*v + (1/N) * colSums( wght*r*(P-X) ) )	  
-                     } # ELSE end
+                       vn  <-  CF * ( w*v + (1/N) * colSums( wght*r*(P-X) ) )	
+                         
+                     }  else if ( method == "canonical")    
+                                       
+                           vn <- CF * ( w*v + r1*c1*(pbest-x) + r2*c2*(localBest-x) )
+                       
   
   return(vn)
   
diff --git a/man/hydroPSO.Rd b/man/hydroPSO.Rd
index 5ab8f2e..0fa0b58 100755
--- a/man/hydroPSO.Rd
+++ b/man/hydroPSO.Rd
@@ -38,12 +38,17 @@ further arguments to be passed to \code{fn}.
 character, variant of the PSO algorithm to be used. By default \code{method='spso2011'}, while valid values are in \code{c('spso2011', 'spso2007', 'ipso', 'fips', 'wfips', 'canonical')}: \cr
 
 \kbd{spso2011}: At each iteration particles are attracted to its own best-known \sQuote{personal} and to the best-known position in its \sQuote{local} neighbourhood, which depens on the value of \code{topology}. In addition, values of the PSO engine are set to the values defined in the Standard PSO 2011 (SPSO 2011, see Clerc 2012) \cr
+
 \kbd{spso2007}: As in \code{method='spso2011'}, but with values of the PSO engine set to the values defined in the Standard PSO 2007 (SPSO 2007, see Clerc 2012)
+
 \kbd{ipso}: at each iteration particles in the swarm are rearranged in descending order according to their goodness-of-fit and the best \code{ngbest} particles are used to modify particles' position and velocity (see Zhao, 2006). Each particle is connected to a neighbourhood of particles depending on the \code{topology} value \cr
+
 \kbd{fips}: at each iteration ALL particles contribute to modify the particles' position and velocity (see Mendes et al., 2004). Each particle is connected to a neighbourhood of particles depending on the \code{topology} value \cr
+
 \kbd{wfips}: same implementation as \kbd{fips} method, but the contribution of each particle is weighted according to their goodness-of-fit value (see Mendes et al., 2004) \cr
+
 \kbd{canonical}: It corresponds to the first formulation of the PSO algorithm, and it is included here for educational and comparative purposes only, due to several limitations described in literature. See Kennedy 2006 \cr
-At each iteration particles are attracted to its own best-known \sQuote{personal} and to the best-known position in all the swarm (\sQuote{global}). The following \code{control} arguments are set when this methos is selected: (i) \code{topology='gbest'}, (ii) \code{Xini.type='random'}, (iii) \code{Vini.type='random2007'}, (iv) \code{use.CF=TRUE}, (v) \code{c1=2.05}, (vi) \code{c2=2.05}, (vii) \code{boundary.wall='absorbing2007'}, (viii) \code{lambda=1.0}
+At each iteration particles are attracted to its own best-known \sQuote{personal} and to the best-known position in all the swarm (\sQuote{global}). The following \code{control} arguments are set when this methos is selected: (i) \code{npart=40}, (ii) \code{topology='gbest'}, (iii) \code{Xini.type='random'}, (iv) \code{Vini.type='random2007'}, (v) \code{use.CF=TRUE}, (vi) \code{c1=2.05}, (vii) \code{c2=2.05}, (viii) \code{boundary.wall='absorbing2007'}, (ix) \code{lambda=1.0}
 }
   \item{lower}{
 numeric, lower boundary for each parameter \cr
-- 
GitLab