def testHTM(self):
    """
    Tests ClassificationModelHTM in matching samples of text.
    
    Network model trains a KNNClassifier on all of the samples, then is
    queried with a new sample, returning a data structure (dict?) of the original samples
    and their distances to the query (similarity measure it total overlap).
    """
    runner = HTMRunner(dataPath=os.path.join(DATA_DIR, "responses.csv"),
                       resultsDir="",
                       experimentName="response_matching",
                       load=False,
                       modelName="ClassificationModelHTM",
                       modelModuleName="fluent.models.classify_htm",
                       numClasses=0,
                       plots=0,
                       orderedSplit=False,
                       trainSize=[35],
                       verbosity=0,
                       generateData=True,
                       classifierType="KNN")

    # setup data
    runner.setupData()
    
    # build model
    trial = 0
    runner.resetModel(trial)
    runner.training(trial)
    import pdb; pdb.set_trace()

    # query the model with sample text
    prototypeDistances = runner.model.queryModel("shower", False)
Beispiel #2
0
def run(args):
    start = time.time()

    root = os.path.dirname(os.path.realpath(__file__))
    args.resultsDir = os.path.join(root, args.resultsDir)

    if args.modelName == "HTMNetwork":
        runner = HTMRunner(**args.__dict__)
        runner.initModel(0)
    else:
        runner = Runner(**args.__dict__)
        runner.initModel(args.modelName)

    print "Reading in data and preprocessing."
    dataTime = time.time()
    runner.setupData(args.textPreprocess)
    print(
        "Data setup complete; elapsed time is {0:.2f} seconds.\nNow encoding "
        "the data".format(time.time() - dataTime))

    encodeTime = time.time()
    runner.encodeSamples(args.writeEncodings)
    print(
        "Encoding complete; elapsed time is {0:.2f} seconds.\nNow running the "
        "experiment.".format(time.time() - encodeTime))

    runner.runExperiment(args.seed)

    runner.writeOutClassifications()

    resultCalcs = runner.calculateResults()
    runner.evaluateCumulativeResults(resultCalcs)

    print "Saving..."
    runner.saveModel()

    print "Experiment complete in {0:.2f} seconds.".format(time.time() - start)

    if args.validation:
        print "Validating experiment against expected classifications..."
        print runner.validateExperiment(args.validation)
def run(args):
  start = time.time()

  root = os.path.dirname(os.path.realpath(__file__))
  args.resultsDir = os.path.join(root, args.resultsDir)

  if args.modelName == "HTMNetwork":
    runner = HTMRunner(**args.__dict__)
    runner.initModel(0)
  else:
    runner = Runner(**args.__dict__)
    runner.initModel(args.modelName)

  print "Reading in data and preprocessing."
  dataTime = time.time()
  runner.setupData(args.textPreprocess)
  print ("Data setup complete; elapsed time is {0:.2f} seconds.\nNow encoding "
         "the data".format(time.time() - dataTime))

  encodeTime = time.time()
  runner.encodeSamples(args.writeEncodings)
  print ("Encoding complete; elapsed time is {0:.2f} seconds.\nNow running the "
         "experiment.".format(time.time() - encodeTime))

  runner.runExperiment(args.seed)

  runner.writeOutClassifications()

  resultCalcs = runner.calculateResults()
  runner.evaluateCumulativeResults(resultCalcs)

  print "Saving..."
  runner.saveModel()

  print "Experiment complete in {0:.2f} seconds.".format(time.time() - start)

  if args.validation:
    print "Validating experiment against expected classifications..."
    print runner.validateExperiment(args.validation)
                     modelName=args.modelName,
                     retinaScaling=args.retinaScaling,
                     retina=args.retina,
                     apiKey=args.apiKey,
                     numClasses=args.numClasses,
                     plots=args.plots,
                     orderedSplit=args.orderedSplit,
                     folds=args.folds,
                     trainSizes=args.trainSizes,
                     verbosity=args.verbosity,
                     generateData=args.generateData,
                     votingMethod=args.votingMethod,
                     classificationFile=args.classificationFile,
                     seed=args.seed)
  runner.initModel(0)
  runner.setupData(args.textPreprocess)
  runner.encodeSamples()
  runner.partitionIndices(args.seed)

  sensorRegion, spRegion, tmRegion, tpRegion, knnRegion = getNupicRegions(runner.model.network)
  tmRegion.learningMode = True
  tmRegion.computePredictedActiveCellIndices = True

  categoryList = ['animal-eats-vegetable', 'vegetable-eats-animal']
  animals, vegetables = getAnimalVegetableList()
  vegetable = {}
  animal = {}
  tmCellUnion = []
  tmInputUnion = []
  tpOutput = []
  categoryLabel = []