Example #1
0
    def newPosition(self, globalBestPosition, rng):
        """See comments in base class."""
        # First, update the velocity. The new velocity is given as:
        # v = (inertia * v)  + (cogRate * r1 * (localBest-pos))
        #                    + (socRate * r2 * (globalBest-pos))
        #
        # where r1 and r2 are random numbers between 0 and 1.0
        lb = float(Configuration.get("nupic.hypersearch.randomLowerBound"))
        ub = float(Configuration.get("nupic.hypersearch.randomUpperBound"))

        self._velocity = (self._velocity * self._inertia +
                          rng.uniform(lb, ub) * self._cogRate *
                          (self._bestPosition - self.getPosition()))
        if globalBestPosition is not None:
            self._velocity += rng.uniform(lb, ub) * self._socRate * (
                globalBestPosition - self.getPosition())

        # update position based on velocity
        self._position += self._velocity

        # Clip it
        self._position = max(self.min, self._position)
        self._position = min(self.max, self._position)

        # Return it
        return self.getPosition()
Example #2
0
  def newPosition(self, globalBestPosition, rng):
    """See comments in base class."""
    # First, update the velocity. The new velocity is given as:
    # v = (inertia * v)  + (cogRate * r1 * (localBest-pos))
    #                    + (socRate * r2 * (globalBest-pos))
    #
    # where r1 and r2 are random numbers between 0 and 1.0
    lb=float(Configuration.get("nupic.hypersearch.randomLowerBound"))
    ub=float(Configuration.get("nupic.hypersearch.randomUpperBound"))

    self._velocity = (self._velocity * self._inertia + rng.uniform(lb, ub) *
                      self._cogRate * (self._bestPosition - self.getPosition()))
    if globalBestPosition is not None:
      self._velocity += rng.uniform(lb, ub) * self._socRate * (
          globalBestPosition - self.getPosition())

    # update position based on velocity
    self._position += self._velocity

    # Clip it
    self._position = max(self.min, self._position)
    self._position = min(self.max, self._position)

    # Return it
    return self.getPosition()
    def __init__(self, milestones=None, logLevel=None):
        # Set class constants.
        self.MATURITY_WINDOW = int(
            Configuration.get("nupic.hypersearch.swarmMaturityWindow"))
        self.MAX_GENERATIONS = int(
            Configuration.get("nupic.hypersearch.swarmMaxGenerations"))
        if self.MAX_GENERATIONS < 0:
            self.MAX_GENERATIONS = None

        # Set up instsance variables.

        self._isTerminationEnabled = bool(
            int(Configuration.get('nupic.hypersearch.enableSwarmTermination')))

        self.swarmBests = dict()
        self.swarmScores = dict()
        self.terminatedSwarms = set([])

        self._logger = logging.getLogger(".".join([
            'com.numenta', self.__class__.__module__, self.__class__.__name__
        ]))

        if milestones is not None:
            self.milestones = milestones
        else:
            self.milestones = copy.deepcopy(self._DEFAULT_MILESTONES)
Example #4
0
    def __init__(self,
                 min,
                 max,
                 stepSize=None,
                 inertia=None,
                 cogRate=None,
                 socRate=None):
        """Construct a variable that permutes over floating point values using
    the Particle Swarm Optimization (PSO) algorithm. See descriptions of
    PSO (i.e. http://en.wikipedia.org/wiki/Particle_swarm_optimization)
    for references to the inertia, cogRate, and socRate parameters.

    Parameters:
    -----------------------------------------------------------------------
    min:          min allowed value of position
    max:          max allowed value of position
    stepSize:     if not None, the position must be at min + N * stepSize,
                    where N is an integer
    inertia:      The inertia for the particle.
    cogRate:      This parameter controls how much the particle is affected
                    by its distance from it's local best position
    socRate:      This parameter controls how much the particle is affected
                    by its distance from the global best position

    """
        super(PermuteFloat, self).__init__()
        self.min = min
        self.max = max
        self.stepSize = stepSize

        # The particle's initial position and velocity.
        self._position = (self.max + self.min) / 2.0
        self._velocity = (self.max - self.min) / 5.0

        # The inertia, cognitive, and social components of the particle
        self._inertia = (float(Configuration.get("nupic.hypersearch.inertia"))
                         if inertia is None else inertia)
        self._cogRate = (float(Configuration.get("nupic.hypersearch.cogRate"))
                         if cogRate is None else cogRate)
        self._socRate = (float(Configuration.get("nupic.hypersearch.socRate"))
                         if socRate is None else socRate)

        # The particle's local best position and the best global position.
        self._bestPosition = self.getPosition()
        self._bestResult = None
Example #5
0
  def __init__(self, min, max, stepSize=None, inertia=None, cogRate=None,
               socRate=None):
    """Construct a variable that permutes over floating point values using
    the Particle Swarm Optimization (PSO) algorithm. See descriptions of
    PSO (i.e. http://en.wikipedia.org/wiki/Particle_swarm_optimization)
    for references to the inertia, cogRate, and socRate parameters.

    Parameters:
    -----------------------------------------------------------------------
    min:          min allowed value of position
    max:          max allowed value of position
    stepSize:     if not None, the position must be at min + N * stepSize,
                    where N is an integer
    inertia:      The inertia for the particle.
    cogRate:      This parameter controls how much the particle is affected
                    by its distance from it's local best position
    socRate:      This parameter controls how much the particle is affected
                    by its distance from the global best position

    """
    super(PermuteFloat, self).__init__()
    self.min = min
    self.max = max
    self.stepSize = stepSize

    # The particle's initial position and velocity.
    self._position = (self.max + self.min) / 2.0
    self._velocity = (self.max - self.min) / 5.0


    # The inertia, cognitive, and social components of the particle
    self._inertia = (float(Configuration.get("nupic.hypersearch.inertia"))
                     if inertia is None else inertia)
    self._cogRate = (float(Configuration.get("nupic.hypersearch.cogRate"))
                     if cogRate is None else cogRate)
    self._socRate = (float(Configuration.get("nupic.hypersearch.socRate"))
                     if socRate is None else socRate)

    # The particle's local best position and the best global position.
    self._bestPosition = self.getPosition()
    self._bestResult = None
    def __init__(self, milestones=None, logLevel=None):
        # Set class constants.
        self.MATURITY_WINDOW = int(Configuration.get("nupic.hypersearch.swarmMaturityWindow"))
        self.MAX_GENERATIONS = int(Configuration.get("nupic.hypersearch.swarmMaxGenerations"))
        if self.MAX_GENERATIONS < 0:
            self.MAX_GENERATIONS = None

        # Set up instsance variables.

        self._isTerminationEnabled = bool(int(Configuration.get("nupic.hypersearch.enableSwarmTermination")))

        self.swarmBests = dict()
        self.swarmScores = dict()
        self.terminatedSwarms = set([])

        self._logger = logging.getLogger(".".join(["com.numenta", self.__class__.__module__, self.__class__.__name__]))

        if milestones is not None:
            self.milestones = milestones
        else:
            self.milestones = copy.deepcopy(self._DEFAULT_MILESTONES)