コード例 #1
0
 def __init__(self):
     """ Initializes the eLCS algorithm """
     print("eLCS: Initializing Algorithm...")
     #Global Parameters-------------------------------------------------------------------------------------
     self.population = None          # The rule population (the 'solution/model' evolved by eLCS)
     self.learnTrackOut = None       # Output file that will store tracking information during learning
     
     #-------------------------------------------------------
     # POPULATION REBOOT - Begin eLCS learning from an existing saved rule population
     #-------------------------------------------------------
     if cons.doPopulationReboot:    
         self.populationReboot()
         
     #-------------------------------------------------------
     # NORMAL eLCS - Run eLCS from scratch on given data
     #-------------------------------------------------------
     else:
         try:
             self.learnTrackOut = open(cons.outFileName+'_LearnTrack.txt','w')   
         except Exception as inst:
             print(type(inst))
             print(inst.args)
             print(inst)
             print('cannot open', cons.outFileName+'_LearnTrack.txt')
             raise 
         else:  
             self.learnTrackOut.write("Explore_Iteration\tMacroPopSize\tMicroPopSize\tAccuracy_Estimate\tAveGenerality\tExpRules\tTime(min)\n")
         
         # Instantiate Population---------
         self.population = ClassifierSet()
         self.exploreIter = 0
         self.correct  = [0.0 for i in range(cons.trackingFrequency)]
         
     #Run the eLCS algorithm-------------------------------------------------------------------------------
     self.results = self.run_eLCS()
コード例 #2
0
ファイル: eLCS_Algorithm.py プロジェクト: zxzang/eLCS
    def populationReboot(self):
        """ Manages the reformation of a previously saved eLCS classifier population. """
        #--------------------------------------------------------------------
        try:  #Re-open track learning file for continued tracking of progress.
            self.learnTrackOut = open(cons.outFileName + '_LearnTrack.txt',
                                      'a')
        except Exception as inst:
            print(type(inst))
            print(inst.args)
            print(inst)
            print('cannot open', cons.outFileName + '_LearnTrack.txt')
            raise

        #Extract last iteration from file name---------------------------------------------
        temp = cons.popRebootPath.split('_')
        iterRef = len(temp) - 1
        completedIterations = int(temp[iterRef])
        print("Rebooting rule population after " + str(completedIterations) +
              " iterations.")
        self.exploreIter = completedIterations - 1
        for i in range(len(cons.learningCheckpoints)):
            cons.learningCheckpoints[i] += completedIterations
        cons.maxLearningIterations += completedIterations

        #Rebuild existing population from text file.--------
        self.population = ClassifierSet(cons.popRebootPath)
コード例 #3
0
    def populationReboot(self):
        """ Manages the reformation of a previously saved eLCS classifier population. """
        #--------------------------------------------------------------------
        try:  #Re-open track learning file for continued tracking of progress.
            self.learnTrackOut = open(cons.outFileName + '_LearnTrack.txt',
                                      'a')
        except Exception as inst:
            print(type(inst))
            print(inst.args)
            print(inst)
            print('cannot open', cons.outFileName + '_LearnTrack.txt')
            raise

        #Extract last iteration from file name---------------------------------------------
        temp = cons.popRebootPath.split('_')
        iterRef = len(temp) - 1
        completedIterations = int(temp[iterRef])
        print("Rebooting rule population after " + str(completedIterations) +
              " iterations.")
        self.exploreIter = completedIterations - 1
        for i in range(len(cons.learningCheckpoints)):
            cons.learningCheckpoints[i] += completedIterations
        cons.maxLearningIterations += completedIterations

        #Rebuild existing population from text file.--------
        self.population = ClassifierSet(cons.popRebootPath)
        #---------------------------------------------------
        try:  #Obtain correct track
            f = open(cons.popRebootPath + "_PopStats.txt", 'r')
        except Exception as inst:
            print(type(inst))
            print(inst.args)
            print(inst)
            print('cannot open', cons.outFileName + '_LearnTrack.txt')
            raise
        else:
            correctRef = 26  #File reference position - only works with eLCS demo version 5 or 6 PopStats output files.

            tempLine = None
            for i in range(correctRef):
                tempLine = f.readline()
            tempList = tempLine.strip().split('\t')
            self.correct = tempList
            if cons.env.formatData.discretePhenotype:
                for i in range(len(self.correct)):
                    self.correct[i] = int(self.correct[i])
            else:
                for i in range(len(self.correct)):
                    self.correct[i] = float(self.correct[i])
            f.close()
コード例 #4
0
    def __init__(self):
        """ Initializes the eLCS algorithm """
        #Global Parameters-------------------------------------------------------------------------------------
        self.population = None  # The rule population (the 'solution/model' evolved by eLCS)
        self.learnTrackOut = None  # Output file that will store tracking information during learning

        #-------------------------------------------------------
        # POPULATION REBOOT - Begin eLCS learning from an existing saved rule population
        #-------------------------------------------------------
        if cons.doPopulationReboot:
            self.populationReboot()

        #-------------------------------------------------------
        # NORMAL eLCS - Run eLCS from scratch on given data
        #-------------------------------------------------------
        else:
            # Instantiate Population---------
            self.population = ClassifierSet()
            self.exploreIter = 0
            self.correct = [0.0 for i in range(cons.trackingFrequency)]

        #Run the eLCS algorithm-------------------------------------------------------------------------------
        self.run_eLCS()