def partitionIndices(self, _):
    """
    Sets self.partitions for the number of tokens for each sample in the
    training and test sets.

    The order of sequences is already specified by the network data files; if
    generated by the experiment, these are in order or randomized as specified
    by the orderedSplit arg.
    """
    if self.experimentType == "k-folds":
      for fold in xrange(self.folds):
        dataFile = self.dataFiles[fold]
        numTokens = NetworkDataGenerator.getNumberOfTokens(dataFile)
        self.partitions = KFolds(self.folds).split(numTokens, randomize=False)
    else:
      for trial, split in enumerate(self.trainSizes):
        dataFile = self.dataFiles[trial]
        numTokens = NetworkDataGenerator.getNumberOfTokens(dataFile)
        self.partitions.append((numTokens[:split], numTokens[split:]))
Exemple #2
0
    def partitionIndices(self, _):
        """
    Sets self.partitions for the number of tokens for each sample in the
    training and test sets.

    The order of sequences is already specified by the network data files; if
    generated by the experiment, these are in order or randomized as specified
    by the orderedSplit arg.
    """
        if self.experimentType == "k-folds":
            for fold in xrange(self.folds):
                dataFile = self.dataFiles[fold]
                numTokens = NetworkDataGenerator.getNumberOfTokens(dataFile)
                self.partitions = KFolds(self.folds).split(numTokens,
                                                           randomize=False)
        else:
            for trial, split in enumerate(self.trainSizes):
                dataFile = self.dataFiles[trial]
                numTokens = NetworkDataGenerator.getNumberOfTokens(dataFile)
                self.partitions.append((numTokens[:split], numTokens[split:]))
Exemple #3
0
  def partitionIndices(self, seed=42, numInference=10):
    """
    Sets self.partitions for the buckets' querying and ranking sets. The
    corresponding numbers of tokens for each sequence are stored in
    self.numTokens.

    The order of sequences is already specified by the network data files; if
    generated by the experiment, these are in order or randomized as specified
    by the orderedSplit arg.
    """
    super(BucketHTMRunner, self).partitionIndices(
      seed=seed, numInference=numInference)

    # Get the number of tokens in each bucket file so the network knows how many
    # iterations to run. The order of buckets in self.bucketFiles is not
    # necessarily the same
    ndg = NetworkDataGenerator()
    for dataFile in self.bucketFiles:
      self.numTokens.append(ndg.getNumberOfTokens(dataFile))
  animals, vegetables = getAnimalVegetableList()
  vegetable = {}
  animal = {}
  tmCellUnion = []
  tmInputUnion = []
  tpOutput = []
  categoryLabel = []
  accuracy = []
  accuracyTp = []
  knnInLastNSequences = 20
  knnNumber = 1

  plt.close('all')
  plt.figure(1)
  plt.show()
  numTokens = NetworkDataGenerator.getNumberOfTokens(args.dataPath)
  for numSample in xrange(len(numTokens)):
    # union SDR for this sequence
    tmCellActivation = np.zeros((tmRegion._tfdr.cellsPerColumn * tmRegion._tfdr.columnDimensions[0],))
    tmInputActivation = np.zeros((tmRegion._tfdr.columnDimensions[0],))
    print
    for word in xrange(numTokens[numSample]):
      sensorInput = None
      sensorOutput = {'categoryOut': np.array([0]),
                      'resetOut': [None],
                      'sourceOut': None,
                      'sequenceIdOut': [None],
                      'encodingOut': None,
                      'dataOut': np.zeros((sensorRegion.encoder.n, ))}
      sensorRegion.compute(sensorInput, sensorOutput)