Esempio n. 1
0
    def setup(self, inDataFile, inProbArrFile, archModelInFile):
        """Method to load in the data and process the target data"""
        self.archModel = loadArchModel(archModelInFile)
        self.archModel.setupParams()

        ifs = open(inProbArrFile)
        self.probArr = []
        for line in ifs:
            chunks = line.strip().split()
            self.probArr.append([int(chunks[0]),
                                 int(chunks[2])])
        ifs.close()
        self.probArr = array(self.probArr)

        self.fDictList = []
        ifs = gzip.open(inDataFile)
        reader = FeatureDictReader(ifs)
        for d in reader:
            self.fDictList.append(d)
        ifs.close()

        self.classifier = PairMonteFeatDictClassifier(self.archModel,
                                                      self.fDictList,
                                                      self.probArr,
                                                      self.postEpochCallback)
        self.classifier.setupModels()
Esempio n. 2
0
    def setup(self, inDataFile, inTargDataFile, archModelInFile):
        """Method to load in the data and process the target data"""
        self.archModel = loadArchModel(archModelInFile)
        self.archModel.setupParams()

        ifs = open(inTargDataFile)
        self.idxArr = []
        self.targArr = []
        for iRow, line in enumerate(ifs):
            row = line.strip().split()
            self.idxArr.append(int(row[0]))
            self.targArr.append(float(row[self.targcolumn]))
        ifs.close()
        self.idxArr = array(self.idxArr)
        self.targArr = array(self.targArr)

        self.fDictList = []
        ifs = gzip.open(inDataFile)
        reader = FeatureDictReader(ifs)
        for d in reader:
            self.fDictList.append(d)
        ifs.close()

        self.classifier = MonteFeatDictClassifier(self.archModel,
                                                  self.fDictList, self.targArr,
                                                  self.idxArr,
                                                  self.postEpochCallback)
        self.classifier.setupModels()
 def main(self, argv):
     """Callable from Command line"""
     if argv is None:
         argv = sys.argv
     
     usageStr = \
         """usage: %prog [options] archModelFile featDataFile idxArrFile outFile
         """
     parser = OptionParser(usage = usageStr);
     parser.add_option('-d', '--deduplicate', dest='deduplicate', action='store_true', default=False,
         help='Deduplicate the idArr');
     parser.add_option('--delimiter', dest='delimiter', default=' ');
     (options, args) = parser.parse_args(argv[1:])
     
     if len(args) == 4:
         (archModelFile, featDataFile, idxArrFile, outFile) = args;
         self.archModel = loadArchModel(archModelFile);
         self.setup();
         
         ifs = open(idxArrFile);
         reader = csv.reader(ifs, quoting=csv.QUOTE_NONE, delimiter=options.delimiter);
         seenIds = set([]);
         idArr = [];
         for row in reader:
             row[0] = int(row[0]);
             row[1:] = [float(x) for x in row[1:]];
             if options.deduplicate:
                 if row[0] not in seenIds: 
                     idArr.append(row);
                     seenIds.add(row[0]);
             else:
                 idArr.append(row);
         ifs.close();
         
         ifs = gzip.open(featDataFile)
         reader = FeatureDictReader(ifs);
         fDictList = [];
         for aDict in reader:
             fDictList.append(aDict);
         ifs.close();
         
         progress = ProgressDots();
         
         ofs = open(outFile, 'w');
         for idChunk, predValChunk in self.predict(fDictList, idArr):
             for iRow in range(len(idChunk)):
                 chunkTargData = [str(x) for x in idChunk[iRow]]
                 chunkTargData = ' '.join(chunkTargData)
                 print >>ofs, chunkTargData, predValChunk[iRow];
                 progress.Update();
         ofs.close();
         progress.PrintStatus();
     else:
         parser.print_help();
         sys.exit(2);
Esempio n. 4
0
 def setup(self, inDataFile, inProbArrFile, archModelInFile):
     """Method to load in the data and process the target data"""
     self.archModel = loadArchModel(archModelInFile);
     self.archModel.setupParams();
     
     ifs = open(inProbArrFile);
     self.probArr = [];
     for line in ifs:
         chunks = line.strip().split()
         self.probArr.append([int(chunks[0]), int(chunks[2])]);
     ifs.close();
     self.probArr = array(self.probArr);
     
     self.fDictList = [];
     ifs = gzip.open(inDataFile);
     reader = FeatureDictReader(ifs);
     for d in reader:
         self.fDictList.append(d);
     ifs.close();
     
     self.classifier = PairMonteFeatDictClassifier(self.archModel, self.fDictList,
                                                   self.probArr, self.postEpochCallback)
     self.classifier.setupModels();
Esempio n. 5
0
 def main(self, argv):
     """Callable from Command line"""
     if argv is None:
         argv = sys.argv
     
     usageStr = \
         """usage: %prog [options] archModelFile featDataFile outFile
         """
     
     parser = OptionParser(usage = usageStr);
     (options, args) = parser.parse_args(argv[1:])
     
     if len(args) == 3:
         archModelFile = args[0]
         featDataFile = args[1]
         outFile = args[2]
         
         #Read in the 
         self.archModel = loadArchModel(archModelFile);
         self.setup();
         
         # Then set up the reader and writer
         ifs = gzip.open(featDataFile);
         reader = FeatureDictReader(ifs);
         ofs = open(outFile, 'w');
         progress = ProgressDots();
         
         for value in self.predict(reader):
             print >> ofs, value;
             progress.Update();
         progress.PrintStatus();
         
         ifs.close();
         ofs.close();
     else:
         parser.print_help();
         sys.exit(2);
Esempio n. 6
0
    def main(self, argv):
        """Callable from Command line"""
        if argv is None:
            argv = sys.argv

        usageStr = \
            """usage: %prog [options] archModelFile featDataFile outFile
            """

        parser = OptionParser(usage=usageStr)
        (options, args) = parser.parse_args(argv[1:])

        if len(args) == 3:
            archModelFile = args[0]
            featDataFile = args[1]
            outFile = args[2]

            #Read in the
            self.archModel = loadArchModel(archModelFile)
            self.setup()

            # Then set up the reader and writer
            ifs = gzip.open(featDataFile)
            reader = FeatureDictReader(ifs)
            ofs = open(outFile, 'w')
            progress = ProgressDots()

            for value in self.predict(reader):
                print >> ofs, value
                progress.Update()
            progress.PrintStatus()

            ifs.close()
            ofs.close()
        else:
            parser.print_help()
            sys.exit(2)
Esempio n. 7
0
 def loadArchModelFromFile(self, fileName):
     """Convenience to load up the archModel from a file"""
     self.archModel = loadArchModel(fileName);
 def loadArchModelFromFile(self, fileName):
     """Convenience to load up the archModel from a file"""
     self.archModel = loadArchModel(fileName);