当前位置: 首页>>代码示例>>Python>>正文


Python BaseExplorer.BaseExplorer类代码示例

本文整理汇总了Python中nupic.vision.regions.ImageSensorExplorers.BaseExplorer.BaseExplorer的典型用法代码示例。如果您正苦于以下问题:Python BaseExplorer类的具体用法?Python BaseExplorer怎么用?Python BaseExplorer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了BaseExplorer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

  def __init__(self, sweepDirections=['left', 'right', 'up', 'down'],
               shiftDuringSweep=1, sweepOffObject=False, *args, **kwargs):
    """
    sweepDirections -- Directions for sweeping. Must be a list containing
      one or more of 'left', 'right', 'up', and 'down' for horizontal and
      vertical sweeps, or 'leftup', 'leftdown', 'rightup', and 'rightdown'
      for diagonal sweeps (or 'upleft, 'downleft', 'upright', and
      'downright'). Can also be the string 'all', for all eight directions.
    shiftDuringSweep -- Number of pixels to jump with each step (during
      a sweep).
    sweepOffObject -- Whether the sensor can only include a part of the
      object, as specified by the bounding box. If False, it will only move
      to positions that include as much of the object as possible.
    """

    BaseExplorer.__init__(self, *args, **kwargs)

    if sweepDirections == 'all':
      sweepDirections = ['left', 'right', 'up', 'down',
        'leftdown', 'leftup', 'rightdown', 'rightup']
    else:
      for direction in sweepDirections:
        if direction not in ('left', 'right', 'up', 'down',
            'leftup', 'upleft', 'leftdown', 'downleft',
            'rightup', 'upright', 'rightdown', 'downright'):
          raise RuntimeError('Unknown sweep direction: %s' % direction)
    if type(shiftDuringSweep) is not int:
      raise RuntimeError("'shiftDuringSweep' should be an integer")
    if type(sweepOffObject) not in (bool, int):
      raise RuntimeError("'sweepOffObject' should be a boolean")

    self.sweepDirections = sweepDirections
    self.shiftDuringSweep = shiftDuringSweep
    self.sweepOffObject = sweepOffObject
开发者ID:jaredweiss,项目名称:nupic.vision,代码行数:34,代码来源:RandomSweep.py

示例2: __init__

  def __init__(self, replacement=True, saccadeMin=10, saccadeMax=10,
               numSaccades=8, maxDrift=0,
               *args, **kwargs):
    """
    :param replacement: Allow the explorer to repeat images (if true)
    :param saccadeMin: Minimum distance a saccade will travel (in px)
    :param saccadeMax: Maxium distance a saccade will travel (in px)
    :param numSaccades: Number of saccades to run over each image
    :param maxDrift: Amount (in px) a saccade's center (fovea) can move out
      of the bounds of the image
    """
    BaseExplorer.__init__(self, *args, **kwargs)

    self.replacement = replacement
    self.saccadeMin = saccadeMin
    self.saccadeMax = saccadeMax
    self.numSaccades = numSaccades
    self.maxDrift = maxDrift

    self.prevSaccade = None

    if not self.replacement:
      self.history = []
      self.imageHistory = []

    self.saccadeIndex = 0
开发者ID:jaredweiss,项目名称:nupic.vision,代码行数:26,代码来源:RandomSaccade.py

示例3: first

  def first(self):
    """
    Set up the position.

    BaseExplorer picks image 0, offset (0,0), etc., but explorers that wish
    to set a different first position should extend this method. Such explorers
    may wish to call BaseExplorer.first(center=False), which initializes the
    position tuple but does not call centerImage() (which could cause
    unnecessary filtering to occur).
    """

    BaseExplorer.first(self, center=True)

    # Update the "home" position for the current image
    self._getHomePosition()

    if self._verbosity >= 1:
      print "BlockSpread: first():"

    # Set start position
    self._centerPosIdx = 0       # Which center point
    self._spreadPosIdx = 0       # radial position around the center point

    # Convert to X and Y offsets
    self._getPosition()
开发者ID:CV-IP,项目名称:nupic.vision,代码行数:25,代码来源:BlockSpread.py

