當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。