예제 #1
0
    def load_dic(self, *filt, **kw):
        d = {}
        if kw.get('keys_iterator'):
            for keys in kw['keys_iterator']:
                print keys
                storage = misc.dict_recursive_get(self, keys)
                val = storage.load_data()
                d = misc.dict_recursive_add(d, keys, val)
            return d

        for keys, storage in misc.dict_iter(self):
            if filt == ():
                pass
            else:
                a = False
                i = 0
                for key in keys:
                    if key not in filt and i not in kw.get('star', []):
                        a = True
                    i += 1

                    if key == 'mean_rates':
                        pass
                    if i == len(keys):
                        break

                if a:
                    continue

            val = storage.load_data()
            d = misc.dict_recursive_add(d, keys, val)

        return d
예제 #2
0
 def load_dic(self, *filt, **kw):
     d={}  
     if kw.get('keys_iterator'):
         for keys in kw['keys_iterator']:
             print keys
             storage=misc.dict_recursive_get(self, keys)
             val=storage.load_data()
             d=misc.dict_recursive_add(d, keys, val)
         return d
   
     for keys, storage in misc.dict_iter(self):
         if filt==():
             pass
         else:
             a=False
             i=0
             for key in keys:
                 if key not in filt and i not in kw.get('star', []):
                     a=True
                 i+=1
                 
                 if key=='mean_rates':
                     pass
                 if i==len(keys):
                     break
                 
             if a:
                 continue
                    
         val=storage.load_data()
         d=misc.dict_recursive_add(d, keys, val)
             
     return d
예제 #3
0
def set_optimization_val(data, nets):
    for key in sorted(nets.keys()):
        net = nets[key]
        inp = net.get_single_unit_input()
        x = 'node.' + inp + '.rate'  #kwargs.get('x', ['node.CFp.rate'])
        dic = misc.dict_recursive_add({}, x.split('.'), data.xopt[-1][0])
        net.update_dic_rep(dic)
예제 #4
0
def cmp_mean_rate_diff(d, models, parings, x, _set='set_0'):
    
    for model in models:
        y=[]
        y_std=[]
        for net0, net1 in parings:
            d0=d[net0][_set]
            d1=d[net1][_set]
   
            v0=d0[model]['mean_rate_slices']
            v1=d1[model]['mean_rate_slices']
            
            y.append(numpy.mean(numpy.abs(v0.y_raw_data-v1.y_raw_data)))
            y_std.append(numpy.std(numpy.abs(v0.y_raw_data-v1.y_raw_data)))
        
        dd={'y':numpy.array(y),
            'y_std':numpy.array(y_std),
            'x':numpy.array(x)}
        
        obj=Data_generic(**dd)
        
        d=misc.dict_recursive_add(d, ['Difference',
                                  model,
                                 'mean_rate_diff'], obj)
    pp(d)
    return d    
예제 #5
0
def generate_plot_data(d,
                       models,
                       attrs,
                       exclude=['all', 'striatum', 'GP-ST-SN', 'Normal']):
    out = {}

    labels = []
    keys = d.keys()
    for k in sorted(keys):
        if k in exclude:
            continue
        labels.append(k)

    for model in models:
        l = []
        for attr in attrs:
            l.append([])
            for k in sorted(keys):
                if k in exclude:
                    continue
                l[-1].append(misc.dict_recursive_get(d, [k, model, attr]))

        lsum = [[a] * len(l[0]) for a in numpy.sum(l, axis=1)]
        obj = Data_bar(**{
            'y': numpy.array(l)  #/numpy.array(lsum)
        })
        out = misc.dict_recursive_add(out, [model], obj)

    return out, labels
예제 #6
0
def generate_plot_data(d, models, attrs, exclude=['all',
                                                  'striatum',
                                                  'GP-ST-SN', 
                                                  'Normal']):
    out={}
    
    labels=[]
    keys=d.keys()
    for k in sorted(keys):
        if k in exclude:
            continue
        labels.append(k)
    
    for model in models:
        l=[]
        for attr in attrs:
            l.append([])
            for k in sorted(keys):
                if k in exclude:
                    continue
                l[-1].append(misc.dict_recursive_get(d, [k, model, attr]))
            
        lsum=[[a]*len(l[0]) for a in numpy.sum(l, axis=1)]
        obj=Data_bar(**{'y':numpy.array(l)#/numpy.array(lsum)
                        })
        out=misc.dict_recursive_add(out, [model], obj)
    
    return out, labels