示例4: next

  def next(self, seeking=False):
    """
    Go to the next position (next iteration).

    seeking -- Boolean that indicates whether the explorer is calling next()
      from seek(). If True, the explorer should avoid unnecessary computation
      that would not affect the seek command. The last call to next() from
      seek() will be with seeking=False.
    """

    BaseExplorer.next(self)

    if self.pointIndex is None:
      self.first()

    self.pointIndex += 1
    if self.pointIndex < len(self.currentPoints):
      # Next fixation point for this image
      self._setOffset()
    else:
      # Ran out of points for this image
      image = self.position['image'] + 1
      if image >= self.numImages:
        self.first()
        return
      while not self.names[image] in self.points:
        image += 1
        if image >= self.numImages:
          self.first()
          return
      self.position['image'] = image
      self._firstPoint()
开发者ID:CV-IP,项目名称:nupic.vision,代码行数:32,代码来源:ManualSaliency.py

示例5: update

  def update(self, **kwargs):
    """
    Update state with new parameters from ImageSensor and call first().
    """

    numFilters = kwargs.get('numFilters', None)
    if numFilters is not None and self.allDimensions:
      # Remove existing filter dimensions
      for dimension in self.dimensions[:]:
        if type(dimension['name']) is int:
          self.dimensions.remove(dimension)
      # Reset the probabilities from the existing dimensions
      for d in self.dimensions:
        d['probability'] = None
      # Add the new filter dimensions
      self.dimensions += \
        [self._newSweepDictionary(name=name) for name in range(numFilters)]

    numImages = kwargs.get('numImages', None)
    if numImages is not None and self.pattern:
      # Parse all the filenames
      self._parseFilenames(numImages)

    self._calculateProbabilities()

    BaseExplorer.update(self, **kwargs)
开发者ID:CV-IP,项目名称:nupic.vision,代码行数:26,代码来源:MultiSweep.py

示例6: first

  def first(self):
    """
    Set up the position.

    BaseExplorer picks image 0, offset (0,0), etc., but explorers that wish
    to set a different first position should extend this method. Such explorers
    may wish to call BaseExplorer.first(center=False), which initializes the
    position tuple but does not call centerImage() (which could cause
    unnecessary filtering to occur).
    """

    BaseExplorer.first(self)

    if not self.numImages:
      return

    # Set up the list of filenames
    self.names = []
    for i in xrange(self.numImages):
      path, filename = os.path.split(self.getImageInfo(i)['imagePath'])
      name = os.path.join(os.path.split(path)[1], filename)
      self.names.append(name)

    # Find the first image with some fixation points
    image = 0
    while not self.names[image] in self.points:
      # No fixation points for this image
      image += 1
      if image >= self.numImages:
        raise RuntimeError("No fixation points for any loaded images")
    self.position['image'] = image
    self._firstPoint()
    self.position['reset'] = True
开发者ID:CV-IP,项目名称:nupic.vision,代码行数:33,代码来源:ManualSaliency.py

示例7: __init__

 def __init__(self, sweepLength=4,
                    numRepetitions=1,
                    sweepOffMode=False,
                    maxOffset=None,
                    minVelocity=1,
                    maxVelocity=3,
                    seed=42,
                    *args, **kwargs):
   """
   @param sweepLen: number of presentations per sweep sequence.
   @param numRepetitions: number of times to present each inward sweep.
   """
   BaseExplorer.__init__(self, *args, **kwargs)
   # Parameter checking
   if type(sweepLength) is not int or sweepLength < 1:
     raise RuntimeError("'sweepLength' should be a positive integer")
   if type(numRepetitions) is not int or numRepetitions < 1:
     raise RuntimeError("'numRepetitions' should be a positive integer")
   # Parameters
   self._sweepLength = sweepLength
   self._numRepetitions = numRepetitions
   self._minVelocity = minVelocity
   self._maxVelocity = maxVelocity
   self._sweepOffMode = sweepOffMode
   self._maxOffset = maxOffset
   # Internal state
   self._seqIndex = 0
   self._repIndex = 0
   self._state = None
   self._repMemory = None
   # Prepare PRNG
   self._rng = random.Random()
   self._rng.seed(seed)
开发者ID:CV-IP,项目名称:nupic.vision,代码行数:33,代码来源:RepetitiveSweep.py

