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


Python BaseExplorer.first方法代码示例

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


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

示例1: first

# 需要导入模块: from nupic.regions.ImageSensorExplorers.BaseExplorer import BaseExplorer [as 别名]
# 或者: from nupic.regions.ImageSensorExplorers.BaseExplorer.BaseExplorer import first [as 别名]
  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:AndreCAndersen,项目名称:nupic,代码行数:35,代码来源:ManualSaliency.py

示例2: first

# 需要导入模块: from nupic.regions.ImageSensorExplorers.BaseExplorer import BaseExplorer [as 别名]
# 或者: from nupic.regions.ImageSensorExplorers.BaseExplorer.BaseExplorer import first [as 别名]
  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:0x0all,项目名称:nupic,代码行数:27,代码来源:BlockSpread.py

示例3: first

# 需要导入模块: from nupic.regions.ImageSensorExplorers.BaseExplorer import BaseExplorer [as 别名]
# 或者: from nupic.regions.ImageSensorExplorers.BaseExplorer.BaseExplorer import first [as 别名]
    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:nithindd,项目名称:nupic,代码行数:62,代码来源:RandomJump.py

示例4: first

# 需要导入模块: from nupic.regions.ImageSensorExplorers.BaseExplorer import BaseExplorer [as 别名]
# 或者: from nupic.regions.ImageSensorExplorers.BaseExplorer.BaseExplorer import first [as 别名]
  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:AI-Cdrone,项目名称:nupic,代码行数:14,代码来源:RepetitiveSweep.py

示例5: first

# 需要导入模块: from nupic.regions.ImageSensorExplorers.BaseExplorer import BaseExplorer [as 别名]
# 或者: from nupic.regions.ImageSensorExplorers.BaseExplorer.BaseExplorer import first [as 别名]
  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)

    self.diagdiri = 0
    self.diagi = 0
    self.position['offset'][0] += self.numSteps
    self.cent = list(self.position['offset'])
    self.jitteri = 0
开发者ID:akhilaananthram,项目名称:nupic,代码行数:20,代码来源:OnionSweep.py

示例6: first