예제 #7
0
def show_plot(axs,
              name,
              d,
              models=['M1', 'M2', 'FS', 'GA', 'GI', 'ST', 'SN'],
              **k):
    dd = {}
    by_sets = k.pop('by_sets', False)

    for keys, val in misc.dict_iter(d):

        if keys[-1] != name:
            continue
        if by_sets and keys[0][0:3] != 'set':
            continue

        first_keys = keys[:-2]
        if type(first_keys) == str:
            first_keys = [first_keys]

        new_keys = ['_'.join(first_keys)] + keys[-2:]

        dd = misc.dict_recursive_add(dd, new_keys, val)

    d = dd

    #     if k.get('fig_and_axes', False):

    #     else:
    #         fig, axs=ps.get_figure(n_rows=len(models), n_cols=1, w=1000.0, h=800.0,
    #                            fontsize=k.get('fontsize',10))
    labels = k.pop('labels', sorted(d.keys()))
    #     colors=misc.make_N_colors('Paired', max(len(labels), 6))
    colors = k.pop('colors', misc.make_N_colors('jet', max(len(labels), 1)))
    linestyles = ['-'] * len(labels)

    j = 0
    nets = k.get('nets', sorted(d.keys()))
    for key in nets:
        v = d[key]
        #         axs[0].set_title(k)
        for i, model in enumerate(models):
            kk = {
                'label': model + ' ' + labels[j],
                'linestyle': linestyles[j],
                'color': colors[j]
            }
            if 'win' in k.keys():
                kk['win'] = k['win']
            if 't_start' in k.keys():
                kk['t_start'] = k['t_start']
            if 't_stop' in k.keys():
                kk['t_stop'] = k['t_stop']

            print model
            if model in v.keys():
                v[model][name].plot(ax=axs[i], **kk)
        j += 1

    for ax in axs:
        ax.legend()
예제 #8
0
def process_exp(exp, tr):
    out = {}

    put_at = {'STN': 3, 'TA': 0, 'TI': 1, 'all': 2}
    for keys, val in misc.dict_iter(exp):
        if keys[-1] == 'CV':
            continue
        keys2 = [tr[keys[1]], tr[keys[2]], 'mean_rates']

        if not misc.dict_haskey(out, keys2):
            a = numpy.zeros(4)
            a[put_at[keys[0]]] = val
            misc.dict_recursive_add(out, keys2, a)
        else:
            out[tr[keys[1]]][tr[keys[2]]]['mean_rates'][put_at[keys[0]]] = val

    pp(out)
    return out
예제 #9
0
def extract_data(d, nets, models, attrs):
    
    out={}
    for keys, val in misc.dict_iter(d):
        
        if keys[-1]=='phases_diff_with_cohere':
            v=numpy.mean(val.y_val, axis=0)
        if keys[-1]=='mean_coherence':
            v=val.y[2:20]
            
        out=misc.dict_recursive_add(out,  keys, v)
    return out             
예제 #10
0
def process_exp(exp, tr):
    out={}
    
    put_at={'STN':3,
            'TA':0,
            'TI':1,
            'all':2}
    for keys, val in misc.dict_iter(exp):
        if keys[-1]=='CV':
            continue
        keys2=[tr[keys[1]],tr[keys[2]], 'mean_rates']
        
        if not misc.dict_haskey(out, keys2):
            a=numpy.zeros(4)
            a[put_at[keys[0]]]=val
            misc.dict_recursive_add(out, keys2,a )
        else:
            out[tr[keys[1]]] [tr[keys[2]]] ['mean_rates'][put_at[keys[0]]]=val

    pp(out)
    return out
예제 #11
0
def extract_data(d, nets, models, attrs):

    out = {}
    for keys, val in misc.dict_iter(d):

        if keys[-1] == 'phases_diff_with_cohere':
            v = numpy.mean(val.y_val, axis=0)
        if keys[-1] == 'mean_coherence':
            v = val.y[2:20]

        out = misc.dict_recursive_add(out, keys, v)
    return out
예제 #12
0
def compute_performance(d, nets, models, attrs):       
    results={}
 
                
    for run in d.keys():
        for model in models:
            for attr in attrs:
                keys1=[run, 'Net_0', model, attr]
                keys2=[run, 'Net_1', model, attr]
                keys3=[run, model, attr]

                v1=misc.dict_recursive_get(d, keys1)
                v2=misc.dict_recursive_get(d, keys2)

                v=(v1-v2)/v1
                v[numpy.isnan(v)]=0
                v=numpy.mean((v)**2)
                
                results=misc.dict_recursive_add(results,  keys3, v)
    d0={}
    for run in results.keys():
        for model in models:
            for attr in attrs:
                keys0=['Normal', model, attr] 
                v1=misc.dict_recursive_get(results, keys0)
                d0=misc.dict_recursive_add(d0, keys0, v1)

       
    for run in results.keys():
        for model in models:
            for attr in attrs:
                keys0=['Normal', model, attr]  
                keys3=[run, model, attr]               
                
                v0=misc.dict_recursive_get(d0, keys0)
                v1=misc.dict_recursive_get(results, keys3)
                results=misc.dict_recursive_add(results, keys3, v1/v0)
                
    return results
