Example #1
0
      def perform_analysis(self):
            self.datastore.print_content()
            dsv = analysis_data_structure_parameter_filter_query(self.datastore,identifier='PerNeuronValue')
            for sheet in self.datastore.sheets():
                # Get PerNeuronValue ASD and make sure they are all associated with the same stimulus are 
                # do not differ in any ASD parameters except the stimulus
                dsv = select_result_sheet_query(dsv,sheet)
                if ads_is_empty(dsv): break
                
                assert equal_ads_except(dsv,['stimulus_id'])
                assert ads_with_equal_stimulus_type(dsv,not_None=True)
 
                self.pnvs = dsv.get_analysis_result(sheet_name=sheet)
                # get stimuli
                st = [StimulusID(s.stimulus_id) for s in self.pnvs]
                
                d = colapse_to_dictionary([z.values for z in self.pnvs],st,self.parameters.parameter_name)
                result_dict = {}
                for k in  d.keys():
                    keys,values = d[k]
                    y = []
                    x = []
                    for v,p in zip(values,keys):
                        y.append(v)
                        x.append(numpy.zeros(numpy.shape(v))+p)
                    
                    
                    pref,sel = circ_mean(numpy.array(x),weights=numpy.array(y),axis=0,low=0,high=st[0].periods[self.parameters.parameter_name],normalize=True)
                    
                    logger.debug('Adding PerNeuronValue to datastore')
                    
                    self.datastore.full_datastore.add_analysis_result(PerNeuronValue(pref,st[0].units[self.parameters.parameter_name],value_name = self.parameters.parameter_name + ' preference',sheet_name=sheet,tags=self.tags,period=st[0].periods[self.parameters.parameter_name],analysis_algorithm=self.__class__.__name__,stimulus_id=str(k)))
                    self.datastore.full_datastore.add_analysis_result(PerNeuronValue(sel,st[0].units[self.parameters.parameter_name],value_name = self.parameters.parameter_name + ' selectivity',sheet_name=sheet,tags=self.tags,period=1.0,analysis_algorithm=self.__class__.__name__,stimulus_id=str(k)))
Example #2
0
 def __init__(self, network, source, target, parameters,name):
     MozaikComponent.__init__(self,network,parameters)
     self.name = name
     self.source = source
     self.target = target
     weights = []
     
     
     for (i,neuron1) in enumerate(self.target.pop.all()):
         for (j,neuron2) in enumerate(self.source.pop.all()):
     
             or_dist = circular_dist(self.target.get_neuron_annotation(i,'LGNAfferentOrientation'),self.source.get_neuron_annotation(j,'LGNAfferentOrientation'),numpy.pi) / (numpy.pi/2)
             
             if self.parameters.specific_arborization.target_synapses == 'excitatory':
                     phase_dist = circular_dist(self.target.get_neuron_annotation(i,'LGNAfferentPhase'),self.source.get_neuron_annotation(j,'LGNAfferentPhase'),2*numpy.pi) / numpy.pi
             elif self.parameters.specific_arborization.target_synapses == 'inhibitory':
                     phase_dist = (numpy.pi - circular_dist(self.target.get_neuron_annotation(i,'LGNAfferentPhase'),self.source.get_neuron_annotation(j,'LGNAfferentPhase'),2*numpy.pi)) / numpy.pi
             else:
                 logger.error('Unknown type of synapse!')
                 return	
     
             or_gauss = normal_function(or_dist,mean=0,sigma=self.parameters.or_sigma)
             phase_gauss = normal_function(phase_dist,mean=0,sigma=self.parameters.or_sigma)
             w = phase_gauss*or_gauss*or_gauss
             
             weights.append((j,i,w,self.parameters.propagation_constant))
     
     we = numpy.zeros((len(self.source.pop),len(self.target.pop)))
     
     
     pnv_source = []
     pnv_target = []
     for (i,neuron1) in enumerate(self.target.pop.all()):
         pnv_target.append(self.target.get_neuron_annotation(i,'LGNAfferentOrientation'))
     
     for (i,neuron1) in enumerate(self.source.pop.all()):
         pnv_source.append(self.source.get_neuron_annotation(i,'LGNAfferentOrientation'))
     
     
     for (j,i,w,xsj) in weights:
         we[j,i] = w
     
     (angle,mag) = circ_mean(numpy.array([numpy.array(pnv_target).T for i in xrange(0,numpy.shape(we)[0])]),weights=numpy.array(we),low=0,high=numpy.pi,axis=1)            
     
    
                             
     if self.parameters.probabilistic:
         SpecificProbabilisticArborization(network, self.source, self.target, weights,self.parameters.specific_arborization,self.name).connect()
     else:
         SpecificArborization(network, self.source, self.target, weights,self.parameters.specific_arborization,self.name).connect()
