Beispiel #1
0
def plotPosteriorMax(mix, axis):
    """ 
    @param axis: matlab-like axis coordinates: [x_start, x_end, y_start, y_end] 
    
    """
    
    # -5, 10.0, -5.0, 10.0

    x = pylab.arange(axis[0],axis[1],0.1)
    y = pylab.arange(axis[2],axis[3],0.1)
    
    #print len(x)
    #print len(y)

    # XXX colors hard coded here XXX
    color =  ['b','r','g','m','c','y']  
    assert mix.G <= len(color)
    
    z = numpy.zeros( (len(y),len(x)),dtype='Float64' )
    for i in range(len(y)):
        dat = numpy.zeros((len(x),2),dtype='Float64' ) 
        dat[:,1] = y[i]
        dat[:,0] = x
        #print numpy.exp(mix.pdf(dat))


        #print "---------------------------\n",dat
        l = mixture.get_posterior(mix,dat)

        #print l

        # XXX pdf is log valued, we want the true value XXX
        
        #print numpy.exp(mix.pdf(dat)).tolist()
        for j in range(len(x)):
            
            z[i,j] = numpy.argmax(l[:,j])
            #print dat[j,:] ,":",l[:,j],numpy.argmax(l[:,j])
            
            
            #print dat[j,:] ,":",l[:,j], "=",z[i,j]
        #print "---------------------------\n"        
    
    #print "z", len(z),'x', len(z[0]) ,'=', len(z) * len(z[0])
    
    print "max",z.max()
    #max_val = z.max()
    
    max_val = numpy.log(mix.G) # maximum entropy for a vector of length mix.G
    print "theor. max", max_val
    
    step = max_val / 40.0
    print "step",step

    #pylab.figure(1)
    #pylab.contour(x,y,z)
    
    #pylab.figure(2)
    #pylab.contour(x,y,z,pylab.arange(0,max_val,step))
    #pylab.legend()  

    pylab.figure()
#    pylab.colorbar()
    

    pylab.contourf(x,y,z,cmap=pylab.cm.hsv) # pylab.arange(0,max_val,step)
    
    
    
    pylab.title('Posterior Maximum Plot')
Beispiel #2
0
def plotPosteriorMax(mix, axis):
    """ 
    @param axis: matlab-like axis coordinates: [x_start, x_end, y_start, y_end] 
    
    """
    
    # -5, 10.0, -5.0, 10.0

    x = pylab.arange(axis[0],axis[1],0.1)
    y = pylab.arange(axis[2],axis[3],0.1)
    
    #print len(x)
    #print len(y)

    # XXX colors hard coded here XXX
    color =  ['b','r','g','m','c','y']  
    assert mix.G <= len(color)
    
    z = numpy.zeros( (len(y),len(x)),dtype='Float64' )
    for i in range(len(y)):
        dat = numpy.zeros((len(x),2),dtype='Float64' ) 
        dat[:,1] = y[i]
        dat[:,0] = x
        #print numpy.exp(mix.pdf(dat))


        #print "---------------------------\n",dat
        l = mixture.get_posterior(mix,dat)

        #print l

        # XXX pdf is log valued, we want the true value XXX
        
        #print numpy.exp(mix.pdf(dat)).tolist()
        for j in range(len(x)):
            
            z[i,j] = numpy.argmax(l[:,j])
            #print dat[j,:] ,":",l[:,j],numpy.argmax(l[:,j])
            
            
            #print dat[j,:] ,":",l[:,j], "=",z[i,j]
        #print "---------------------------\n"        
    
    #print "z", len(z),'x', len(z[0]) ,'=', len(z) * len(z[0])
    
    print "max",z.max()
    #max_val = z.max()
    
    max_val = numpy.log(mix.G) # maximum entropy for a vector of length mix.G
    print "theor. max", max_val
    
    step = max_val / 40.0
    print "step",step

    #pylab.figure(1)
    #pylab.contour(x,y,z)
    
    #pylab.figure(2)
    #pylab.contour(x,y,z,pylab.arange(0,max_val,step))
    #pylab.legend()  

    pylab.figure()
#    pylab.colorbar()
    

    pylab.contourf(x,y,z,cmap=pylab.cm.hsv) # pylab.arange(0,max_val,step)
    
    
    
    pylab.title('Posterior Maximum Plot')