示例8: __init__

  def __init__(self, numSteps, diagonals=False, jitterSize=0, *args, **kwargs):
    """
    numSteps --
    diagonals -- Whether to step along the diagonal
    jitterSize -- How much to jitter around each step of the onion trajectories.
    """

    BaseExplorer.__init__(self, *args, **kwargs)

    self.numSteps = numSteps
    self.diagonals = diagonals
    if self.diagonals:
      self.offsetDelta = [[-1,-1],[-1,1],[1,1],[1,-1]]
    else:
      self.offsetDelta = [[-numSteps,-numSteps],[-numSteps,numSteps], \
                          [numSteps,numSteps],[numSteps,-numSteps]]
    if jitterSize == 0:
      self.jitter = [[0,0]]
      self.jitterLength = 1
    else:
      # eg. jitterSize = 2 ->
      #         self.jitter = [[-2,0],[-1,0],[1,0],[2,0],
      #                        [0,2],[0,1],[0,-1],[0,-2],
      #                        [0,0]]
      self.jitter = []
      listi = range(-jitterSize,0) + range(1,jitterSize+1)
      for i in listi:
        self.jitter.append([i,0])
      for i in listi:
        self.jitter.append([0,i])
      self.jitter.append([0,0])
      self.jitterLength = len(self.jitter)
      assert(self.jitterLength == 4*jitterSize+1)
开发者ID:jaredweiss,项目名称:nupic.vision,代码行数:33,代码来源:OnionSweep.py

