def createModel(args): """ Return a classification model of the appropriate type. The model could be any supported subclass of ClassficationModel based on args. """ if args.modelName == "htm": # Instantiate the HTM model model = ClassificationModelHTM(networkConfig=getNetworkConfig( args.networkConfigPath), inputFilePath=None, retina=args.retina, verbosity=args.verbosity, numLabels=2, prepData=False, modelDir="tempdir") elif args.modelName == "keywords": # Instantiate the keywords model model = ClassificationModelKeywords(verbosity=args.verbosity, numLabels=2, k=9, modelDir="tempdir") elif args.modelName == "docfp": # Instantiate the document fingerprint model model = ClassificationModelDocumentFingerprint( verbosity=args.verbosity, retina=args.retina, numLabels=2, k=3) else: raise RuntimeError("Unknown model type: " + args.modelName) return model
def initModel(self, trial=0): """ Load or instantiate the classification model. Assumes network data is already setup. """ if self.loadPath: with open(self.loadPath, "rb") as f: self.model = pkl.load(f) # TODO: uncomment once we can save TPRegion; do we need this? # networkFile = self.model.network # self.model.network = Network(networkFile) print "Model loaded from \'{0}\'.".format(self.loadPath) else: print "Creating HTM classification model..." self.model = ClassificationModelHTM( self.networkConfig, self.dataFiles[trial], retinaScaling=self.retinaScaling, retina=self.retina, apiKey=self.apiKey, verbosity=self.verbosity, numLabels=self.numClasses, modelDir=self.modelDir, prepData=False)