Beispiel #3
0
def plotMixtureEntropy(mix, axis):
    """ 
    @param axis: matlab-like axis coordinates: [x_start, x_end, y_start, y_end] 
    
    """
    
    # -5, 10.0, -5.0, 10.0

    x = pylab.arange(axis[0],axis[1]+0.1,0.1)
    y = pylab.arange(axis[2],axis[3]+0.1,0.1)
    
    #print x
    #print y
    
    #print len(x)
    #print len(y)
    
    
    #X,Y = pylab.meshgrid(x,y)
    #z = pylab.exp(-(X*X + Y*Y)) + 0.6*pylab.exp(-((X+1.8)**2 + Y**2))   
    #pylab.contour(x,y,z)

    z = numpy.zeros( (len(y),len(x)),dtype='Float64' )
    for i in range(len(y)):
        dat = numpy.zeros((len(x),2),dtype='Float64' ) 
        dat[:,1] = y[i]
        dat[:,0] = x
        #print numpy.exp(mix.pdf(dat))


        #print "---------------------------\n",dat
        data = mixture.DataSet()
        data.fromList(dat)
        data.internalInit(mix)
        
        l = mixture.get_posterior(mix,data,logreturn=False)

        #print l

        
        #print numpy.exp(mix.pdf(dat)).tolist()
        for j in range(len(x)):
            
            z[i,j] = mixture.entropy(l[:,j])
            #print dat[j,:] ,":",l[:,j], "=",z[i,j]
        #print "---------------------------\n"        
    
    #print "z", len(z),'x', len(z[0]) ,'=', len(z) * len(z[0])
    
    print "max",z.max()
    #max_val = z.max()
    
    max_val = numpy.log(mix.G) # maximum entropy for a vector of length mix.G
    print "theor. max", max_val
    
    step = max_val / 10.0
    print "step",step

    #pylab.figure(1)
    #pylab.contour(x,y,z)
    
    #pylab.figure(2)
    #pylab.contour(x,y,z,pylab.arange(0,max_val,step))
    #pylab.legend()  

#    pylab.colorbar()
    pylab.contourf(x,y,z,) # pylab.arange(0,max_val,step)
    
    
    
    pylab.title('Posterior Entropy Plot')
Beispiel #4
0
def plotMixtureEntropy(mix, axis):
    """ 
    @param axis: matlab-like axis coordinates: [x_start, x_end, y_start, y_end] 
    
    """
    
    # -5, 10.0, -5.0, 10.0

    x = pylab.arange(axis[0],axis[1]+0.1,0.1)
    y = pylab.arange(axis[2],axis[3]+0.1,0.1)
    
    #print x
    #print y
    
    #print len(x)
    #print len(y)
    
    
    #X,Y = pylab.meshgrid(x,y)
    #z = pylab.exp(-(X*X + Y*Y)) + 0.6*pylab.exp(-((X+1.8)**2 + Y**2))   
    #pylab.contour(x,y,z)

    z = numpy.zeros( (len(y),len(x)),dtype='Float64' )
    for i in range(len(y)):
        dat = numpy.zeros((len(x),2),dtype='Float64' ) 
        dat[:,1] = y[i]
        dat[:,0] = x
        #print numpy.exp(mix.pdf(dat))


        #print "---------------------------\n",dat
        data = mixture.DataSet()
        data.fromList(dat)
        data.internalInit(mix)
        
        l = mixture.get_posterior(mix,data,logreturn=False)

        #print l

        
        #print numpy.exp(mix.pdf(dat)).tolist()
        for j in range(len(x)):
            
            z[i,j] = mixture.entropy(l[:,j])
            #print dat[j,:] ,":",l[:,j], "=",z[i,j]
        #print "---------------------------\n"        
    
    #print "z", len(z),'x', len(z[0]) ,'=', len(z) * len(z[0])
    
    print "max",z.max()
    #max_val = z.max()
    
    max_val = numpy.log(mix.G) # maximum entropy for a vector of length mix.G
    print "theor. max", max_val
    
    step = max_val / 10.0
    print "step",step

    #pylab.figure(1)
    #pylab.contour(x,y,z)
    
    #pylab.figure(2)
    #pylab.contour(x,y,z,pylab.arange(0,max_val,step))
    #pylab.legend()  

#    pylab.colorbar()
    pylab.contourf(x,y,z,) # pylab.arange(0,max_val,step)
    
    
    
    pylab.title('Posterior Entropy Plot')