コード例 #1
0
ファイル: PSO.py プロジェクト: AmeenaK/nbites
    def updateParticlePosition(self):
        for i in range(0, self.dimension):
            self.position[i] = self.position[i] + self.velocity[i]

            clip(self.position[i],
                 self.searchMins[i],
                 self.searchMaxs[i])
コード例 #2
0
ファイル: PSO.py プロジェクト: AmeenaK/nbites
    def updateParticleVelocity(self):
        for i in range(0, self.dimension):
            # if mins[i] == maxs[i] then ignore, we aren't optimizing it
            if self.searchMins[i] == self.searchMaxs[i]:
                continue

            # Random component to avoid local minima
            R1 = random.random()
            R2 = random.random()

            self.velocity[i] = self.INERTIAL*self.velocity[i] \
                + COG * R1 * (self.pBest_vars[i] - self.position[i]) \
                + SOC * R2 * (self.gBest_position[i] - self.position[i])

            clip(self.velocity[i],
                 -self.velocityCap[i],
                 self.velocityCap[i])

            if fabs(self.velocity[i]) < VELOCITY_MINIMUM_MAGNITUDE:
                self.velocity[i] = 0
コード例 #3
0
ファイル: PSO.py プロジェクト: suthumb/nbites
    def updateParticlePosition(self):
        for i in range(0, self.dimension):
            newPosition = self.position[i] + self.velocity[i]

            if ((newPosition > self.searchMaxs[i]) or
                (newPosition < self.searchMins[i]) and
                RANDOMIZE_LOST_PARTICLES):
                if DEBUG:
                    print 'Randomized a lost particle (dimension {0})'.format(i)
                self.position[i] = random.uniform(self.searchMins[i],
                                                  self.searchMaxs[i])
                self.velocity[i] = 0
            else:
                self.position[i] = clip(newPosition,
                                        self.searchMins[i],
                                        self.searchMaxs[i])
コード例 #4
0
ファイル: PSO.py プロジェクト: suthumb/nbites
    def updateParticleVelocity(self):
        for i in range(0, self.dimension):
            # if mins[i] == maxs[i] then ignore, we aren't optimizing it
            if self.searchMins[i] == self.searchMaxs[i]:
                continue

            # Random component to avoid local minima
            R1 = random.random()
            R2 = random.random()

            newVelocity = self.INERTIAL*self.velocity[i] \
                + COG * R1 * (self.pBest_position[i] - self.position[i]) \
                + SOC * R2 * (self.gBest_position[i] - self.position[i])

            self.velocity[i] = clip(newVelocity,
                                    -self.velocityCap[i],
                                    self.velocityCap[i])

            if fabs(self.velocity[i]) < VELOCITY_MINIMUM_MAGNITUDE:
                self.velocity[i] = 0