def testClassifyHTMUsingTPAsExpectedWithKNN(self): """ Tests ClassificationModelHTM using TP region. Training on the first five samples of the dataset, and testing on the rest, the model's classifications should match those in the expected classes data file. """ modelName = "HTMNetwork" runner = HTMRunner(dataPath=os.path.join(DATA_DIR, "responses_network.csv"), networkConfigPath=os.path.join( DATA_DIR, "network_config_tp_knn.json"), resultsDir="", experimentName="htm_test", experimentType="incremental", loadPath=None, modelName=modelName, numClasses=3, plots=0, orderedSplit=True, trainSizes=[5], verbosity=0, generateData=False, votingMethod="last", classificationFile=os.path.join( DATA_DIR, "responses_categories.json")) runner.initModel(0) runner.runExperiment() expectedClasses, resultClasses = self.getExpectedClassifications(runner, os.path.join(DATA_DIR, "responses_expected_classes_htm_tp.csv")) [self.assertEqual(sorted(e), sorted(r), "HTM model predicted classes other than what we expect.") for e, r in zip(expectedClasses, resultClasses)]
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)
def testClassifyHTMAsExpectedWithKNN(self): """ Tests ClassificationModelHTM, where the network is LanguageSensor->KNNClassifier. Training on the first five samples of the dataset, and testing on the rest, the model's classifications should match those in the expected classes data file. """ modelName = "HTMNetwork" runner = HTMRunner(dataPath=os.path.join(DATA_DIR, "responses.csv"), networkConfigPath=os.path.join( DATA_DIR, "network_config_ls_knn.json"), resultsDir="", experimentName="htm_test", experimentType="incremental", loadPath=None, modelName=modelName, numClasses=3, plots=0, orderedSplit=True, trainSizes=[5], verbosity=0, generateData=True, votingMethod="most") runner.initModel(0) runner.runExperiment() expectedClasses, resultClasses = self.getExpectedClassifications( runner, os.path.join(DATA_DIR, "responses_expected_classes_htm.csv")) [ self.assertEqual( sorted(e), sorted(r), "HTM model predicted classes other than what we expect.") for e, r in zip(expectedClasses, resultClasses) ]
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)
networkConfigPath='data/network_configs/tm_tp_knn_4k_retina.json') else: args = inputParameters(retina=args.retina, apiKey=args.apiKey, networkConfigPath='data/network_configs/tm_knn_4k_retina.json') runner = HTMRunner(dataPath=args.dataPath, networkConfigPath=args.networkConfigPath, resultsDir=args.resultsDir, experimentName=args.experimentName, experimentType=args.experimentType, loadPath=args.loadPath, 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)
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)