Пример #1
0
def gather_repeated_simulation_statistics(clab_fname, coordinate, cat):
    '''
    Gathers statistics from several repetitions of the same simulation.
    
    Returns:
    statistics - a dictionary: {chwila czasowa: {lewy: {stat1: , stat2: ...}, prawy: {}}, ...} lewy i prawy zamienione na 0/1
    mode_bigger - 
    files - ids of consecutive time stamps, used in statistics dictionary
    '''
    import os
    cats = map(lambda x: cat+"//"+x, os.listdir(cat))
    #assume that in each catalogue there are files named the same, which correspond to one another
    files = os.listdir(cats[0])

    #how many simulations chose bigger, how many chose smaller
    mode_bigger = {}
    statistics = {} # 
    #list statistics for each file, gathering info from all catalogues:
    for fname in sorted(files, key=lambda x: string2prefix_num(x)):
        mode_bigger[fname] = [0, 0]
        #all results_of_simulation for left and all results_of_simulation for right
        all_results_modes = []
        all_results_words = []
        for cat in cats:
            bigger_mode, smaller_mode, avg_wordnum1, avg_wordnum2 = \
            get_mode_word_stats(cat+"/"+fname, clab_fname, coordinate)
            
            if bigger_mode > smaller_mode:
                mode_bigger[fname][0] += 1
            elif bigger_mode < smaller_mode:
                mode_bigger[fname][1] += 1
            
            all_results_modes += [(bigger_mode, smaller_mode)] 
            all_results_words += [(avg_wordnum1, avg_wordnum2)]
        
        #=====calculate statistics for current fname=====#
        statistics[fname] = [{}, {}]
        for ind in [0, 1]:#index of half
            sub_stats = {}
            sub_stats = get_numpy_statistics( map(lambda x: x[ind],
                                                        all_results_modes), 
                                             STATISTICS_MEASURES )
            for key in sub_stats.iterkeys():
                statistics[fname][ind]['mode_'+key] = sub_stats[key]
            
            sub_stats = get_numpy_statistics( map(lambda x: x[ind],
                                                        all_results_words),
                                             STATISTICS_MEASURES )
            for key in sub_stats.iterkeys():
                statistics[fname][ind]['wordnum_'+key] = sub_stats[key]
    
    return statistics, mode_bigger, files
Пример #2
0
     exit(1)
 res_cat = sys.argv[3]#katalog z wynikami
 print "res_cat:", res_cat
 ensure_dir(res_cat)"""
 
 position2coordinates = load_position2coordinates(chip_fname)
 print "position2coordinates:", position2coordinates 
 min_x, max_x, min_y, max_y = get_borders_position2coordinates(position2coordinates)
 print "min_x:", min_x
 print "max_x:", max_x
 print "min_y:", min_y
 print "max_y:", max_y
 
 files = get_files(cat)
 matrices = {}
 for fname in sorted(files, key=lambda x: string2prefix_num(x)):
     ######################################################################
     #generate results for current fname
     word_moda = get_moda_dict(cat, fname)
     print "word_moda:", word_moda
     
     #mtx = [[0]*(max_y-min_y+1)]*(max_x-min_x+1) VERY WRONG!! CHECK WHY
     mtx = [[0 for _ in xrange(max_y-min_y+1)] for _ in xrange(max_x-min_x+1)]
     for key, moda in word_moda.iteritems():
         x, y = position2coordinates[key+1]
         mtx[x][y] = moda
     #print matrix(mtx)
     #matrices[string2prefix_num(fname)] = ...
     #scipy.misc.imsave(str(string2prefix_num(fname))+'.jpg', matrix(mtx))
     ax = plt.gca()
     ax.patch.set_alpha(0.0)
Пример #3
0
        exit(1)
    clab_fname = sys.argv[1]#plik z c-lab
    if len(sys.argv) < 3:
        print "Parameter 2: an integer corresponding to a coordinate by which colours are separated."
        exit(1)
    coordinate = int(sys.argv[2])#podzial wzgledem ktorej wspolrzednej
    if len(sys.argv) < 4:
        print "Parameter 3: catalogue, where results of a simulation are stored."
        exit(1)
    cat = sys.argv[3]#katalog z wynikami

    statistics, mode_bigger, files = gather_repeated_simulation_statistics(clab_fname, coordinate, cat)
    
    #=====print results=====#
    
    for fname in sorted(files, key=lambda x: string2prefix_num(x)):
        #=====print results for current fname=====#
        print str(string2prefix_num(fname))+":"

        #print header
        res_line = ["Bigger_wins", "Smaller_wins", "|"] + \
            map(lambda x: "mode_"+x, STATISTICS_MEASURES) + \
            ["|"] + \
            map(lambda x: "word_number_"+x, STATISTICS_MEASURES)
        print "\t".join([printable_elem(res) for res in res_line])
        
        for ind in [0, 1]:#index of half
            res_line = []
            res_line.append( mode_bigger[fname][0] )
            res_line.append( mode_bigger[fname][1] )
            res_line.append( "|" )
Пример #4
0
        print "Parameter 3: catalogue, where results of a simulation are stored."
        exit(1)
    cat = sys.argv[3]#katalog z wynikami
    if len(sys.argv) < 5:
        print "Parameter 4: measured statistic to plot, for example 'median'."
        exit(1)
    measured_statistic = sys.argv[4]

    statistics, mode_bigger, files = gather_repeated_simulation_statistics(clab_fname, coordinate, cat)

    x = []
    y1 = []
    y2 = []
    ydiff = []
    ydiffstd = []
    for fname in sorted(files, key=lambda x: string2prefix_num(x)):
        #=====print results for current fname=====#
        x.append(string2prefix_num(fname))
        for ind, y in enumerate([y1, y2]):
            y.append(statistics[fname][ind]['mode_'+measured_statistic])
        ydiffstd.append(statistics[fname][0]['mode_std']+statistics[fname][1]['mode_std'])
    
    for i in xrange(len(x)):
        ydiff.append(y1[i]-y2[i])
    
    #===================================================================
    #PLOT
    #===================================================================
    
    import numpy as np
    import matplotlib.pyplot as plt