Exemple #1
0
def evaluate_pic(genome, debug=False, save=None):
    verbose = True
    net = NEAT.NeuralNetwork()
    genome.BuildPhenotype(net)

    if verbose:
        print 'dcalc'

    genome.CalculateDepth()
    if verbose:
        print 'dcalc complete'

    depth = genome.GetDepth()
    error = 0

    # do stuff and return the fitness
    tot_vox = sz_x * sz_y * sz_z
    voxels = numpy.zeros((tot_vox, 4))

    print "calling batch...", genome.NumNeurons()
    voxels = net.Batch_input(coordinates, depth)
    print "complete"

    voxels = voxels.reshape((sz_x, sz_y, 4))
    voxels = voxels[:, :, :3]
    imgs = [voxels]

    if verbose:
        print 'running image rec'

    results, behavior = run_image(imgs)
    print "behavior shape: ", behavior.shape
    #print results.shape
    #print niche_matrix.T.shape
    results = np.dot(results, niche_matrix.T)
    full_matrix = results.copy()

    if debug:
        return imgs, results

    results = results[0, :]  #results.prod(axis=0)

    print results.shape

    #return float(results[target_class]),results,full_matrix
    return behavior, results, full_matrix
Exemple #2
0
def evaluate_pic(genome,debug=False,save=None):
    verbose=True
    net = NEAT.NeuralNetwork()
    genome.BuildPhenotype(net)

    if verbose:
     print 'dcalc'

    genome.CalculateDepth()
    if verbose:
     print 'dcalc complete'

    depth = genome.GetDepth()
    error = 0

    # do stuff and return the fitness
    tot_vox = sz_x*sz_y*sz_z
    voxels = numpy.zeros((tot_vox,4))

    print "calling batch...", genome.NumNeurons()
    voxels = net.Batch_input(coordinates,depth)
    print "complete"

    voxels = voxels.reshape((sz_x,sz_y,4))
    voxels = voxels[:,:,:3] 
    imgs = [voxels] 
    
    if verbose:
     print 'running image rec'

    results,behavior = run_image(imgs)  
    print "behavior shape: ", behavior.shape
    #print results.shape
    #print niche_matrix.T.shape
    results=np.dot(results,niche_matrix.T)
    full_matrix = results.copy()

    if debug:
     return imgs,results

    results = results[0,:] #results.prod(axis=0)
    
    print results.shape

    #return float(results[target_class]),results,full_matrix
    return behavior,results,full_matrix
Exemple #3
0
def evaluate(genome, debug=False, save=None, dnn=True):
    global lighting
    verbose = True

    if verbose:
        print 'building...'

    net = NEAT.NeuralNetwork()
    genome.BuildPhenotype(net)

    if verbose:
        print 'dcalc'

    genome.CalculateDepth()
    if verbose:
        print 'dcalc complete'
    depth = genome.GetDepth()

    #fixed depth for now...
    #depth=6

    error = 0
    # do stuff and return the fitness
    tot_vox = sz_x * sz_y * sz_z
    voxels = numpy.zeros((tot_vox, 4))

    print "calling batch...", genome.NumNeurons()
    voxels = net.Batch_input(coordinates, depth)
    print "complete"

    voxels = voxels.reshape((sz_x, sz_y, sz_z, 4))

    percentile = np.clip(net.neurons[5].bias, 0, 1)

    thresh = 0.5
    #thresh=np.percentile(voxels[:,:,:,0],100.0*percentile)

    voxels[0, :, :, 0] = thresh - 0.01
    voxels[-1, :, :, 0] = thresh - 0.01

    voxels[:, 0, :, 0] = thresh - 0.01
    voxels[:, -1, :, 0] = thresh - 0.01

    voxels[:, :, 0, 0] = thresh - 0.01
    voxels[:, :, -1, 0] = thresh - 0.01

    bg_color = [net.neurons[k].time_const for k in range(3)]

    if fixed_bg:
        #bg_color=[0.6,0.6,0.6]
        bg_color = [0.4078, 0.4575, 0.4811]

    oparam = np.clip([net.neurons[k].bias for k in range(4)], 0, 1)

    print bg_color
    print oparam

    if verbose:
        print 'rendering images'

    theta = 45
    jitter = 5

    shiny = oparam[0] * 128
    spec = oparam[1]
    amb = oparam[2]
    diff = oparam[3]

    img1 = render(voxels,
                  bg_color,
                  0,
                  0,
                  save=save,
                  shiny=shiny,
                  spec=spec,
                  amb=amb,
                  lighting=lighting,
                  diff=diff)
    img2 = render(voxels,
                  bg_color,
                  theta,
                  jitter,
                  shiny=shiny,
                  spec=spec,
                  amb=amb,
                  lighting=lighting,
                  diff=diff)
    img3 = render(voxels,
                  bg_color,
                  theta * 2,
                  0,
                  shiny=shiny,
                  spec=spec,
                  amb=amb,
                  lighting=lighting,
                  diff=diff)
    img4 = render(voxels,
                  bg_color,
                  theta * 3,
                  jitter,
                  shiny=shiny,
                  spec=spec,
                  amb=amb,
                  lighting=lighting,
                  diff=diff)
    img5 = render(voxels,
                  bg_color,
                  theta * 4,
                  0,
                  shiny=shiny,
                  spec=spec,
                  amb=amb,
                  lighting=lighting,
                  diff=diff)
    img6 = render(voxels,
                  bg_color,
                  theta * 5,
                  jitter,
                  spec=spec,
                  amb=amb,
                  lighting=lighting,
                  diff=diff)

    imgs = [img1, img2, img3, img4, img5, img6]

    if verbose:
        print 'running image rec'
    results, beh = None, None
    full_matrix = None

    if dnn:
        print "dnn"
        results, beh = run_image(imgs)
        #print niche_matrix.T.shape
        results = np.dot(results, niche_matrix.T)
        full_matrix = results.copy()
    else:
        print "no dnn"
    if debug:
        return imgs, results

    results = results.prod(axis=0)

    print results.shape

    return beh, results, full_matrix
