Exemplo n.º 1
0
    def calculate_Population_fitness(self, part):
        # (h,w)
        DomBlockSize = (16,16)
        RanBlockSize = (8,8)
        max_fitness = 1000000000
        ranking = []
        
        for chrom in part:
            # genes
            gen_x_dom = chrom[0:9]
            gen_y_dom = chrom[9:18]
            gen_flip  = chrom[18:21]
    
            # fenotypes
            fen_xdom  = int(gen_x_dom,2)  # 2 for binary representation
            fen_ydom  = int(gen_y_dom,2)  
            fen_flip  = int(gen_flip,2)
            
            try:
                DomBlk = self.Dom[fen_ydom:fen_ydom+DomBlockSize[0] ,fen_xdom:fen_xdom+DomBlockSize[1]]
            except:
                return "DomBlkError"
            
            try:
                DomBlk_hex = rgb2hex(DomBlk.copy())
            except:
                return "rgb2hexError"
            
            try:
                temp = get_scaled.geometric_transform(DomBlk_hex, resize_func, output_shape=RanBlockSize)
            except:
                return "transformError"    
            
            try:
                DomBlk_subsampled = get_dihedrical_transf(temp,fen_flip)
            except:
                return "dihedrTransformError"    
            #p,q = calc_massic(DomBlk_subsampled,rngBlk)
            
            try:
                MSE = self.calculate_mse(DomBlk_subsampled)
            except MSEError,E:
                return E.reason
            try:
                rank = min(1/MSE,max_fitness)
            except ZeroDivisionError:
                rank = max_fitness

            heappush(ranking,(rank,chrom))
Exemplo n.º 2
0
def get_phenotype(chrom, Dom,DomBlockSize, RanBlockSize ):
    gen_x_dom = chrom[0:9]
    gen_y_dom = chrom[9:18]
    gen_flip  = chrom[18:21]
    
    # fenotypes
    fen_xdom  = int(gen_x_dom,2)  # 2 for binary representation
    fen_ydom  = int(gen_y_dom,2)  
    fen_flip  = int(gen_flip,2)
    
    DomBlk = Dom[fen_ydom:fen_ydom+DomBlockSize[0] ,fen_xdom:fen_xdom+DomBlockSize[1]]
    DomBlk_hex = rgb2hex(DomBlk.copy())
    temp = get_scaled.geometric_transform(DomBlk_hex, resize_func, output_shape=RanBlockSize)
    DomBlk_subsampled = get_dihedrical_transf(temp,fen_flip)
    
    return DomBlk_subsampled
Exemplo n.º 3
0
    def next_rangBlk(self):
        
        for i in xrange (int(self.w/8)):
            for j in xrange (int(self.h/8)):
                ranBlk = self.Dom[j*self.RanBlockSize[0]:j*self.RanBlockSize[0]+ self.RanBlockSize[0], i*self.RanBlockSize[1]:i*self.RanBlockSize[1]+self.RanBlockSize[1]]
                self.curr_ranBlk = rgb2hex(ranBlk.copy())
                
                for fit_calculator in self.fit_calculators:
                    self.work_queue.put("Next_ranBlk")

                self.start_fit_calc.set()
                
                ACKS = []
                while len(ACKS) < len(self.fit_calculators):
                    ACKS.append(self.result_queue.get())
                    
                self.start_fit_calc.clear()                    
                    
                yield self.curr_ranBlk
Exemplo n.º 4
0
def show_chrom(chrom, Dom, DomBlockSize ):

    RanBlockSize = (8,8)
     
    gen_x_dom = chrom[0:9]
    gen_y_dom = chrom[9:18]
    gen_flip  = chrom[18:21]

    # fenotypes
    fen_xdom  = int(gen_x_dom,2)  # 2 for binary representation
    fen_ydom  = int(gen_y_dom,2)  
    fen_flip  = int(gen_flip,2)

    DomBlk = Dom[fen_ydom:fen_ydom+DomBlockSize[0] ,fen_xdom:fen_xdom+DomBlockSize[1]]
    DomBlk_hex = rgb2hex(DomBlk.copy())

    temp = get_scaled.geometric_transform(DomBlk_hex, resize_func, output_shape=RanBlockSize)
    DomBlk_subsampled = get_dihedrical_transf(temp,fen_flip)
    
    DomBlk_subsampled = DomBlk_subsampled.copy()
    pilImage = Image.frombuffer('RGBA',DomBlk_subsampled.shape,DomBlk_subsampled,'raw','RGBA',0,1) #for rgba
    #pilImage = Image.frombuffer('RGBA',DomBlk_hex.shape,DomBlk_hex,'raw','RGBA',0,1) #for rgba

    imshow(pilImage.transpose(1))
Exemplo n.º 5
0
 def next_rangBlk(self):
     for i in xrange (int(self.w/8)):
         for j in xrange (int(self.h/8)):
             ranBlk = self.Dom[j*self.RanBlockSize[0]:j*self.RanBlockSize[0]+ self.RanBlockSize[0], i*self.RanBlockSize[1]:i*self.RanBlockSize[1]+self.RanBlockSize[1]]
             self.ranBlk = rgb2hex(ranBlk.copy())
             yield None