# 需要导入模块: from nupic.regions.ImageSensorExplorers.BaseExplorer import BaseExplorer [as 别名]
# 或者: from nupic.regions.ImageSensorExplorers.BaseExplorer.BaseExplorer import first [as 别名]
  def first(self, center=True):
    """
    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)
    self._resetIndex()

    offsets = self._getCurrentOffsets()
    # Set the 2 dimensions of the position.
    for i in (0,1):
      self.position['offset'][i] = offsets[self.index][i]
开发者ID:akhilaananthram,项目名称:nupic,代码行数:20,代码来源:SpiralSweep.py

示例7: first

# 需要导入模块: from nupic.regions.ImageSensorExplorers.BaseExplorer import BaseExplorer [as 别名]
# 或者: from nupic.regions.ImageSensorExplorers.BaseExplorer.BaseExplorer import first [as 别名]
  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

    if not self.replacement \
        and len(self.history) == self.getNumIterations(None):
      # All images have been visited
      self.history = []

    while True:
      self.position['image'] = self.pickRandomImage(self.random)
      self.position['filters'] = self.pickRandomFilters(self.random)
      index = self.random.randint(0, 8)
      historyItem = (self.position['image'], self.position['filters'][:], index)
      if self.replacement or historyItem not in self.history:
        # Use this position
        if not self.replacement:
          # Add to the history
          self.history.append(historyItem)
        # Calculate the offset from the eye movement index
        if index in (1, 2, 3):
          self.position['offset'][1] -= self.shift
        elif index in (5, 6, 7):
          self.position['offset'][1] += self.shift
        if index in (1, 7, 8):
          self.position['offset'][0] -= self.shift
        elif index in (3, 4, 5):
          self.position['offset'][0] += self.shift
        break

    self.position['reset'] = True
开发者ID:0x0all,项目名称:nupic,代码行数:45,代码来源:RandomEyeMovements.py

示例8: first

# 需要导入模块: from nupic.regions.ImageSensorExplorers.BaseExplorer import BaseExplorer [as 别名]
# 或者: from nupic.regions.ImageSensorExplorers.BaseExplorer.BaseExplorer import first [as 别名]
  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

    # Pick a random dimension (exclude filters without multiple outputs)
    filters = []
    for i in xrange(self.numFilters):
      if self.numFilterOutputs[i] > 1:
        filters.append(i)
    legalDimensions = self.dimensions[:]
    for d in self.dimensions:
      if type(d['name']) is int and d['name'] not in filters:
        legalDimensions.remove(d)
    # Choice is weighted by probabilities
    r = self.random.uniform(0, sum([d['probability'] for d in legalDimensions]))
    for i, d in enumerate(legalDimensions):
      if r <= d['probability']:
        self.dimension = d
        break
      r -= d['probability']

    self.start = None
    restart = True
    while restart:

      self.position['reset'] = False
      restart = False

      # Translation sweep
      if self.dimension['name'] == 'translation':

        # Pick a random direction, image, and set of filters
        self.direction = self.random.choice(('left', 'right', 'up', 'down',
          'leftdown', 'leftup', 'rightdown', 'rightup'))
        self.position['image'] = self.pickRandomImage(self.random)
        self.position['filters'] = self.pickRandomFilters(self.random)
        filteredImages = self.getFilteredImages()
        ebbox = self._getEffectiveBoundingBox(filteredImages[0])

        # Align starting position at zero offset position.
        forceAlignment = self.dimension.get('forceAlignment')
        if forceAlignment is not None and forceAlignment:
          self.position['offset'] = [0,0]
        # Pick a random starting position on the appropriate edge of the image
        else:
          self._firstTranslationPosition(ebbox, filteredImages[0])

        # Increment the start position until it is not blank
        while self.isBlank(self.dimension['sweepOffObject']):
          self._nextTranslationPosition(shift=1)
          if self.position['reset'] or not self.isValid():
            restart = True
            break
        if restart:
          continue

        # Increment the position by a random amount in the range [0, shift)
        if not forceAlignment:
          self._nextTranslationPosition(randomShift=True)

      # Image sweep
      elif self.dimension['name'] == 'image':

        # Pick a random direction
        self.direction = self.random.choice(('up', 'down'))

        # Pick a random image and find the first or last image in the category
        image = self.pickRandomImage(self.random)
        startCategory = self.getImageInfo(image)['categoryIndex']
        if self.direction == 'up':
          while image > 0 and \
              self.getImageInfo(image-1)['categoryIndex'] == startCategory:
            image -= 1
        else:
          while image < self.numImages - 1 and \
              self.getImageInfo(image+1)['categoryIndex'] == startCategory:
            image += 1
        self.position['image'] = image

        # Pick the filters
        self.position['filters'] = self.pickRandomFilters(self.random)
        filteredImages = self.getFilteredImages()

        # Pick a random position within the bounding box
        ebbox = self._getEffectiveBoundingBox(filteredImages[0])
        self.position['offset'] = [
          self.random.randint(ebbox[0], ebbox[2]-1),
          self.random.randint(ebbox[1], ebbox[3]-1)
#.........这里部分代码省略.........
开发者ID:AndreCAndersen,项目名称:nupic,代码行数:103,代码来源:MultiSweep.py

示例9: first

# 需要导入模块: from nupic.regions.ImageSensorExplorers.BaseExplorer import BaseExplorer [as 别名]
# 或者: from nupic.regions.ImageSensorExplorers.BaseExplorer.BaseExplorer import first [as 别名]
  def first(self, seeking=False):
    """
    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).

    seeking -- Passed from seek() through next() to avoid loading images
      unnecessarily when seeking.
    """

    BaseExplorer.first(self, center=False)

    if not self.numImages:
      return

    if not self.replacement \
        and len(self.history) == self.getNumIterations(None):
      # All images have been visited
      self.history = []

    if self.equalizeCategories:
      # Breakdown the images by category
      if self.imagesByCat is None:
        categoryIndex = []
        for k in range(self.numImages):
          categoryIndex += [self.getImageInfo(k)['categoryIndex']]
        categories = list(set(categoryIndex))
        numCats = len(categories)

        catPopulation = {}
        imagesByCat = {}
        for catIndex in categories:
          #catPopulation[catIndex] = len([c for c in categoryIndex if c == catIndex])
          imagesByCat[catIndex] = [k for k, c in enumerate(categoryIndex) if c == catIndex]
          catPopulation[catIndex] = len(imagesByCat[catIndex])
        minNumSamples = min([pop for (cat, pop) in catPopulation.items()])
        totalNumSamples = minNumSamples * numCats
        # Store
        self.imagesByCat = imagesByCat
        self.categories = categories
        self.numCategories = numCats
        self.nextCatIndex = 0

      # Pick random image from next category
      thisCat = self.imagesByCat[self.nextCatIndex]
      #randomImageIndex = random.randint(0, len(thisCat))
      self.position['image'] = self.random.choice(thisCat)
      self.position['filters'] = self.pickRandomFilters(self.random)
      self.nextCatIndex = (self.nextCatIndex + 1) % self.numCategories

    else:
      # Pick a random image and set of filters
      while self.start >= 0:

        finished = False
        while not finished:
          # Pick a position randomly
          self.position['image'] = self.pickRandomImage(self.random)
          self.position['filters'] = self.pickRandomFilters(self.random)
          # Pick again if not replacing and this position has been visited
          if self.replacement or (self.position['image'],
              self.position['filters']) not in self.history:
            finished = True

        if not self.replacement:
          # Remember this position
          self.history.append(
            (self.position['image'], self.position['filters'][:]))

        self.start -= 1

      self.start = 0

    if not seeking:
      self.centerImage()
开发者ID:akhilaananthram,项目名称:nupic,代码行数:81,代码来源:RandomFlash.py

示例10: first

# 需要导入模块: from nupic.regions.ImageSensorExplorers.BaseExplorer import BaseExplorer [as 别名]
# 或者: from nupic.regions.ImageSensorExplorers.BaseExplorer.BaseExplorer import first [as 别名]
    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

        # Pick a random direction and filtered image
        self.direction = self.random.choice(self.sweepDirections)
        self.position["image"] = self.random.randint(0, self.numImages - 1)
        for i in xrange(self.numFilters):
            self.position["filters"][i] = self.random.randint(0, self.numFilterOutputs[i] - 1)
        filteredImages = self.getFilteredImages()

        # Pick a random starting position on the appropriate edge of the image
        sbbox = self._getSweepBoundingBox(filteredImages[0])

        if self.direction == "left":
            self.position["offset"][0] = sbbox[2] - 1
            self.position["offset"][1] = self.random.randint(sbbox[1], sbbox[3] - 1)
        elif self.direction == "right":
            self.position["offset"][0] = sbbox[0]
            self.position["offset"][1] = self.random.randint(sbbox[1], sbbox[3] - 1)
        elif self.direction == "up":
            self.position["offset"][0] = self.random.randint(sbbox[0], sbbox[2] - 1)
            self.position["offset"][1] = sbbox[3] - 1
        elif self.direction == "down":
            self.position["offset"][0] = self.random.randint(sbbox[0], sbbox[2] - 1)
            self.position["offset"][1] = sbbox[1]
        elif self.direction in ("leftup", "upleft"):
            if self.random.randint(0, 1):
                self.position["offset"][0] = self.random.randint(sbbox[0] + (sbbox[2] - sbbox[0]) / 2, sbbox[2] - 1)
                self.position["offset"][1] = sbbox[3] - 1
            else:
                self.position["offset"][0] = sbbox[2] - 1
                self.position["offset"][1] = self.random.randint(sbbox[1] + (sbbox[3] - sbbox[1]) / 2, sbbox[3] - 1)
        elif self.direction in ("leftdown", "downleft"):
            if self.random.randint(0, 1):
                self.position["offset"][0] = self.random.randint(sbbox[0] + (sbbox[2] - sbbox[0]) / 2, sbbox[2] - 1)
                self.position["offset"][1] = sbbox[1]
            else:
                self.position["offset"][0] = sbbox[2] - 1
                self.position["offset"][1] = self.random.randint(sbbox[1], sbbox[3] - 1 - (sbbox[3] - sbbox[1]) / 2)
        elif self.direction in ("rightup", "upright"):
            if self.random.randint(0, 1):
                self.position["offset"][0] = self.random.randint(sbbox[0], sbbox[2] - 1 - (sbbox[2] - sbbox[0]) / 2)
                self.position["offset"][1] = sbbox[3] - 1
            else:
                self.position["offset"][0] = sbbox[0]
                self.position["offset"][1] = self.random.randint(sbbox[1] + (sbbox[3] - sbbox[1]) / 2, sbbox[3] - 1)
        elif self.direction in ("rightdown", "downright"):
            if self.random.randint(0, 1):
                self.position["offset"][0] = self.random.randint(sbbox[0], sbbox[2] - 1 - (sbbox[2] - sbbox[0]) / 2)
                self.position["offset"][1] = sbbox[1]
            else:
                self.position["offset"][0] = sbbox[0]
                self.position["offset"][1] = self.random.randint(sbbox[1], sbbox[3] - 1 - (sbbox[3] - sbbox[1]) / 2)

        # Increment the position by a random amount in the range
        # [0, shiftDuringSweep)
        if self.shiftDuringSweep > 1:
            prevShiftDuringSweep = self.shiftDuringSweep
            self.shiftDuringSweep = self.random.randint(0, self.shiftDuringSweep)
            self._nextSweepPosition()
            self.shiftDuringSweep = prevShiftDuringSweep
            if self.position["reset"]:
                self.first()

        self.position["reset"] = True
开发者ID:nithindd,项目名称:nupic,代码行数:80,代码来源:RandomSweep.py


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