示例9: first

  def first(self):
    """
    Set up the position.

    BaseExplorer picks image 0, offset (0,0), etc., but explorers that wish
    to set a different first position should extend this method. Such explorers
    may wish to call BaseExplorer.first(center=False), which initializes the
    position tuple but does not call centerImage() (which could cause
    unnecessary filtering to occur).
    """

    BaseExplorer.first(self, center=False)

    if not self.numImages:
      return

    isBlank = True
    while isBlank:

      # Pick a random position
      if not self.numJumpsPerImage or self.lastImageIndex is None or \
          (self.numJumpsThisImage % self.numJumpsPerImage == 0):
        # Pick new image
        image = self.pickRandomImage(self.random)
        self.lastImageIndex = image
        self.numJumpsThisImage = 0
      else:
        image = self.lastImageIndex
      self.position['image'] = image
      self.position['filters'] = self.pickRandomFilters(self.random)
      filteredImages = self.getFilteredImages()

      # Pick a random offset
      if self.spaceShape is not None:
        self.centerImage()
        # NOTE: self.position['offset'] is (x, y), whereas our spaceShape is
        #  (height, width). Also note that the self.position['offset']
        #  direction is counter-intuitive: negative numbers move us to the RIGHT
        #  and DOWN instead of LEFT and UP.
        xOffset = self.random.randint(-(self.spaceShape[1]//2), self.spaceShape[1]//2)
        yOffset = self.random.randint(-(self.spaceShape[0]//2), self.spaceShape[0]//2)
        #print "(yOffset, xOffset) = ", yOffset, xOffset
        self.position['offset'][0] += xOffset
        self.position['offset'][1] += yOffset

      else:
        ebbox = self._getEffectiveBoundingBox(filteredImages[0])
        self.position['offset'] = [
          self.random.randint(ebbox[0], ebbox[2]-1),
          self.random.randint(ebbox[1], ebbox[3]-1)
        ]

      # Check if the position is blank
      isBlank = self.isBlank(self.jumpOffObject)

    self.position['reset'] = True
    self.numJumpsThisImage += 1
开发者ID:jaredweiss,项目名称:nupic.vision,代码行数:57,代码来源:RandomJump.py

示例10: next

  def next(self, seeking=False):
    """
    Go to the next position (next iteration).

    seeking -- Boolean that indicates whether the explorer is calling next()
      from seek(). If True, the explorer should avoid unnecessary computation
      that would not affect the seek command. The last call to next() from
      seek() will be with seeking=False.
    """
    BaseExplorer.next(self)
    self._computeNextPosn()
开发者ID:jaredweiss,项目名称:nupic.vision,代码行数:11,代码来源:OnionBlock.py

示例11: first

  def first(self):
    """
    Set up the position.

    BaseExplorer picks image 0, offset (0,0), etc., but explorers that wish
    to set a different first position should extend this method. Such explorers
    may wish to call BaseExplorer.first(center=False), which initializes the
    position tuple but does not call centerImage() (which could cause
    unnecessary filtering to occur).
    """
    BaseExplorer.first(self, center=False)
    self._computeNextPosn()
开发者ID:CV-IP,项目名称:nupic.vision,代码行数:12,代码来源:RepetitiveSweep.py

示例12: next

  def next(self, seeking=False):
    """
    Go to the next position (next iteration).

    seeking -- Boolean that indicates whether the explorer is calling next()
      from seek(). If True, the explorer should avoid unnecessary computation
      that would not affect the seek command. The last call to next() from
      seek() will be with seeking=False.
    """
    BaseExplorer.next(self)

    if self._verbosity >= 1:
      print "BlockSpread: next():"

    # ========================================================================
    # Update to next position
    self._spreadPosIdx += 1
    if self._spreadPosIdx == self._numSpreadOffsets:
      self._spreadPosIdx = 0
      self._centerPosIdx += 1

      # If we've run through all the center positions, advance to the next
      #  filtered image
      if self._centerPosIdx == self._numCenterOffsets:
        self._centerPosIdx = 0

        # --------------------------------------------------------------------
        # Go to next filter for this image, or next image
        # Iterate through the filters first
        needNewImage = True
        for i in xrange(self.numFilters):
          self.position['filters'][i] += 1
          if self.position['filters'][i] < self.numFilterOutputs[i]:
            needNewImage = False
            break
          else:
            self.position['filters'][i] = 0

        # Go to the next image if ready
        if needNewImage:
          self.position['image'] += 1
          if self.position['image'] == self.numImages:
            self.position['image'] = 0

        # -----------------------------------------------------------------
        # Get the home position for this new filtered image
        self._getHomePosition()

    # ========================================================================
    # Get the X,Y corrdinates and reset signal
    if not seeking:
      self._getPosition()
开发者ID:CV-IP,项目名称:nupic.vision,代码行数:52,代码来源:BlockSpread.py

示例13: next

  def next(self, seeking=False):
    """
    Go to the next position (next iteration).

    seeking -- Boolean that indicates whether the explorer is calling next()
      from seek(). If True, the explorer should avoid unnecessary computation
      that would not affect the seek command. The last call to next() from
      seek() will be with seeking=False.
    """

    BaseExplorer.next(self)

    # If filters were changed, order may be invalid
    if self.order is None or \
        len([x for x in self.order if type(x) == int]) != self.numFilters:
      # If user did not set a custom order, just create new one automatically
      if not self.customOrder:
        self.order = ["image"]
        self.order.extend(range(self.numFilters))
        self.order += ["sweep"]
      # Otherwise, user needs to recreate the explorer with a new order
      else:
        raise RuntimeError("'order' is invalid. Must recreate explorer with "
          "valid order after changing filters.")

    if self.position['reset'] and self.blankWithReset:
      # Last iteration was a blank, so don't increment the position
      self.position['reset'] = False
    else:
      self.position['reset'] = False
      for x in reversed(self.order):
        if x == 'image':  # Iterate the image
          self.position['image'] += 1
          if self.position['image'] == self.numImages:
            self.position['image'] = 0
            self.position['reset'] = True
          else:
            break
        elif x == 'sweep':  # Iterate the sweep position
          nextImage = self._nextSweepPosition()
          if not nextImage:
            break
        else:  # Iterate the filter with index x
          self.position['filters'][x] += 1
          if self.position['filters'][x] == self.numFilterOutputs[x]:
            self.position['filters'][x] = 0
            self.position['reset'] = True
          else:
            break
      if nextImage:
        self._firstSweepPosition()
开发者ID:jaredweiss,项目名称:nupic.vision,代码行数:51,代码来源:ExhaustiveSweep.py

示例14: __init__

  def __init__(self, shift=1, aggregate='sum', *args, **kwargs):
    """
    @param shift -- Number of pixels to move from the center ("radius" of the
      eye movement square).

    @param aggregate -- A function that's used by inference analysis to
      aggregate the results of different eye movement presentations. Valid
      values are 'sum', 'average', 'product' and 'max'. The default is 'sum'.
    """

    BaseExplorer.__init__(self, *args, **kwargs)
    assert aggregate in ('sum', 'average', 'max', 'product')
    self.aggregate_func = aggregate
    self.shift = shift
开发者ID:CV-IP,项目名称:nupic.vision,代码行数:14,代码来源:EyeMovements.py

示例15: __init__

 def __init__(self, radius=4, *args, **kwargs):
   """
   @param radius: the distance from the center, in pixels, at which the
                  sweeps start;
   @param numRepetitions: number of times to present each inward sweep.
   """
   BaseExplorer.__init__(self, *args, **kwargs)
   # Parameter checking
   if type(radius) is not int or radius < 1:
     raise RuntimeError("'radius' should be a positive integer")
   # Parameters
   self._radius = radius
   # Internal state
   self._itersDone = 0
开发者ID:jaredweiss,项目名称:nupic.vision,代码行数:14,代码来源:OnionBlock.py


注:本文中的nupic.vision.regions.ImageSensorExplorers.BaseExplorer.BaseExplorer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。