Example #1
0
def findBestPictureWithMethod():
    from analysis import getPrCurve
    from tools import saveData
    d = getPrCurve(allMethods, 1000)
    #d[3]['img']['0.jpg']['MEAN'].keys()
    d = d[3]['img']
    aucs = {
        name: {method: d[name][method]['auc']
               for method in d[name]}
        for name in d
    }
    # auc = d['13.jpg']['RC']['auc']
    saveData(aucs, 'aucs')

    def sortGood(myMethod='ME1', compare='DISC2'):
        l = [(name, aucs[name][myMethod] - aucs[name][compare])
             for name in aucs]
        l.sort(key=lambda x: x[1])
        return l


#    [showpr(i) for i,j in l]

    def sortAucByMethod(method='ME1'):
        l = [(name, aucs[name][method]) for name in aucs]
        l.sort(key=lambda x: x[1])
        return l

    return sortGood()
Example #2
0
def plotPrCurve(precisions, recalls, labels=None, avgPreScore=-1, save=None):
    '''
    recalls, precision: list of PR curves
    labels: each line's name
    save: if is string of path, save plot img and data to path
    '''
    n = len(recalls) if isinstance(recalls, list) else 1
    if labels == None:
        labels = range(n) if n != 1 else 'line'
    if n == 1 and not isinstance(recalls, list):
        precisions = [precisions]
        recalls = [recalls]
        labels = [labels]

    plt.clf()
    color = ['r', 'b', 'k', 'g', 'c', 'y', 'm']
    lineStyle = '-', '--', ':', '-.'
    colors = []
    for i in lineStyle:
        colors += map(lambda x: x + i, color)

    for recall, precision, label, i in zip(recalls, precisions, labels,
                                           range(len(recalls))):
        plt.plot(recall, precision, colors[i % len(colors)], lw=1, label=label)
    plt.xlabel('Recall')
    plt.ylabel('Precision')

    #    plt.axis('equal')
    plt.axis([0., 1., 0., 1.])
    plt.title('Avg of {0:d} line\'s AUC={1:0.2f}'.format(n, avgPreScore))
    plt.legend(bbox_to_anchor=(0., 0, .8, 1.1),
               loc=3,
               ncol=3,
               mode="expand",
               borderaxespad=0.)
    plt.grid()
    if save != None:
        if not isinstance(save, str) and not isinstance(save, unicode):
            save = 'lastResoult'
        name = save
        data = recalls, precisions, labels, avgPreScore

        plt.savefig('./figs/' + name + '.png', dpi=300)
        dirr = './figs/' + name + '/'
        if not os.path.isdir(dirr):
            os.mkdir(dirr)

        plt.savefig(dirr + name + '.svg')
        saveData(data, dirr + name + '.pickle')
    plt.show()
Example #3
0
def findBestPictureWithMethod():
    d = getPrCurve(allMethods, 10)
    #d[3]['img']['0.jpg']['MEAN'].keys()
    d = d[3]['img']
    aucs = {
        name: {method: d[name][method]['auc']
               for method in d[name]}
        for name in d
    }
    saveData(aucs, 'aucs')

    def sortAucByMethod(method='ME2'):
        l = [(name, aucs[name][method]) for name in aucs]
        l.sort(key=lambda x: x[1])
        return l
Example #4
0
def saveImgData(imgName, methods):
    '''
    save data to LABEL_DATA_DIR
    return default method`s AUC
    '''
    if isinstance(imgName, int):
        imgName = IMG_NAME_LIST[imgName]
    imgGt = io.imread(IMG_DIR + imgName[:-3] + 'png') / 255.
    coarseDic = getCoarseDic(imgName, methods, COARSE_DIR)
    data = {}
    data['name'] = imgName

    data['method'] = {}
    for method, refindImg in coarseDic.items():
        data['method'][method] = getAucAndPr(imgGt, refindImg, method)

    dataName = LABEL_DATA_DIR + imgName[:-3] + 'data'
    AUC_METHOD = "DRFI"
    data['aucMethod'] = AUC_METHOD

    data['auc'] = data['method'][AUC_METHOD][0]
    saveData(data, dataName)
    return data['auc']
                    print("Saving data...")
                    # Save spikes
                    # tools.saveData(Simulation_params["experiment_id"],filename,".spikes",all_spikes)

                    # Save connection matrix
                    # tools.saveData(Simulation_params["experiment_id"],filename,".connections",connection_matrix)

                    # Save membrane potentials
                    # if Simulation_params["computeMP"]:
                    #     tools.saveData(Simulation_params["experiment_id"],filename,".MP_exc",potentials[0])
                    #     tools.saveData(Simulation_params["experiment_id"],filename,".MP_inh",potentials[1])

                    # Save AMPA and GABA currents
                    if Simulation_params["decimate"]:
                        tools.saveData(Simulation_params["experiment_id"],
                                       filename, ".AMPA",
                                       tools.decimate(AMPA_current, 10))

                        tools.saveData(Simulation_params["experiment_id"],
                                       filename, ".GABA",
                                       tools.decimate(GABA_current, 10))
                    else:
                        tools.saveData(Simulation_params["experiment_id"],
                                       filename, ".AMPA", AMPA_current)

                        tools.saveData(Simulation_params["experiment_id"],
                                       filename, ".GABA", GABA_current)

                    # # Normalize LFPs
                    # # Discard first 500 ms for comp. mean and s. deviation
                    # start_time_pos = int(500.0/Simulation_params["simstep"])
