def __init__(self,
                 verbosity=1,
                 numLabels=3,
                 modelDir="ClassificationModelFingerprint",
                 fingerprintType=EncoderTypes.word,
                 unionSparsity=20.0):

        super(ClassificationModelFingerprint,
              self).__init__(verbosity=verbosity,
                             numLabels=numLabels,
                             modelDir=modelDir)

        # Init kNN classifier and Cortical.io encoder; need valid API key (see
        # CioEncoder init for details).
        self.classifier = KNNClassifier(k=numLabels,
                                        distanceMethod='rawOverlap',
                                        exact=False,
                                        verbosity=verbosity - 1)

        if fingerprintType is (not EncoderTypes.document
                               or not EncoderTypes.word):
            raise ValueError("Invaid type of fingerprint encoding; see the "
                             "EncoderTypes class for eligble types.")
        self.encoder = CioEncoder(cacheDir="./fluent/experiments/cioCache",
                                  fingerprintType=fingerprintType,
                                  unionSparsity=unionSparsity)
        self.n = self.encoder.n
        self.w = int((self.encoder.targetSparsity / 100) * self.n)
Esempio n. 2
0
  def __init__(self, inputFilePath, verbosity=1, numLabels=3, spTrainingSize=0,
               tmTrainingSize=0, clsTrainingSize=0, classifierType="KNN"):
    """
    @param inputFilePath      (str)       Path to data formatted for network
                                          API
    @param spTrainingSize     (int)       Number of samples the network has to
                                          be trained on before training the
                                          spatial pooler
    @param tmTrainingSize     (int)       Number of samples the network has to
                                          be trained on before training the
                                          temporal memory
    @param clsTrainingSize    (int)       Number of samples the network has to
                                          be trained on before training the
                                          classifier
    @param classifierType     (str)       Either "KNN" or "CLA"
    See ClassificationModel for remaining parameters
    """
    self.spTrainingSize = spTrainingSize
    self.tmTrainingSize = tmTrainingSize
    self.clsTrainingSize = clsTrainingSize

    super(ClassificationModelHTM, self).__init__(verbosity=verbosity,
      numLabels=numLabels)

    # Initialize Network
    self.classifierType = classifierType
    self.recordStream = FileRecordStream(streamID=inputFilePath)
    self.encoder = CioEncoder(cacheDir="./experiments/cache")
    self._initModel()
Esempio n. 3
0
    def initModel(self):
        """
    Initialize the network; self.networdDataPath must already be set.
    """
        recordStream = FileRecordStream(streamID=self.networkDataPath)
        encoder = CioEncoder(cacheDir="./experiments/cache")

        return configureNetwork(recordStream, self.networkConfig, encoder)
Esempio n. 4
0
  def testWordFingerprint(self):
    """Test the Cortical.io term (word-lelevl) encoding."""

    cio = CioEncoder(fingerprintType=EncoderTypes.word)
    response = cio.encode(self.text)
    
    self.assertFingerprintFields(response)
    
    encodingDict = getTestData("cio_encoding_word.json")
    self.assertEqual(encodingDict["fingerprint"]["positions"],
        response["fingerprint"]["positions"], "Cio bitmap is not as expected.")
Esempio n. 5
0
    def __init__(self, verbosity=1, numLabels=1):
        """
    Initialize the CorticalClient and CioEncoder. Requires a valid API key
    """
        super(ClassificationModelContext, self).__init__(verbosity)

        self.encoder = CioEncoder(cacheDir="./experiments/cache")
        self.client = CorticalClient(self.encoder.apiKey)

        self.n = self.encoder.n
        self.w = int((self.encoder.targetSparsity / 100) * self.n)

        self.categoryBitmaps = {}
        self.numLabels = numLabels
Esempio n. 6
0
    def __init__(self, verbosity=1, numLabels=3):
        """
    Initialize the encoder as CioEncoder; requires a valid API key.
    """
        super(ClassificationModelEndpoint, self).__init__(verbosity, numLabels)

        self.encoder = CioEncoder(cacheDir="./experiments/cache")
        self.compareEncoder = LanguageEncoder()

        self.n = self.encoder.n
        self.w = int((self.encoder.targetSparsity / 100) * self.n)

        self.categoryBitmaps = {}
        self.negatives = defaultdict(list)
        self.positives = defaultdict(list)