Exemple #4
0
def evaluate(genome,debug=False,save=None,dnn=True):
    global lighting
    verbose=True

    if verbose:
     print 'building...'

    net = NEAT.NeuralNetwork()
    genome.BuildPhenotype(net)

    if verbose:
     print 'dcalc'

    genome.CalculateDepth()
    if verbose:
     print 'dcalc complete'
    depth = genome.GetDepth()

    #fixed depth for now...
    #depth=6

    error = 0
    # do stuff and return the fitness
    tot_vox = sz_x*sz_y*sz_z
    voxels = numpy.zeros((tot_vox,4))

    print "calling batch...", genome.NumNeurons()
    voxels = net.Batch_input(coordinates,depth)
    print "complete"

    voxels = voxels.reshape((sz_x,sz_y,sz_z,4))

    percentile = np.clip(net.neurons[5].bias,0,1)

    thresh=0.5
    #thresh=np.percentile(voxels[:,:,:,0],100.0*percentile)

    voxels[0,:,:,0]=thresh-0.01
    voxels[-1,:,:,0]=thresh-0.01

    voxels[:,0,:,0]=thresh-0.01
    voxels[:,-1,:,0]=thresh-0.01

    voxels[:,:,0,0]=thresh-0.01
    voxels[:,:,-1,0]=thresh-0.01

    bg_color = [net.neurons[k].time_const for k in range(3)]

    if fixed_bg:
      #bg_color=[0.6,0.6,0.6]
      bg_color=[0.4078,0.4575,0.4811]

    oparam = np.clip([net.neurons[k].bias for k in range(4)],0,1)

    print bg_color 
    print oparam

    if verbose:
     print 'rendering images'

    theta=45
    jitter=5

    shiny = oparam[0]*128
    spec = oparam[1]
    amb = oparam[2]
    diff = oparam[3]

    img1 = render(voxels,bg_color,0,0,save=save,shiny=shiny,spec=spec,amb=amb,lighting=lighting,diff=diff) 
    img2 = render(voxels,bg_color,theta,jitter,shiny=shiny,spec=spec,amb=amb,lighting=lighting,diff=diff) 
    img3 = render(voxels,bg_color,theta*2,0,shiny=shiny,spec=spec,amb=amb,lighting=lighting,diff=diff) 
    img4 = render(voxels,bg_color,theta*3,jitter,shiny=shiny,spec=spec,amb=amb,lighting=lighting,diff=diff) 
    img5 = render(voxels,bg_color,theta*4,0,shiny=shiny,spec=spec,amb=amb,lighting=lighting,diff=diff)
    img6 = render(voxels,bg_color,theta*5,jitter,spec=spec,amb=amb,lighting=lighting,diff=diff)

    imgs = [img1,img2,img3,img4,img5,img6]

    if verbose:
     print 'running image rec'
    results,beh = None,None
    full_matrix=None

    if dnn:
     print "dnn"
     results,beh = run_image(imgs)  
     #print niche_matrix.T.shape
     results=np.dot(results,niche_matrix.T)
     full_matrix = results.copy()
    else:
     print "no dnn"
    if debug:
     return imgs,results

    results = results.prod(axis=0)
    
    print results.shape

    return beh,results,full_matrix