Example #6
0
                        if st_con['source'] in pop_ex:
                            connection_matrix[ind].append(
                                pop_ex.index(st_con['source']))
                        if st_con['source'] in pop_in:
                            connection_matrix[ind].append(pop_in.index(st_con['source'])+\
                            len(pop_ex))

                # Add connections from external inputs
                for j in range(len(pop_parrot_th)):
                    connection_matrix[j].append(j + len(pop_ex) + len(pop_in))
                    connection_matrix[j].append(j + len(pop_ex) + len(pop_in) +
                                                len(pop_parrot_th))

        print("Saving data...")
        # Save spikes
        tools.saveData(Simulation_params["experiment_id"], filename, ".spikes",
                       all_spikes)

        # Save connection matrix
        tools.saveData(Simulation_params["experiment_id"], filename,
                       ".connections", connection_matrix)

        # Save membrane potentials
        if Simulation_params["computeMP"]:
            tools.saveData(Simulation_params["experiment_id"], filename,
                           ".MP_exc", potentials[0])
            tools.saveData(Simulation_params["experiment_id"], filename,
                           ".MP_inh", potentials[1])

        # Save AMPA and GABA currents
        if Simulation_params["decimate"]:
            tools.saveData(Simulation_params["experiment_id"], filename,
Example #7
0
       len(cluster_2_rate_1[0]) / 100000))
print("Rate 2 sp/s: %s, %s, %s" %
      (len(cluster_0_rate_2[0]) / 100000, len(cluster_1_rate_2[0]) / 100000,
       len(cluster_2_rate_2[0]) / 100000))
print("mean(g) = %s,%s,%s" %
      (np.mean(g_cluster_0), np.mean(g_cluster_1), np.mean(g_cluster_2)))

#######################################################################
# Save data
# os.mkdir('../results/merged_files')

# A) 1.5 sp/s
filename = 'trial_' + str(0) + '_rate_' + str(1.5) + '_gex_' + str(
    1.78289473684) + '_gin_' + str(1.0)
# AMPA and GABA
tools.saveData("merged_files", filename, ".AMPA", cluster_0_rate_1[0])
tools.saveData("merged_files", filename, ".GABA", cluster_0_rate_1[1])
# Save time array
tools.saveData("merged_files", filename, ".times", t_sim)
# Save time step
tools.saveData("merged_files", filename, ".dt", simstep)

filename = 'trial_' + str(0) + '_rate_' + str(1.5) + '_gex_' + str(
    1.20394736842) + '_gin_' + str(1.0)
# AMPA and GABA
tools.saveData("merged_files", filename, ".AMPA", cluster_1_rate_1[0])
tools.saveData("merged_files", filename, ".GABA", cluster_1_rate_1[1])
# Save time array
tools.saveData("merged_files", filename, ".times", t_sim)
# Save time step
tools.saveData("merged_files", filename, ".dt", simstep)
Example #8
0
    kurtosis = computeKurtosisCustom(vel)
    a2 = computeExcessKurtosis_a2(kurtosis, 2)
    if verbose_temperature == True:
        print('Temperature: '+'{:.3f}'.format(meanTemperature))
        #print('{:.3f}'.format(a2))
    # Saving temperature and a2 data
    file_t.write('{0:10.6f} {1:10.4f}\n'.format(abs_time, meanTemperature))
    file_a2.write('{0:10.6f} {1:10.4f}\n'.format(abs_time, a2))
    
    
    if verbose_absTime == True:
        print('Contador de tiempo absoluto: ', str(abs_time))


    # We save positions and velocities data after current collision
    saveData(c, data_folder, n_particles, pos, vel)
    p = "{:.2f}".format(100*(c/n_collisions)) + " %" # Percent completed
    if verbose_percent == True:
        print(p)
    if verbose_saveData == True:
        print('Saving file, collision nº: '+str(c+1)+' / '+str(n_collisions))
      
        
        
        
    if verbose_debug == True:
        print(' ')
        print('COLLISION Nº: '+str(c))
        print('Event list head:')
        print(events.eventTimesList.iloc[0:1])
        if dt==0:
Example #9
0
 def saveKs(self, npz_filename):
     saveData(npz_filename, tuneX=self.tuneX, tuneY=self.tuneY, k0=self.k0, k1=self.k1, b1=self.b1)
Example #10
0
 def saveCubes(self, npz_cubefile):
     saveData(npz_cubefile, **self.cubes)