예제 #13
0
def compute_performance(d, nets, models, attrs):
    results = {}

    for run in d.keys():
        for model in models:
            for attr in attrs:
                keys1 = [run, 'Net_0', model, attr]
                keys2 = [run, 'Net_1', model, attr]
                keys3 = [run, model, attr]

                v1 = misc.dict_recursive_get(d, keys1)
                v2 = misc.dict_recursive_get(d, keys2)

                v = (v1 - v2) / v1
                v[numpy.isnan(v)] = 0
                v = numpy.mean((v)**2)

                results = misc.dict_recursive_add(results, keys3, v)
    d0 = {}
    for run in results.keys():
        for model in models:
            for attr in attrs:
                keys0 = ['Normal', model, attr]
                v1 = misc.dict_recursive_get(results, keys0)
                d0 = misc.dict_recursive_add(d0, keys0, v1)

    for run in results.keys():
        for model in models:
            for attr in attrs:
                keys0 = ['Normal', model, attr]
                keys3 = [run, model, attr]

                v0 = misc.dict_recursive_get(d0, keys0)
                v1 = misc.dict_recursive_get(results, keys3)
                results = misc.dict_recursive_add(results, keys3, v1 / v0)

    return results
예제 #14
0
def postprocess(d):
    out = {}
    ylabels0 = sorted(d.keys())

    xlabels = sorted(d[ylabels0[0]]['Net_0'].keys())
    i, j = 0, 0
    for tp in ['beta', 'sw']:
        ylabels = []
        for key in ylabels0:
            if key[0] != tp[0] or len(d[key].keys()) < 2:
                continue
            ylabels.append(key)
            j += 1
            #             if j==396:
            #                 pass

            for net in d[key].keys():
                mrs = []
                for model in xlabels:
                    obj = d[key][net][model]['spike_statistic']
                    mrs.append(obj.rates['mean'])

                keys = [tp, net, 'mean_rates']
                if not misc.dict_haskey(out, keys):
                    misc.dict_recursive_add(out, keys, [mrs])
                    if net == 'Net_0': i += 1
                else:
                    out[tp][net]['mean_rates'].append(mrs)
                    if net == 'Net_0': i += 1
            if not i == j:
                print d[key].keys(), i, j
                raise


#             print j,i
        for net in d[key].keys():
            keys = [tp, net, 'xlabels']
            misc.dict_recursive_add(out, keys, xlabels)
            keys = [tp, net, 'ylabels']
            misc.dict_recursive_add(out, keys, ylabels)

    pp(out)
    for tp in out.keys():
        for net in out[tp].keys():
            out[tp][net]['mean_rates'] = numpy.array(
                out[tp][net]['mean_rates'])

    return out
예제 #15
0
 def load_dic(self, *filt):
           
     d={}
     for keys, storage in misc.dict_iter(self):
         if filt==():
             pass
         else:
             a=False
             i=0
             for key in keys:
                 if key not in filt:
                     a=True
                 i+=1
                 if i==3:
                     break
             if a:
                 continue
                    
         val=storage.load_data()
         d=misc.dict_recursive_add(d, keys, val)
             
     return d
예제 #16
0
    def load_dic(self, *filt):

        d = {}
        for keys, storage in misc.dict_iter(self):
            if filt == ():
                pass
            else:
                a = False
                i = 0
                for key in keys:
                    if key not in filt:
                        a = True
                    i += 1
                    if i == 3:
                        break
                if a:
                    continue

            val = storage.load_data()
            d = misc.dict_recursive_add(d, keys, val)

        return d
예제 #17
0
def postprocess(d):
    out={}
    ylabels0=sorted(d.keys())

    xlabels=sorted(d[ylabels0[0]]['Net_0'].keys())
    i,j=0,0
    for tp in ['beta','sw']:
        ylabels=[]
        for key in ylabels0:
            if key[0]!=tp[0] or len(d[key].keys())<2:
                continue
            ylabels.append(key)
            j+=1
#             if j==396:
#                 pass
            
            for net in d[key].keys():
                mrs=[]
                for model in xlabels:
                    obj=d[key][net][model]['spike_statistic']
                    mrs.append(obj.rates['mean'])
                
                keys=[tp, net, 'mean_rates']    
                if not misc.dict_haskey(out, keys):
                    misc.dict_recursive_add(out, keys, [mrs])
                    if net=='Net_0': i+=1
                else:
                    out[tp][net]['mean_rates'].append(mrs)
                    if net=='Net_0':i+=1
            if not i==j:
                print d[key].keys(), i,j
                raise
#             print j,i
        for net in d[key].keys(): 
            keys=[tp, net, 'xlabels']    
            misc.dict_recursive_add(out, keys, xlabels)
            keys=[tp, net, 'ylabels']  
            misc.dict_recursive_add(out, keys, ylabels)
        
    pp(out)
    for tp in out.keys():
        for net in out[tp].keys():
            out[tp][net]['mean_rates']=numpy.array(out[tp][net]['mean_rates'])
    
    return out
예제 #18
0
 def add_storage(self, keys):
     val = self.Factory_storage()
     self.dic = misc.dict_recursive_add(self.dic, keys, val)
예제 #19
0
 def add_storage(self, keys):
     val=self.Factory_storage()
     self.dic=misc.dict_recursive_add(self.dic, keys, val)