Exemplo n.º 1
0
def plot_errors_classweights_C(classweights, fourclutest, fourclutrain, Clist):
    
    false_discovery_rate, true_positive_rate = supe.pre_plotROC(fourclutest)  
    false_discovery_train_rate, true_positive_train_rate = supe.pre_plotROC(fourclutrain)  
    
    weightzero = np.zeros(len(classweights))
    weightone = np.zeros(len(classweights))
    #Extract the weights
    for i in np.arange(len(classweights)):
        weightzero[i] = classweights[i][0]
        weightone[i] = classweights[i][1]
        
    
    fig = plt.figure()
    #axes1 = fig1.add_axes([0.1,0.1,0.8,0.8]) 
    axes1 = fig.add_subplot(221)
    axes1.set_xlabel('log(C*weight 0)')
    axes1.set_ylabel('log(C*weight 1)')
    axes1.set_title('Test set FDR')
    axes1.hold(True)
    axes2 = fig.add_subplot(222)
    axes2.set_xlabel('log(C*weight 0)')
    axes2.set_ylabel('log(C*weight 1)')
    axes2.set_title('Test set 1-TPR')
    axes2.hold(True)
    axes3 = fig.add_subplot(223)
    axes3.set_xlabel('log(C*weight 0)')
    axes3.set_ylabel('log(C*weight 1)')
    axes3.set_title('Training set FDR')
    axes3.hold(True)
    axes4 = fig.add_subplot(224)
    axes4.set_xlabel('log(C*weight 0)')
    axes4.set_ylabel('log(C*weight 1)')
    axes4.set_title('Training set 1-TPR')
    axes4.hold(True)
    
    numCvalues = len(Clist)
    #Number of values of C, 
    # fourclu should have shape (numCvalues, len(classweights), numspikes)
    cm = plt.cm.get_cmap('RdYlBu')
    sizeadjust = 100
    for c, cval in enumerate(Clist):
        sc1 = axes1.scatter(np.log(cval*weightzero[:]),np.log(cval*weightone[:]),marker = 's',s=sizeadjust, c=false_discovery_rate[c,:] , cmap=cm)
        sc1.set_clim(vmin=0,vmax=1)
        fig.colorbar(sc1, ax=axes1, shrink=0.9)
        sc2 = axes2.scatter(np.log(cval*weightzero[:]),np.log(cval*weightone[:]),marker = 's',s=sizeadjust, c=(1-true_positive_rate[c,:]) , cmap=cm)
        #plt.colorbar(sc2)
        sc2.set_clim(vmin=0,vmax=1)
        fig.colorbar(sc2, ax=axes2, shrink=0.9)
        sc3 = axes3.scatter(np.log(cval*weightzero[:]),np.log(cval*weightone[:]),marker = 's',s=sizeadjust, c=false_discovery_train_rate[c,:] , cmap=cm)
        #plt.colorbar(sc3)
        sc3.set_clim(vmin=0,vmax=1)
        fig.colorbar(sc3, ax=axes3, shrink=0.9)
        sc4 = axes4.scatter(np.log(cval*weightzero[:]),np.log(cval*weightone[:]), marker = 's',s=sizeadjust,c=(1-true_positive_train_rate[c,:]) , cmap=cm)
        sc4.set_clim(vmin=0,vmax=1)
        fig.colorbar(sc4, ax=axes4, shrink=0.9)
        #plt.colorbar(sc4)
    plt.show()
Exemplo n.º 2
0
def plot_errors_classweights_C(classweights, fourclu, Clist):
    
    false_discovery_rate, true_positive_rate = supe.pre_plotROC(fourclu)  
    #false_discovery_train_rate, true_positive_train_rate = supe.pre_plotROC(fourclutest)  
    
    weightzero = np.zeros(len(classweights))
    weightone = np.zeros(len(classweights))
    #Extract the weights
    for i in np.arange(len(classweights)):
        weightzero[i] = classweights[i][0]
        weightone[i] = classweights[i][1]
        
    
    fig1 = plt.figure()
    axes1 = fig1.add_axes([0.1,0.1,0.8,0.8]) 
    
    axes1.set_xlabel('log(C*weight 0)')
    axes1.set_ylabel('log(C*weight 1)')
    axes1.hold(True)
    
    numCvalues = len(Clist)
    #Number of values of C, 
    # fourclu should have shape (numCvalues, len(classweights), numspikes)
    cm = plt.cm.get_cmap('RdYlBu')
    for c, cval in enumerate(Clist):
        sc = axes1.scatter(np.log(cval*weightzero[:]),np.log(cval*weightone[:]), c=false_discovery_rate[c,:] , cmap=cm)
        plt.colorbar(sc)
    plt.show()
    return axes1
