def __init__(self, **_KwargsVariablesDict): # # Default # #init with the default dict first self.__dict__.update(DefaultDict) # # super # #call PredicterClass.__init__(self,**_KwargsVariablesDict) # # set Time # #time variables self.bins_int = int(self.finalTimeFloat/self.stepTimeFloat) #no. of time steps self.t_span = np.linspace(0, self.finalTimeFloat, self.bins_int) #leak terms self.lambda_a = 1/float(self.tau_a) self.lambda_v = 1/float(self.tau_v) self.lambda_d = 1/float(self.tau_d) # # set Gamma # #init Gamma connectivity self.sensorsInt = self.globalSensorsInt+self.placeSensorsInt self.distinctSensorsInt = self.distinctGlobalSensorsInt + self.distinctPlaceSensorsInt self.gammaArray = np.zeros((self.sensorsInt,self.agentsInt),dtype=float) #Build global Gamma connectivity if self.decodGlobalGammaStdFloat>0.: self.gammaArray[:self.globalSensorsInt,:] = ( np.random.normal( self.decodGlobalGammaMeanFloat, self.decodGlobalGammaStdFloat, (self.globalSensorsInt,self.agentsInt) ) ) else: self.gammaArray[:self.globalSensorsInt,:] = self.decodGlobalGammaMeanFloat*np.ones( (self.globalSensorsInt,self.agentsInt) ) #debug 'after global set gammaArray: ', self.gammaArray #Build place Gamma connectivity placeGammaArray = np.zeros( (self.placeSensorsInt,self.placeSensorsInt), dtype=float ) #DIAGONAL #np.fill_diagonal(placeGammaArray,[1.]*self.placeSensorsInt) #debug("placeGammaArray is ",placeGammaArray) #RANDOM if self.placeSensorsInt>0: #random placeGammaArray=( np.random.normal( self.decodPlaceGammaMeanFloat, self.decodPlaceGammaStdFloat, (self.placeSensorsInt,self.placeSensorsInt) ) ) #R FIELD self.placeAgentsInt = self.agentsInt/self.distinctPlaceSensorsInt #middleArray = self.gammaGaussFloat*np.exp( # -(np.arange(self.agentsInt)-(self.agentsInt/2.) # )**2/self.gammaPlaceStdFloat**2 #) middleArray = -self.gammaGaussFloat*np.cos( (2.*np.pi*self.distinctPlaceSensorsInt/self.agentsInt)*(np.arange(self.agentsInt)-(self.agentsInt/2.)) )*np.array( map( float, (np.abs((np.arange(self.agentsInt)-(self.agentsInt/2.)-self.gammaPlaceStdFloat))<(self.placeAgentsInt/2.)) ) ) placeGammaArray = np.zeros((self.placeSensorsInt, self.agentsInt),dtype=float) for __Int in xrange( 0, self.placeSensorsInt, self.distinctPlaceSensorsInt ): #init rollArray = np.copy(middleArray) for _Int in xrange(self.distinctPlaceSensorsInt): #roll rollArray = np.roll(rollArray,self.placeAgentsInt) #set placeGammaArray[__Int+_Int,:] = rollArray #roll placeGammaArray = np.roll(placeGammaArray,(1+self.distinctPlaceSensorsInt/2),axis=0) #set self.gammaArray[self.globalSensorsInt:,:] = placeGammaArray #Check if self.perturbGammaStdFloat>0. or self.perturbGammaMeanFloat>0.: self.perturbGammaArray = scipy.stats.norm( self.perturbGammaMeanFloat, self.perturbGammaStdFloat ).rvs( size=(self.sensorsInt,self.agentsInt) ) self.gammaArray+=self.perturbGammaArray debug('gammaArray: ', self.gammaArray) # # set Omega Fast # #Fast connections self.omegaFastArray = -1.*np.dot(self.gammaArray.T,self.gammaArray) if type(self.constantFast)!=None.__class__: self.omegaFastArray -= self.constantFast self.omegaReset = np.diag(self.omegaFastArray) self.omegaFastArrayEuler = np.copy(self.omegaFastArray) np.fill_diagonal(self.omegaFastArrayEuler,[0. for _Int in xrange(self.agentsInt)]) #debug #debug("self.omegaFastArray is ",self.omegaFastArray) #debug("self.omegaReset is ",self.omegaReset) #Check if self.perturbFastStdFloat>0.: self.perturbFast = scipy.stats.norm( 0., self.perturbFastStdFloat ).rvs( size=(self.agentsInt,self.agentsInt) ) #np.fill_diagonal(self.perturbFast,[0. for _Int in xrange(self.agentsInt)]) self.omegaFastArray = self.perturbFastRatioFloat*self.omegaFastArray self.omegaFastArray = self.omegaFastArray + self.perturbFast np.fill_diagonal(self.omegaFastArray,[0. for _Int in xrange(self.agentsInt)]) debug('omegaFastArray: ', self.omegaFastArray) self.input = self.gammaArray.T # # set Slow # #Slow connections self.omegaSlowArray = None self.jacobianDecodeArray = self.jacobianArray + self.lambda_d*np.eye(self.sensorsInt) if (self.jacobianDecodeArray!=0).any(): self.almostOmegaSlowArray = np.dot(self.gammaArray.T, self.jacobianDecodeArray) self.omegaSlowArray = np.dot(self.almostOmegaSlowArray,self.gammaArray) self.dv = self.dv_complete else: self.dv = self.dv_leak #set self.jacobianDistinctGlobalArray=self.jacobianArray[:self.distinctGlobalSensorsInt,:self.distinctGlobalSensorsInt] #debug "jacobianDistinctGlobalArray is: ", self.jacobianDistinctGlobalArray self.jacobianDistinctPlaceArray=self.jacobianArray[self.globalSensorsInt:self.globalSensorsInt+self.distinctPlaceSensorsInt, self.globalSensorsInt:self.globalSensorsInt+self.distinctPlaceSensorsInt] #debug "jacobianDistintPlaceArray is: ", self.jacobianDistinctPlaceArray self.jacobianDistinctArray=np.zeros((self.distinctSensorsInt,self.distinctSensorsInt),dtype=float) self.jacobianDistinctArray[:self.distinctGlobalSensorsInt,:self.distinctGlobalSensorsInt]=self.jacobianDistinctGlobalArray self.jacobianDistinctArray[self.distinctGlobalSensorsInt:,self.distinctGlobalSensorsInt:]=self.jacobianDistinctPlaceArray # # set Theta # #Threshold for each neuron self.thetaArray = (np.sum(self.gammaArray*self.gammaArray/2, axis=0)) if type(self.constantTheta)!=None.__class__: #debug("self.constantTheta is ",self.constantTheta) self.thetaArray=np.array([self.constantTheta]*self.agentsInt) if type(self.constantFast)!=None.__class__: #debug("l",self.thetaArray) self.thetaArray += self.constantFast/2. debug('thetaArray: ', self.thetaArray) # # set Monitor # self.tau_rate=5. self.refractoryBinsInt=int(self.refractoryFloat/self.stepTimeFloat) self.delayBinsInt=int(self.delayFloat/self.stepTimeFloat) if self.globalSensorIndexIntsList==None: self.globalSensorIndexIntsList=range(self.distinctGlobalSensorsInt) if self.placeSensorIndexIntsList==None: self.placeSensorIndexIntsList=range(self.distinctGlobalSensorsInt,self.distinctGlobalSensorsInt+self.distinctPlaceSensorsInt) self.sensorIndexIntsList=self.globalSensorIndexIntsList+self.placeSensorIndexIntsList self.voltageIndexIntsList=[0,1] self.distinctSensorIndexIntsList=range(self.distinctGlobalSensorsInt)+range( self.globalSensorsInt,self.globalSensorsInt+self.distinctPlaceSensorsInt) if hasattr(self,'rateIndexIntsList')==False: self.rateIndexIntsList=xrange(0,self.agentsInt/2) self.ratesInt=len(self.rateIndexIntsList) # # set Commands # #Input command c self.commandArray = np.zeros((self.sensorsInt, self.bins_int),dtype=float) #global part self.commandArray[:self.globalSensorsInt,:] = self.commandMeanFloat self.commandArray[:self.globalSensorsInt,:] += self.commandOsciFloat*np.sin( 2.*np.pi*0.001*self.commandFrequencyFloat*self.t_span ) #place part if self.distinctPlaceSensorsInt>0: #set placeUnitTimeFloat = self.finalTimeFloat/self.distinctPlaceSensorsInt placeUnitTimeBinsInt = int(placeUnitTimeFloat/self.stepTimeFloat) #Debug #debug("placeUnitTimeFloat is ",placeUnitTimeFloat) #debug("placeUnitTimeBinsInt is ",placeUnitTimeBinsInt) #debug("") #init middleArray = self.commandGaussFloat*np.exp(-(self.t_span-self.t_span[self.bins_int/2])**2/self.commandPlaceStdFloat**2) placeCommandArray = np.zeros((self.placeSensorsInt, self.bins_int),dtype=float) for __Int in xrange( 0, self.placeSensorsInt, self.distinctPlaceSensorsInt ): #init rollArray = np.copy(middleArray) for _Int in xrange(self.distinctPlaceSensorsInt): #roll rollArray = np.roll(rollArray,placeUnitTimeBinsInt) #set placeCommandArray[__Int+_Int,:] = rollArray #roll placeCommandArray = np.roll(placeCommandArray,(1+self.distinctPlaceSensorsInt/2),axis=0) #set self.commandArray[self.globalSensorsInt:,:] = placeCommandArray #Look for noise if self.commandNoiseFloat>0.: noise=0. for IndexInt in xrange(self.bins_int): noise=( 1.-self.commandAttractionFloat )*noise+self.commandNoiseFloat*scipy.stats.norm.rvs() self.commandArray[:, IndexInt]+=noise #Look for step if self.commandStepFloat!=0.: t1=self.finalTimeFloat/(4.*self.stepTimeFloat) t2=3.*self.finalTimeFloat/(4.*self.stepTimeFloat) self.commandArray[:self.globalSensorsInt,t1:t2] += self.commandStepFloat debug('commandArray: ', self.commandArray)
def __init__(self,**_KwargsVariablesDict): # # Default # #init with the default dict first self.__dict__.update(DefaultDict) # # super # #call PredicterClass.__init__(self,**_KwargsVariablesDict) #Check if hasattr(self,'A')==False or type(self.A)==None.__class__: self.A = np.zeros((self.M, self.M)) #np.fill_diagonal(self.A,[-1./float(self.tau_a)]*self.M) np.fill_diagonal(self.A,[-1./float(self.tau_a)]) #fix self.M=len(self.A) #/##############/# # Build protocols # #Check if self.protocol=='split': self.__dict__.update( { "c0a": 0., #input stationary command "c0b": np.linspace(1.,-1.,self.M) if self.M>1 else 0.5, #input stationary command "c1a":0., "c1b":0., "cnoise":0., "rnoise":0., } ) if self.protocol=='damp': self.__dict__.update( { "c0a": 0., #input stationary command "c0b": 0.5, #input stationary command "c1a":0., "c1b":0., "cnoise":0., "rnoise":0., } ) elif self.protocol=='noise': self.__dict__.update( { "c0a": 0., #input stationary command "c0b": 0., #input stationary command "c1a": 0., "c1b": 0., "f1a":4., #oscillatory drive (Hz) "f1b":4., "cnoise":1., "attraction":0.01, "rnoise":0., } ) elif self.protocol=='osci': self.__dict__.update( { "c0a": 0., #input stationary command "c0b": 0., #input stationary command "c1a":1., "c1b":1., "f1a":4., #oscillatory drive (Hz) "f1b":4., "cnoise":0., "rnoise":0., } ) #/##############/# # Build connectivity # #Decoder if self.N==1: self.D = np.array([[self.weight]]) else: #Check if type(self.weight) not in [np.float64,float]: self.D = np.array(self.weight) else: #import import scipy.stats np.random.seed(4) #debug stdFloat=self.weight/float(self.N) #debug debug('stdFloat is ') debug(stdFloat) debug('') #set self.D = scipy.stats.norm( 0., stdFloat ).rvs( size=(self.M, self.N) ) """ self.D = np.random.normal( 0, self.weight/float(self.N), (self.M, self.N) ) """ #debug debug('self.D is ') debug(self.D) debug("") #transpose self.input=self.D.T self.lambda_r=1./float(self.tau_r) self.OmegaFast=-np.dot(self.D.T,self.D) if self.type=="dynamic": #set self.lambda_d = 1./float(self.tau_d) #leak in Hz #Debug debug("self.A is ") debug(self.A) debug('') #Check self.ADecode = self.A + self.lambda_d*np.eye(self.M) #Check if (self.ADecode!=0).any(): #debug debug("self.ADecode is ") debug(self.ADecode) debug('') self.AlmostOmegaSlow=np.dot(self.D.T, self.ADecode) self.OmegaSlow=np.dot(self.AlmostOmegaSlow,self.D) self.AgentEulerMethod=self.dr_dyn_complete #debug debug("self.AlmostOmegaSlow is ") debug(self.AlmostOmegaSlow) debug('') else: self.AgentEulerMethod=self.dr_dyn_leak else: self.AgentEulerMethod=self.dr_auto #build transfer self.TransferMethod=getattr(self,'f_'+self.transfer)