Example #3
0
 def ploter(self,idx,gs,params):
     sx = self.connecting_neurons_positions[idx][0]
     sy = self.connecting_neurons_positions[idx][1]
     tx = self.connected_neuron_position[idx][0]
     ty = self.connected_neuron_position[idx][1]
     if not self.parameters.reversed:
         w  = self.connections[idx].weights[self.parameters.neuron,:]
     else:
         w  = self.connections[idx].weights[:,self.parameters.neuron]
     
     
     # pick the right PerNeuronValue to show
     pnv = []
     if self.pnvs!=None:
        for p in self.pnvs:
            if not self.parameters.reversed and p.sheet_name == self.connections[idx].target_name:
               pnv.append(p)
            if self.parameters.reversed and p.sheet_name == self.connections[idx].source_name:
               pnv.append(p)
        
        if len(pnv) > 1:
           raise ValueError('ERROR: too many matching PerNeuronValue ADSs')  
        else:
           pnv = pnv[0] 
            
        if len(pnv.values) != len(w):
           raise ValueError('ERROR: length of colors does not match length of weights \[%d \!\= %d\]. Ignoring colors!' % (len(pnv.values),len(w))) 
           
     
     if pnv != None: 
         from mozaik.tools.circ_stat import circ_mean
         (angle,mag) = circ_mean(numpy.array(pnv.values),weights=w,high=pnv.period)
         params.setdefault("title",str(self.connections[idx].name) + "| Weighted mean: " + str(angle))
         params.setdefault("colorbar_label",pnv.value_name)
         params.setdefault("colorbar",True)
         
         if self.connections[idx].source_name == self.connections[idx].target_name:
            ConnectionPlot(sx,sy,tx,ty,w,colors=pnv.values,line=False,period=pnv.period,**params)(gs) 
         else:
            ConnectionPlot(sx,sy,numpy.min(sx)*1.2,numpy.min(sy)*1.2,w,colors=pnv.values,period=pnv.period,line=False,**params)(gs) 
     else:
         params.setdefault("title",self.connections[idx].name)
         if self.connections[idx].source_name == self.connections[idx].target_name:
            ConnectionPlot(sx,sy,tx,ty,w,line=False,**params)(gs) 
         else:
            ConnectionPlot(sx,sy,numpy.min(sx)*1.2,numpy.min(sy)*1.2,w,line=False,**params)(gs) 
Example #4
0
    def _ploter(self, idx, gs):
        #ix = numpy.flatnonzero(self.connections[idx].weights[:,1]==index)
        #x = self.proj.pre.positions[0][self.connections[idx].weights[ix,0]]
        #y = self.proj.pre.positions[1][self.connections[idx].weights[ix,0]]
        #w = weights[idx,2]
        tx = self.connected_neuron_position[idx][0]
        ty = self.connected_neuron_position[idx][1]
        if not self.parameters.reversed:
            index = self.datastore.get_sheet_indexes(self.connections[idx].source_name,self.parameters.neuron)
            ix = numpy.flatnonzero(numpy.array(self.connections[idx].weights)[:,1]==index)
        else:
            index = self.datastore.get_sheet_indexes(self.connections[idx].target_name,self.parameters.neuron)
            ix = numpy.flatnonzero(numpy.array(self.connections[idx].weights)[:,0]==index)
            
            
        sx = self.connecting_neurons_positions[idx][0][ix]
        sy = self.connecting_neurons_positions[idx][1][ix]
        w = numpy.array(self.connections[idx].weights)[ix,2]
        d = numpy.array(self.connections[idx].delays)[ix,2]

        assert numpy.shape(w) == numpy.shape(d)
        # pick the right PerNeuronValue to show
        pnv = []
        if self.pnvs != None:
            for p in self.pnvs:
                if not self.parameters.reversed and p.sheet_name == self.connections[idx].target_name:
                    pnv.append(p)
                if self.parameters.reversed and p.sheet_name == self.connections[idx].source_name:
                    pnv.append(p)
            
            if len(pnv) > 1:
                raise ValueError('ERROR: too many matching PerNeuronValue ADSs')
            elif len(pnv) != 0:
                pnv = pnv[0]

                if len(pnv.values) != len(w):
                    raise ValueError('ERROR: length of colors does not match length of weights \[%d \!\= %d\]. Ignoring colors!' % (len(pnv.values), len(w)))

        gss = gridspec.GridSpecFromSubplotSpec(2, 1, subplot_spec=gs)
        
        # Plot the weights
        gs = gss[0,0]
        params = {}
        if pnv != []:
            from mozaik.tools.circ_stat import circ_mean
            (angle, mag) = circ_mean(numpy.array(pnv.values),
                                     weights=w,
                                     high=pnv.period)
            params["title"] = 'Weights: '+ str(self.connections[idx].proj_name) + "| Weighted mean: " + str(angle)
            params["colorbar_label"] =  pnv.value_name
            params["colorbar"] = True
            
            if self.connections[idx].source_name == self.connections[idx].target_name:
                params["line"] = False
                plots = [("ConnectionsPlot",ConnectionPlot(sx, sy, tx, ty, w,colors=pnv.values,period=pnv.period),gs,params)]
            else:
                params["line"] = True
                plots = [("ConnectionsPlot",ConnectionPlot(sx, sy, numpy.min(sx)*1.2, numpy.min(sy)*1.2, w,colors=pnv.values,period=pnv.period),gs,params)]
        else:
            params["title"] = 'Weights: '+ self.connections[idx].proj_name
            
            if self.connections[idx].source_name == self.connections[idx].target_name:
                params["line"] = False
                plots = [("ConnectionsPlot",ConnectionPlot(sx, sy, tx, ty, w,colors=pnv.values,period=pnv.period),gs,params)]
            else:
                params["line"] = True
                plots = [("ConnectionsPlot",ConnectionPlot(sx, sy, numpy.min(sx)*1.2, numpy.min(sy)*1.2,w),gs,params)]

        # Plot the delays
        gs = gss[1,0]
        params = {}
        params["title"]  = 'Delays: '+ self.connections[idx].proj_name
        if self.connections[idx].source_name == self.connections[idx].target_name:
            params["line"] = False
            plots.append(("DelaysPlot",ConnectionPlot(sx, sy, tx, ty, (numpy.zeros(w.shape)+0.3)*(w!=0),colors=d),gs,params))
        else:
            params["line"] = True
            plots.append(("DelaysPlot",ConnectionPlot(sx, sy, numpy.min(sx)*1.2, numpy.min(sy)*1.2,(numpy.zeros(w.shape)+0.3)*(w!=0),colors=d),gs,params))
        
        return plots