Exemplo n.º 3
0
def make_one_list(fourclulist):
    false_discovery_rate = []
    true_positive_rate = []
    for s, tclu in enumerate(fourclulist):
        fdr, tpr = supe.pre_plotROC(tclu)  
        for c in np.arange(fdr.shape[0]):
            false_discovery_rate.append(fdr)
            true_positive_rate.append(tpr)        
    return false_discovery_rate, true_positive_rate        
Exemplo n.º 4
0
def plotROCcomplete(graphpath,fourclu,KKconflistsquared):
    false_discovery_rate, true_positive_rate = supe.pre_plotROC(fourclu)          
    
    fig1 = plt.figure(1)
    axes1 = fig1.add_axes([0.1,0.1,0.8,0.8]) 
    #Area on page not axes
    #dreadful notation, but we are stuck with it!
    axes1.hold(True)
    colours = ['r', 'g', 'b']
    axes1.set_xlim([0,1])
    axes1.set_ylim([0,1])
    #plt.xlim([0,1]) 
    #plt.ylim([0,1])
    axes1.set_xlabel('False discovery rate')
    axes1.set_ylabel('True positive rate')
    fig1.suptitle(' %s  '%(graphpath), fontsize=14, fontweight='bold')
    #embed()
    for i in np.arange(fourclu.shape[0]):
        axes1.scatter(false_discovery_rate[i,:],true_positive_rate[i,:],marker = 'x', color = 'c')   
        ratepoints = zip(false_discovery_rate[i,:],true_positive_rate[i,:])
        hull = ConvexHull(ratepoints)
        #simplexlist = [simplex for simplex in hull.simplices]
        #print simplexlist
        for simplex in hull.simplices:
            for data in itertools.combinations(simplex.coords,2):
                data = np.array(data)
                print data
                print 'next!'
                axes1.plot(data[:,0],data[:,1],color = 'c')
            #print vertex_index
            #xes = ratepoints[vertex_index,0]
            #print xes
            #yes = ratepoints[vertex_index,1]
            #axes1.plot(ratepoints[vertex_index,0],ratepoints[vertex_index,1],'k-')
    #plt.show()
    #plt.savefig('%s_%g.pdf'%(graphpath,i))    
    errorlist = []
    for k in np.arange(len(KKconflistsquared)):
        errors = Error_rates_KK(KKconflistsquared[k])  
        false_discovery_rateKK = errors[4]
        true_positive_rateKK = errors[5]
        axes1.scatter(false_discovery_rateKK,true_positive_rateKK, color = colours[np.mod(k,len(colours))])
        #embed()
        errorlist.append(errors)
    
    fig1.savefig('%s'%(graphpath))      
    #plt.figure(2)
    plt.show()
    #fig2 = plt.figure(2)
    #axes2 = fig2.add_axes([0.1,0.1,0.8,0.8]) 
    
    #return ratepoints
    #return xes, yes, 
    return errorlist, hull, ratepoints, false_discovery_rate, true_positive_rate   
Exemplo n.º 5
0
def plotROCcomplete_simple(graphpath,fourclu,KKconflistsquared):
    false_discovery_rate, true_positive_rate = supe.pre_plotROC(fourclu)          
    
    fig1 = plt.figure(1)
    axes1 = fig1.add_axes([0.1,0.1,0.8,0.8]) 
    #Area on page not axes
    #dreadful notation, but we are stuck with it!
    axes1.hold(True)
    colours = ['r', 'g', 'b']
    axes1.set_xlim([0,1])
    axes1.set_ylim([0,1])
    #plt.xlim([0,1]) 
    #plt.ylim([0,1])
    axes1.set_xlabel('False discovery rate')
    axes1.set_ylabel('True positive rate')
    fig1.suptitle(' %s  '%(graphpath), fontsize=14, fontweight='bold')
    for i in np.arange(fourclu.shape[0]):
        axes1.scatter(false_discovery_rate[i,:],true_positive_rate[i,:],marker = 'x', color = 'c')   
        
        #Simple plot - No convex hull 
    
    for k in np.arange(len(KKconflistsquared)):
        errors = Error_rates_KK(KKconflistsquared[k])  
        false_discovery_rateKK = errors[4]
        true_positive_rateKK = errors[5]
        axes1.scatter(false_discovery_rateKK,true_positive_rateKK, color = colours[np.mod(k,len(colours))])
    
    plt.show()
    fig1.savefig('%s'%(graphpath))      
    #plt.figure(2)
    
    #fig2 = plt.figure(2)
    #axes2 = fig2.add_axes([0.1,0.1,0.8,0.8]) 
    
    #return ratepoints
    #return xes, yes, 
    return  false_discovery_rate, true_positive_rate