Пример #1
0
	def getSynapticRisePerturbationVariable(self,_PerturbationComplex):

		#debug
		'''
		self.debug(
			[
				('self.',self,[
						'StabilizedDecayTimeVariable',
					]),
				'_PerturbationComplex is '+str(_PerturbationComplex)
			]
		)
		'''

		#return
		return SYS.setMatrixArray(
					SYS.setMatrixArray(
						self.getSynapticDelayPerturbationVariable(_PerturbationComplex),
						1.+self.StabilizedDecayTimeVariable*_PerturbationComplex,
						np.ndarray.__div__,
						_AxisInt=1
					),
					1.+self.StabilizedRiseTimeVariable*_PerturbationComplex,
					np.ndarray.__div__,
					_AxisInt=1
				)
Пример #2
0
	def getSynapticDelayPerturbationVariable(self,_PerturbationComplex):

		#debug
		'''
		self.debug(
			[
				('self.',self,[
						'StabilizedDelayTimeVariable'
					]),
				'_PerturbationComplex is '+str(_PerturbationComplex)
			]
		)
		'''

		#return
		return SYS.setMatrixArray(
					np.ones(
								(self.StationarizingUnitsInt,self.StationarizingUnitsInt),
								dtype=complex
							),
					np.exp(
						-self.StabilizedDelayTimeVariable*_PerturbationComplex
					),
					np.ndarray.__mul__,
					_AxisInt=1
				)
Пример #3
0
	def setStabilizedFlatPerturbationComplexesArray(self):

		#call
		self.setStabilizedTotalPerturbationComplexesArray()

		#/###############/#
		# multiply all by the LeakNeuralPerturbationVariable
		#

		#get the numerator leak term
		StabilizedLeakNeuralPerturbationVariable=self.getLeakNeuralPerturbationComplex(
			self.StabilizedPerturbationComplex
		)

		#mul
		self.StabilizedFlatTotalPerturbationComplexesArray=SYS.setMatrixArray(
			self.StabilizedTotalPerturbationComplexesArray.T,
			StabilizedLeakNeuralPerturbationVariable,
			np.ndarray.__mul__
		).T

		#debug
		'''
Пример #4
0
	def do_numscipy(
				self
			):	

		#debug
		'''
		self.debug(
				[
					'We numscipy here',
					('self.',self,[
							'NumscipyingValueVariable',
							'NumscipiedValueFloatsArray'
						])
				]
			)
		'''

		#/#################/#
		# Set the size of the matrix
		#

		#Check
		if type(self.NumscipyingValueVariable)==None.__class__:

			#debug
			'''
			self.debug(
				[
					'This is an array that we have to build'
				]
			)
			'''

			#set
			if self.NumscipyingSizeTuple==None or len(self.NumscipyingSizeTuple)==0 :

				#set
				self.NumscipyingSizeTuple=(
					self.NumscipyingRowsInt,
					self.NumscipyingColsInt
				)

			else:

				#set
				self.NumscipyingRowsInt=self.NumscipyingSizeTuple[0]
				self.NumscipyingColsInt=self.NumscipyingSizeTuple[1]


			#init
			self.NumscipiedValueFloatsArray=None

		else:

			#debug
			'''
			self.debug(
				[
					'This is an array already built'
				]
			)
			'''

			#set
			self.NumscipyingSizeTuple=np.shape(
				self.NumscipyingValueVariable
			)
			self.NumscipyingRowsInt=self.NumscipyingSizeTuple[0]
			self.NumscipyingColsInt=self.NumscipyingSizeTuple[1]

			#alias
			self.NumscipiedValueFloatsArray=self.NumscipyingValueVariable

			#debug
			'''
			self.debug(
				[
					'We have setted the shape of the matrix',
					('self.',self,['NumscipyingSizeTuple'])
				]
			)
			'''


		#/#################/#
		# Build maybe
		#

		#Check
		if type(self.NumscipyingValueVariable)==None.__class__:


			#/#################/#
			# Set maybe the seed
			#
	
			#check
			if self.NumscipyingSeedVariable!=None:

				#seed
				np.random.seed(self.NumscipyingSeedVariable)

				#debug
				'''
				self.debug(
					[
						"We have fixed a seed",
						('self.',self,[
								'NumscipyingSeedVariable'
							])
					]
				)
				'''

			#/#################/#
			# Get the continuous stat
			#

			#Check
			if self.NumscipyingStdFloat>0.:

				#import
				import scipy.stats

				#get
				self.NumscipiedContinuousStatRigidFunction=getattr(
					scipy.stats,
					self.NumscipyingContinuousStatStr
				)(
					self.NumscipyingMeanFloat,
					self.NumscipyingStdFloat
				).rvs

			#/#################/#
			# Get the discrete stat
			#

			#Check
			if self.NumscipyingSparseFloat>0. and self.NumscipyingSparseFloat<1.:

				#debug
				'''
				self.debug(
					[
						'We numscipy here',
						'We set a discrete skeleton',
						('self.',self,[
								'NumscipyingDiscreteStatStr',
								'NumscipyingSparseFloat'
							])
					]
				)
				'''
				
				#/#################/#
				# Get a list of one or zero
				#

				#import
				import scipy.stats

				#get
				self.NumscipiedDiscreteStatRigidFunction=getattr(
					scipy.stats,
					self.NumscipyingDiscreteStatStr
				).rvs

				#prod
				NumscipiedSizeInt=np.prod(self.NumscipyingSizeTuple)

				#set
				NumscipiedRandomIntsArray=self.NumscipiedDiscreteStatRigidFunction(
					self.NumscipyingSparseFloat,
					size=NumscipiedSizeInt
				)

				#/#################/#
				# Maybe set a continuous stat for non zero values
				#

				#debug
				self.debug(
					[
						('self.',self,[
								'NumscipiedContinuousStatRigidFunction'
							])
					]
				)

				#map
				if self.NumscipiedContinuousStatRigidFunction!=None:

					#Check
					self.NumscipiedValueFloatsArray=np.array(
						map(
							lambda __IndexInt,__BoolInt:
							self.NumscipiedContinuousStatRigidFunction()
							if __BoolInt==1
							else 0.,
							xrange(NumscipiedSizeInt),
							NumscipiedRandomIntsArray,
						)
					)


				else:

					#just floatify
					self.NumscipiedValueFloatsArray=self.NumscipyingMeanFloat*np.array(
						map(
							float,
							NumscipiedRandomIntsArray
						)
					)



				#reshape
				self.NumscipiedValueFloatsArray=self.NumscipiedValueFloatsArray.reshape(
					self.NumscipyingSizeTuple
				)

				#Check
				if self.NumscipyingSwitchFloat>0.:

					#/##################/#
					# Switch the sgn 
					#

					#debug
					'''
					self.debug(
						[
							'We switch the sign',
							('self.',self,[
									'NumscipyingSwitchFloat'
								])
						]
					)
					'''

					#import
					import itertools

					#filter the upper index tuples
					self.NumscipiedIndexIntsTuplesList=filter(
						lambda __Tuple:
						__Tuple[1]!=__Tuple[0],
						itertools.product(
							xrange(self.NumscipyingColsInt),
							xrange(self.NumscipyingColsInt)
						)
					)

					#/#################/#
					# group by the null and non null index tuples
					#

					#filter
					[
						self.NumscipiedNonNullIndexIntsTuplesList,
						self.NumscipiedNullIndexIntsTuplesList
					]=SYS.groupby(
						lambda __IndexIntsTuple:
						self.NumscipiedValueFloatsArray[
							__IndexIntsTuple
						]!=0.,
						self.NumscipiedIndexIntsTuplesList
					)

					#len
					NumscipiedSwitchsInt=int(self.NumscipyingSwitchFloat*len(
							self.NumscipiedNonNullIndexIntsTuplesList
						)
					)

					#copy
					self.NumscipiedToSwitchIndexIntsTuplesList=self.NumscipiedNonNullIndexIntsTuplesList[:]

					#debug
					'''
					self.debug(
						[
							'Before shuffle to switch',
							('self.',self,[
									'NumscipiedToSwitchIndexIntsTuplesList'
								]),
						]
					)
					'''

					#Shuffle and pick the NumscipiedToSwitchIndexIntsTuplesList
					np.random.shuffle(
						self.NumscipiedToSwitchIndexIntsTuplesList
					)

					#cut
					self.NumscipiedToSwitchIndexIntsTuplesList=self.NumscipiedToSwitchIndexIntsTuplesList[
						:NumscipiedSwitchsInt
					] 

					#debug
					'''
					self.debug(
						[
							'We map switch here',
							('self.',self,[
									'NumscipiedToSwitchIndexIntsTuplesList'
								]),
							'NumscipiedSwitchsInt is '+str(NumscipiedSwitchsInt)
						]
					)
					'''

					#map switch
					map(
						lambda __NumscipiedToSwitchIndexIntsTuple:
						self.NumscipiedValueFloatsArray.__setitem__(
							__NumscipiedToSwitchIndexIntsTuple,
							-self.NumscipiedValueFloatsArray[
								__NumscipiedToSwitchIndexIntsTuple
							]
						),
						self.NumscipiedToSwitchIndexIntsTuplesList
					)	


			#/#################/#
			# If it is a dense matrix then 
			# set direct all the matrix

			#Check
			if type(self.NumscipiedValueFloatsArray)==None.__class__:

				#debug
				'''
				self.debug(
					[
						'This is a random norm distribution',
						('self.',self,[
								'NumscipyingMeanFloat',
								'NumscipyingStdFloat',
								'NumscipiedContinuousStatRigidFunction'
							])
					]
				)
				'''

				#Check
				if self.NumscipiedContinuousStatRigidFunction!=None:

					#set
					self.NumscipiedValueFloatsArray=self.NumscipiedContinuousStatRigidFunction(
						size=self.NumscipyingSizeTuple
					)

				else:

					#set
					self.NumscipiedValueFloatsArray=self.NumscipyingMeanFloat*np.ones(
						self.NumscipyingSizeTuple
					)

		#debug
		'''
		self.debug(
			[
				'at this step',
				('self.',self,[
						'NumscipiedValueFloatsArray',
						'NumscipyingMeanFloat'
					])
			]
		)	
		'''
		

		#/#################/#
		# Normalize maybe 
		# 

		#debug
		'''
		self.debug(
			[
				'Do we have to normalize',
				('self.',self,[
						'NumscipyingDivideVariable',
						'NumscipyingNormalisationFunction'
					])
			]
		)
		'''

		#Check
		if self.NumscipyingDivideVariable!=None:

			#divide
			self.NumscipiedValueFloatsArray=(
				self.NumscipiedValueFloatsArray.T/self.NumscipyingDivideVariable
			).T
		
		#Check
		if self.NumscipyingNormalisationFunction!=None and len(
			self.NumscipyingSizeTuple) and self.NumscipyingSizeTuple[0]==self.NumscipyingSizeTuple[1]:

				#set
				self.NumscipiedNormVariable=self.NumscipyingNormalisationFunction(
					self.NumscipyingSizeTuple[0]
				)

				#debug
				'''
				self.debug(
					[
						'We normalize with',
						'NumscipiedNormVariable is',
						str(NumscipiedNormVariable),
						('self.',self,[
								'NumscipyingStdFloat'
							])
					]
				)
				'''
				
				#normalize
				self.NumscipiedValueFloatsArray/=self.NumscipiedNormVariable

		#/#################/#
		# Symmetrize maybe 
		# 

		#set
		NumscipiedShiftSymmetryFloat=0.5*(self.NumscipyingSymmetryFloat+1.)

		#compute
		self.NumscipiedSymmetricsInt=(
			self.NumscipyingColsInt*(self.NumscipyingColsInt-1)
		)

		#Check
		if self.NumscipyingSymmetryFloat!=0.:

			#debug
			'''
			self.debug(
				[
					'We are going to symmetrize',
					('self.',self,[
						'NumscipyingSymmetryFloat'
					])

				]
			)
			'''

			#Check
			if self.NumscipyingSparseFloat==0. and self.NumscipyingStdFloat>0.:

				#/#################/#
				# This is a dense symmetrization
				# 

				#debug
				'''
				self.debug(
					[
						'We do a dense symmetrization'
					]
				)
				'''

				#import 
				import itertools

				#copy
				NumscipiedValueFloatsArray=self.NumscipiedValueFloatsArray[:]

				#build the scale factor
				"""
				#ERWAN version
				NumscipiedScaleFloat=(
					(
						self.NumscipyingSymmetryFloat-1.
					)*0.5
				)+1

				#Build a more or less DisSymmetricRandomArray
				self.NumscipiedValueFloatsArray=2.*(
					(NumscipiedScaleFloat/2.)*(NumscipiedValueFloatsArray+NumscipiedValueFloatsArray.T)
						+(0.5-(NumscipiedScaleFloat/2.))*(NumscipiedValueFloatsArray-NumscipiedValueFloatsArray.T)
					)
				"""

				#CELIAN version

				#compute
				NumscipiedScaleFloat = np.sqrt(
		        	NumscipiedShiftSymmetryFloat**2-NumscipiedShiftSymmetryFloat+0.5
		        )

		        #compute the anti-symm martix
				self.NumscipiedValueFloatsArray = (
					NumscipiedShiftSymmetryFloat * (
						NumscipiedValueFloatsArray + NumscipiedValueFloatsArray.T
					)/2. + (1.-NumscipiedShiftSymmetryFloat) * (
						NumscipiedValueFloatsArray - NumscipiedValueFloatsArray.T
					)/2.
				) / NumscipiedScaleFloat

				#fill diagonal
				np.fill_diagonal(
					NumscipiedValueFloatsArray,
					np.diagonal(self.NumscipiedValueFloatsArray)
				) 

			elif self.NumscipyingSparseFloat>0.:

				#/#################/#
				# This is a sparse symmetrization
				# 

				#debug
				'''
				self.debug(
					[
						'We do a targeted symmetrization',
						'First we keep only the upper part and triangularize',
						('self.',self,[
								'NumscipyingSymmetryFloat',
								'NumscipiedSymmetricsInt'
							])
					]
				)		
				'''

				#triu
				self.NumscipiedValueFloatsArray=np.triu(
					self.NumscipiedValueFloatsArray
				)
				self.NumscipiedValueFloatsArray=self.NumscipiedValueFloatsArray+(
					1. if self.NumscipyingSymmetryFloat>=0. else -1.
				)*self.NumscipiedValueFloatsArray.T-np.diag(
					np.diagonal(
							self.NumscipiedValueFloatsArray
						)
					)

				#Check
				if self.NumscipiedIndexIntsTuplesList==None:

					#import
					import itertools

					#filter the upper index tuples
					self.NumscipiedIndexIntsTuplesList=filter(
						lambda __Tuple:
						__Tuple[1]!=__Tuple[0],
						itertools.product(
							xrange(self.NumscipyingColsInt),
							xrange(self.NumscipyingColsInt)
						)
					)

				#/#################/#
				# group by the null and non null index tuples
				#

				#filter
				[
					self.NumscipiedNonNullIndexIntsTuplesList,
					self.NumscipiedNullIndexIntsTuplesList
				]=SYS.groupby(
					lambda __IndexIntsTuple:
					self.NumscipiedValueFloatsArray[
						__IndexIntsTuple
					]!=0.,
					self.NumscipiedIndexIntsTuplesList
				)

				#debug
				'''
				self.debug(
					[
						'Now',
						('self.',self,[
							'NumscipiedNonNullIndexIntsTuplesList'
						])
					]
				)
				'''

				#/#################/#
				# This is a sparse targeting symmetrization
				# 

				#debug
				'''
				self.debug(
					[
						'Ok we have built a sparse symmetric matrix',
						'We are going to dissymetrize by picking index tuples',
						'For now, we have just kept the upper values',
						('self.',self,[
							'NumscipiedIndexIntsTuplesList'
						]),
						'We are just going to pick the non null values',
					]
				)
				'''

				#/#################/#
				# determine a shuffle list of pair to dissymetrize
				#

				#int
				self.NumscipiedToDissymetricsInt=(int)(
					(1.-abs(self.NumscipyingSymmetryFloat))*len(
							self.NumscipiedNonNullIndexIntsTuplesList
					)
				)/2

				#copy
				self.NumscipiedToDissymetrizeIndexIntsTuplesList=self.NumscipiedNonNullIndexIntsTuplesList[:]

				#debug
				'''
				self.debug(
					[
						'Before shuffle',
						('self.',self,[
								'NumscipiedToDissymetrizeIndexIntsTuplesList'
							]),
						'We take the half of self.NumscipiedToDissymetricsInt for the targetting case'
					]
				)
				'''

				#Shuffle and pick the self.NumscipiedToDissymetricsInt/2
				np.random.shuffle(self.NumscipiedToDissymetrizeIndexIntsTuplesList)
				self.NumscipiedToDissymetrizeIndexIntsTuplesList=self.NumscipiedToDissymetrizeIndexIntsTuplesList[
					:(self.NumscipiedToDissymetricsInt/2)
				] if self.NumscipyingStdFloat==0 else self.NumscipiedToDissymetrizeIndexIntsTuplesList[
					:self.NumscipiedToDissymetricsInt
				]

				#debug
				'''
				self.debug(
					[
						'in the end',
						('self.',self,[
							#'NumscipiedNonNullIndexIntsTuplesList',
							'NumscipiedToDissymetrizeIndexIntsTuplesList',
							#'NumscipiedNullIndexIntsTuplesList',	
							'NumscipiedToDissymetricsInt'					
						]),
						'len(self.NumscipiedNonNullIndexIntsTuplesList) is ',
						str(len(self.NumscipiedNonNullIndexIntsTuplesList)),

					]
				)
				'''

				#/#################/#
				# prepare the other list of null tuples
				# in which we are going to transform

				#map
				self.NumscipiedNullIndexIntsListsList=map(
					lambda __IndexInt:
					[],
					xrange(self.NumscipyingColsInt)
				)

				#map
				map(
					lambda __NumscipiedNullIndexIntsTuple:
					self.NumscipiedNullIndexIntsListsList[
						__NumscipiedNullIndexIntsTuple[0]
					].append(
						__NumscipiedNullIndexIntsTuple[1]
					),
					self.NumscipiedNullIndexIntsTuplesList
				)

				#debug
				'''
				self.debug(
					[
						('self.',self,[
								'NumscipiedNullIndexIntsListsList'
							])
					]
				)
				'''

				#/#################/#
				# Now setSymmmetrize for each ToDissymetrize
				# 

				#map
				self.NumscipiedIsDisymmetrizeIndexIntsListsList=map(
					lambda __IndexInt:
					[],
					xrange(self.NumscipyingColsInt)
				)

				#init
				self.NumscipiedIsDissymetricsInt=0

				#set
				self.NumscipiedDissymetryFunction=(lambda : 0.) if self.NumscipyingStdFloat==0. else (
					(lambda : self.NumscipiedContinuousStatRigidFunction()/self.NumscipiedNormVariable)
					if self.NumscipiedNormVariable!=None else self.NumscipiedContinuousStatRigidFunction
				)

				#debug
				'''
				self.debug(
					[
						'before setDisymmetrize',
						('self.',self,[
								'NumscipiedDissymetryFunction'
							])
					]
				)
				'''

				#map
				map(
					lambda __NumscipiedToDissymetrizeIndexIntsTuple:
					self.setDisymmetrize(
						__NumscipiedToDissymetrizeIndexIntsTuple
					),
					self.NumscipiedToDissymetrizeIndexIntsTuplesList
				)
			
				#debug
				'''
				self.debug(
					[
						'In the end',
						('self.',self,
							[
								'NumscipiedToDissymetricsInt',
								'NumscipiedToDissymetrizeIndexIntsTuplesList',
								'NumscipiedIsDisymmetrizeIndexIntsListsList',
								'NumscipiedIsDissymetricsInt',
							]
						)
					]
				)
				'''

		#/#################/#
		# Maybe set a specific diagonal
		# 

		#Check
		if type(self.NumscipyingDiagFloatsArray)!=None.__class__ and len(
			self.NumscipyingDiagFloatsArray)==np.shape(
				self.NumscipiedValueFloatsArray
			)[0]:

			#debug
			'''
			self.debug(('self.',self,['NumscipyingDiagFloatsArray']))
			'''
			
			#map
			'''
			map(
					lambda __RowInt,__NumscipyingDiagFloat:
					self.NumscipiedValueFloatsArray.__setitem__(
						(__RowInt,__RowInt),
						__NumscipyingDiagFloat
					),
					xrange(len(self.NumscipiedValueFloatsArray)),
					self.NumscipyingDiagFloatsArray
				)
			'''

			#fill diagonal
			np.fill_diagonal(
				self.NumscipiedValueFloatsArray,
				np.diagonal(self.NumscipyingDiagFloatsArray)
			) 


		#/#################/#
		# Force maybe the sum of the rows or the cols to be the same
		# 

		#Check
		if self.NumscipyingMeanForceStr!="None":

			#debug
			"""
			self.debug(
				[
					('We force the ' + self.NumscipyingMeanForceStr + ' to be the same'),
					('self.',self,[
						'NumscipyingMeanFloat',
						'NumscipiedValueFloatsArray'
					])
				]
			)
			"""

			#Check
			if self.NumscipyingMeanForceStr=="rows":
				SumAxisInt=1
				SetAxisInt=0
			elif self.NumscipyingMeanForceStr=="cols":
				SumAxisInt=0
				SetAxisInt=1

			#compute
			NumscipiedResiduFloatsArray = np.sum(
					self.NumscipiedValueFloatsArray, 
					axis = SumAxisInt,
				) - self.NumscipyingMeanFloat

			#debug
			"""
			self.debug(
				[
					"NumscipiedResiduFloatsArray is "+str(NumscipiedResiduFloatsArray)
				]
			)
			"""

			#set
			SYS.setMatrixArray(
				self.NumscipiedValueFloatsArray,
				- NumscipiedResiduFloatsArray/float(self.NumscipyingColsInt),
				_SetMethod=np.ndarray.__add__,
				_AxisInt=SetAxisInt
			)

		#/#################/#
		# Compute statistic
		# 

		#debug
		'''
		self.debug(
			[
				'Do we compute statistics on the matrix ?',
				('self.',self,[
						'NumscipyingStatBool',
						'NumscipyingRowsInt',
						'NumscipyingColsInt'	
					]),
				'self.NumscipyingRowsInt==self.NumscipyingColsInt is '+str(
					self.NumscipyingRowsInt==self.NumscipyingColsInt
				)
			]
		)
		'''
		
		#Check
		if self.NumscipyingStatBool and self.NumscipyingRowsInt==self.NumscipyingColsInt:

			#import
			import itertools

			#debug
			'''
			self.debug(
				[
					'We compute the variance',
					('self.',self,[
							'NumscipiedSymmetricsInt'
						])
				]
			)
			'''

			#list
			NumscipiedLateralIndexIntsList=list(
				itertools.product(
										xrange(self.NumscipyingRowsInt),
										xrange(self.NumscipyingColsInt)
									)
			)

			#variance
			self.NumscipiedMeanFloat=np.sum(
				np.array(
						filter(
								lambda __Float:
								__Float!=None,
								map(
									lambda __Tuple:
									self.NumscipiedValueFloatsArray[__Tuple]
									if __Tuple[0]!=__Tuple[1] else None
									,
									NumscipiedLateralIndexIntsList
								)
							)
						)
					)/(float(self.NumscipiedSymmetricsInt))

			#debug
			'''
			self.debug(
				[
					('self.',self,[
							'NumscipiedMeanFloat'
						])
				]
			)
			'''

			#variance
			self.NumscipiedVarianceFloat=np.sum(
				np.array(
					filter(
							lambda __Float:
							__Float!=None,
							map(
								lambda __Tuple:
								(
									self.NumscipiedValueFloatsArray[__Tuple]-self.NumscipiedMeanFloat
								)**2
								if __Tuple[0]!=__Tuple[1] else None
								,NumscipiedLateralIndexIntsList
							)
						)
					)
				)/(float(self.NumscipiedSymmetricsInt-1))

			#set
			self.NumscipiedSommersFloat = (
				2.*NumscipiedShiftSymmetryFloat-1.
			)/(
				2.*NumscipiedShiftSymmetryFloat*(
					NumscipiedShiftSymmetryFloat-1.
				)+1.
			)

			#Check
			if self.NumscipyingStdFloat==0.:

				#mul
				self.NumscipiedSommersFloat*=self.NumscipyingSparseFloat*(
					1.-self.NumscipyingSparseFloat
				)

			#debug
			'''
			self.debug(
				[
					'NumscipiedShiftSymmetryFloat is '+str(NumscipiedShiftSymmetryFloat),
					('self.',self,
						[
							'NumscipyingSparseFloat',
							'NumscipiedVarianceFloat',
							'NumscipiedSommersFloat',
							'NumscipiedSymmetricsInt'
						]
					)
				]
			)
			'''

			#deviation
			self.NumscipiedStdFloat=np.sqrt(self.NumscipiedVarianceFloat)

			#covariance
			self.NumscipiedCovarianceFloat=self.NumscipyingColsInt*np.sum(
						np.array(
								filter(
										lambda __Float:
										__Float!=None,
										map(
											lambda __Tuple:
			(
				self.NumscipiedValueFloatsArray[__Tuple]-self.NumscipiedMeanFloat
			)*(
				self.NumscipiedValueFloatsArray[(__Tuple[1],__Tuple[0])]-self.NumscipiedMeanFloat
			) 
											if __Tuple[0]!=__Tuple[1] else None
											,NumscipiedLateralIndexIntsList
										)
									)
								)
							)/(
							float(
								self.NumscipiedSymmetricsInt-1
							)
						)	

			#debug
			'''
			self.debug(
				[
					'We compute the center',
					('self.',self,[
							'NumscipyingSwitchFloat',
							'NumscipyingMeanFloat'
						])
				]
			)
			'''

			#compute the center
			self.NumscipiedCenterFloat=(
				self.NumscipyingSwitchFloat*self.NumscipyingMeanFloat-(
					1.-self.NumscipyingSwitchFloat
				)*self.NumscipyingMeanFloat)/2.

			#set
			self.NumscipiedWidthFloat=2.*(1.+self.NumscipiedSommersFloat)
			self.NumscipiedHeightFloat=2.*(1.-self.NumscipiedSommersFloat)

			#Check
			if self.NumscipyingStdFloat>0.:

				#mul
				self.NumscipiedWidthFloat*=self.NumscipyingStdFloat
				self.NumscipiedHeightFloat*=self.NumscipyingStdFloat
			else:

				#sqrt
				self.NumscipiedStdSparseFloat=np.sqrt(
					self.NumscipyingSparseFloat*(
						1.-self.NumscipyingSparseFloat)
				)
			
				#mul
				self.NumscipiedWidthFloat*=self.NumscipiedStdSparseFloat
				self.NumscipiedHeightFloat*=self.NumscipiedStdSparseFloat





		#/#################/#
		# Get the eigenvalues
		#

		#Check
		if self.NumscipyingEigenvectorBool:
			
			pass

		#Check
		if self.NumscipyingEigenvalueBool:

			#debug
			'''
			self.debug(
				[
					'We compute the eigenvalues',
					('self.',self,[
							'NumscipiedValueFloatsArray'
						])
				]
			)
			'''

			#Check
			if self.NumscipyingSymmetryFloat==1.:

				#compute
				self.NumscipiedEigenvalueComplexesArray=np.linalg.eigvalsh(
					self.NumscipiedValueFloatsArray
				)
			else:

				#compute
				self.NumscipiedEigenvalueComplexesArray=np.linalg.eigvals(
					self.NumscipiedValueFloatsArray
				)

			#project
			self.NumscipiedRealEigenvalueFloatsArray=np.real(
				self.NumscipiedEigenvalueComplexesArray
			)
			self.NumscipiedImagEigenvalueFloatsArray=np.imag(
				self.NumscipiedEigenvalueComplexesArray
			)

			#debug
			'''
			self.debug(
				[
					'We have computed the eigenvalues',
					('self.',self,[
							'NumscipiedEigenvalueComplexesArray'
						])
				]
			)
			'''

		#/#################/#
		# Compute Global
		# 

		#Check
		if self.NumscipyingGlobalBool:

			#debug
			'''
			self.debug(
				[
					'We compute some global properties'
				]
			)
			'''

			#/###############/#
			# Compute basic statistics
			#

			#mean
			self.NumscipiedMeanGlobalFloatsArray=self.NumscipiedValueFloatsArray.mean(
				axis=0
			)

			#std
			self.NumscipiedStdGlobalFloatsArray=self.NumscipiedValueFloatsArray.std(
				axis=0
			)

			#/###############/#
			# Compute fourier amp and phase
			#

			#import
			from scipy.fftpack import fft

			#set
			self.NumscipiedSampleStepFloat=self.NumscipyingSampleFloatsArray[
				1
			]-self.NumscipyingSampleFloatsArray[
				0
			]

			#linspace
			self.NumscipiedFourierFrequencyFloatsArray=np.linspace(
				0.0, 
				1.0/(2.0*self.NumscipiedSampleStepFloat),
				self.NumscipyingColsInt/2
			)

			#fft
			self.NumscipiedFourierGlobalComplexesArray=fft(
				self.NumscipiedMeanGlobalFloatsArray
			)

			#amplitude
			self.NumscipiedFourierAmplitudeGlobalFloatsArray=(
					2.0/self.NumscipyingColsInt
				)* np.abs(
					self.NumscipiedFourierGlobalComplexesArray[
						0:self.NumscipyingColsInt/2
					]
				)

			#fourier
			self.NumscipiedFourierComplexesArray=np.array(
					map(
						lambda __NumscipiedValueFloatsArray:
						fft(
							__NumscipiedValueFloatsArray
						),
						self.NumscipiedValueFloatsArray
					)
				)

			#get
			NumscipiedHalfFourierComplexesArray=self.NumscipiedFourierComplexesArray[
						:,
						0:self.NumscipyingColsInt/2
					]

			#ampitude
			self.NumscipiedFourierAmplitudeFloatsArray=(
					2.0/float(self.NumscipyingColsInt)
				)* np.abs(
					NumscipiedHalfFourierComplexesArray
				)

			#phase
			self.NumscipiedFourierPhaseFloatsArray=np.array(
					map(
						lambda __NumscipiedHalfFourierComplexesArray:
						getArgumentVariable(
							__NumscipiedHalfFourierComplexesArray
						),
						NumscipiedHalfFourierComplexesArray
					)
				)

			#setCrossPhase
			self.setCrossPhase()

			#setExtremum
			self.setExtremum()

			#debug
			'''
			self.debug(
				[
					('self.',self,[
							'NumscipiedFourierMaxCrossPhaseFloatsArray'
						])
				]
			)
			'''

			#	(
			#		xrange(self.NumscipyingColsInt),
			#		[0]*
			#	)

			"""
			NumscipiedFourierCrossPhaseDict=map(
				lambda __NumscipiedFourierCrossPhaseTuple:
				(
					__NumscipiedFourierCrossPhaseTuple[0][0],
					__NumscipiedFourierCrossPhaseTuple[1]
				),
				self.NumscipiedFourierCrossPhaseTuplesList
			)
			"""

			"""
			self.NumscipiedFourierMaxCrossPhaseFloatsArray=np.array(
				map(
					lambda __NumscipiedFourierMaxAmplitudeIndexIntsArray,__IndexInt:
					self.NumscipiedFourierCrossPhaseTuplesList[
						__IndexInt,
						:
					],
					self.NumscipiedFourierMaxAmplitudeIndexIntsArray,
					xrange(len(self.NumscipiedFourierMaxAmplitudeIndexIntsArray))
				)
			)
			"""

			#/###############/#
			# Compute correlations
			#

			#import
			from scipy import signal

			#acf
			self.NumscipiedAutocorrelationGlobalFloatsArray=signal.correlate(
				self.NumscipiedMeanGlobalFloatsArray,
				self.NumscipiedMeanGlobalFloatsArray,
				mode="same"
			)

			#cut
			#self.NumscipiedAutocorrelationGlobalFloatsArray=self.NumscipiedAutocorrelationGlobalFloatsArray[
			#	self.NumscipiedAutocorrelationGlobalFloatsArray.size/2:
			#]

			#debug
			'''
			self.debug(
				[
					'We computed the correlations',
					('self.',self,[
							'NumscipiedAutocorrelationGlobalFloatsArray'
						])
				]
			)
			'''

			#/###############/#
			# Compute local maxima
			#

			"""
			#Maxima
			self.NumscipiedMaxGlobalIndexIntsArray=SYS.argmax(
				self.NumscipiedMeanGlobalFloatsArray
			)
			
			#debug
			self.debug(
				[
					'We found the local extrema',
					('self.',self,[
							'NumscipiedMaxGlobalIndexIntsArray'
						])
				]
			)

			#map
			NumscipiedMaxIndexIntsArray=map(
				lambda __SimulatedFloatsArray:
				SYS.argmax(__SimulatedFloatsArray),
				SimulatedFloatsArray
			)
			"""


		#/#################/#
		# Reset to None
		# 

		#set
		self.NumscipiedDiscreteStatRigidFunction=None
		self.NumscipiedContinuousStatRigidFunction=None
Пример #5
0
	def setStabilizedTotalPerturbationComplexesArray(self):

		#/###############/#
		# Prepare the complex pulsation perturbation
		# init StabilizedTotalPerturbationComplexesArray

		#alias
		PerturbationComplex = self.StabilizedPerturbationComplex

		#copy
		self.StabilizedTotalPerturbationComplexesArray =- np.array(
			self.StabilizedPerturbationWeightFloatsArray[:],
			dtype=complex
		)

		#/###############/#
		# Synaptic coupling
		#

		#exp
		#self.StabilizedSynapticPerturbationVariable=self.getSynapticPerturbationVariable(
		#		PerturbationComplex
		#	)

		#debug
		#self.debug(
		#	[
		#		('self.',self,[
		#				'StabilizedSynapticPerturbationVariable',
		#				'getSynapticPerturbationVariable',
		#				'StabilizedSynapticPerturbationMethodVariable'
		#			])
		#	]
		#)

		#Check
		if self.StabilizedSynapticPerturbationMethodVariable!=None:

			#set
			self.StabilizedSynapticPerturbationComplexesArray=self.StabilizedSynapticPerturbationMethodVariable(
					PerturbationComplex
				)

			#debug
			'''
			self.debug(
				[
					"Just before the synaptic set",
					('self.',self,[
						'StabilizedPerturbationComplex',
						'StabilizedTotalPerturbationComplexesArray',
						'StabilizedSynapticPerturbationMethodVariable'
					])
				]
			)
			'''

			#mul
			SYS.setMatrixArray(
				self.StabilizedTotalPerturbationComplexesArray,
				self.StabilizedSynapticPerturbationComplexesArray,
				np.ndarray.__mul__
			)

			#debug
			'''
			self.debug(
				[
					"Just after the synaptic set",
					('self.',self,[
						'StabilizedPerturbationComplex',
						'StabilizedTotalPerturbationComplexesArray',
						'StabilizedSynapticPerturbationComplexesArray'
					])
				]
			)	
			'''

		#debug
		'''
		self.debug(
			[
				'Ok we have mul the synaptic coupling',
				('self.',self,[
						'StabilizedTotalPerturbationComplexesArray'
					])
			]
		)
		'''

		#/###############/#
		# Neural response coupling
		#

		#exp
		self.StabilizedNeuralPerturbationComplexesArray=self.StabilizedNeuralPerturbationMethodVariable(
			PerturbationComplex
		)

		#debug
		'''
		self.debug(
			[
				"PerturbationComplex is "+str(PerturbationComplex),
				('self.',self,[
						'StabilizedNeuralPerturbationComplexesArray',
						'StabilizedNeuralPerturbationMethodVariable'
					])
			]
		)
		'''

		#mul
		SYS.setMatrixArray(
			self.StabilizedTotalPerturbationComplexesArray,
			self.StabilizedNeuralPerturbationComplexesArray,
			np.ndarray.__mul__
		)

		#debug
		'''
		self.debug(
			[
				'Ok we have mul the neural coupling',
				('self.',self,[
						'StabilizedTotalPerturbationComplexesArray',
						'StabilizedNeuralPerturbationComplexesArray'
					])
			]
		)
		'''
		
		#/###############/#
		# fill diagonal with also the leak identity term
		#

		#fill
		'''
		np.fill_diagonal(
			self.StabilizedTotalPerturbationComplexesArray,
			self.getLeakNeuralPerturbationComplex(
					PerturbationComplex
				)+np.diag(
					self.StabilizedTotalPerturbationComplexesArray
				)
		)
		'''

		#fill
		np.fill_diagonal(
			self.StabilizedTotalPerturbationComplexesArray,
			1.+np.diag(
					self.StabilizedTotalPerturbationComplexesArray
				)
		)

		#debug
		'''
Пример #6
0
	def stabilizeNetwork(self):

		#/###################/#
		# Determine the time constant structures
		# 

		#set
		if type(self.StabilizingConstantTimeVariable)==None.__class__:
			self.StabilizingConstantTimeVariable=map(
				lambda __DeriveStabilizer:
				__DeriveStabilizer.LifingConstantTimeFloat,
				self.TeamDict['Populations'].ManagementDict.values()
			)

		#debug
		'''
		self.debug(
			[
				('self.',self,[
						'StabilizingConstantTimeVariable'
					])
			]
		)
		'''

		#map
		map(
			lambda __TimeStr:
			SYS.setInitArray(
				self,
				'Stabilize',
				__TimeStr+'Time'
			),
			[
				'Constant',
				'Delay',
				'Decay',
				'Rise'
			]
		)

 
 		#/###################/#
		# Build the always fixed terms of the perturbation matrix
		# 

		#debug
		'''
		self.debug(
			[
				'We init the computations the StabilizedPerturbationWeightFloatsArray',
				('self.',self,[
						'StationarizingConstantTimeVariable',
						'StationarizedMeanWeightFloatsArray',
						'StabilizedConstantTimeVariable'
					])
			]
		)
		'''

		#set
		self.StabilizedPerturbationWeightFloatsArray=self.StationarizedMeanWeightFloatsArray[
			:
		]

		#mul
		SYS.setMatrixArray(
			self.StabilizedPerturbationWeightFloatsArray,
			self.StabilizedConstantTimeVariable,
			np.ndarray.__mul__
		)

		#debug
		'''
		self.debug(
			[
				'In the end',
				('self.',self,[
						'StabilizedPerturbationWeightFloatsArray'
					])
			]
		)
		'''

		#/###################/#
		# Determine which function to get for the synaptic computation
		#

		#debug
		'''
		self.debug(
			[
				"We determine the type of Synaptic function",
				('self.',self,[
						'StabilizedRiseTimeVariable',
						'StabilizedDecayTimeVariable',
						'StabilizedDelayTimeVariable'
					])
			]
		)
		'''

		#Check
		if SYS.getIsNullBool(
			self.StabilizedRiseTimeVariable
		):

			#Check
			if SYS.getIsNullBool(
				self.StabilizedDecayTimeVariable
			):
				
				#Check
				if SYS.getIsNullBool(
					self.StabilizedDelayTimeVariable
				):

					#set
					self.StabilizedSynapticPerturbationMethodVariable=lambda __PerturbationComplex:1.

				else:

					#set
					self.StabilizedSynapticPerturbationMethodVariable=self.getSynapticDelayPerturbationVariable

			else:

				#set
				self.StabilizedSynapticPerturbationMethodVariable=self.getSynapticDecayPerturbationVariable

		else:

			#set
			self.StabilizedSynapticPerturbationMethodVariable=self.getSynapticRisePerturbationVariable

		#/###################/#
		# Prepare the combinations to consider
		#

		#import 
		import itertools

		#list
		self.StabilizedIndexIntsTuplesList=list(
			itertools.product(
				xrange(self.StationarizingUnitsInt),
				xrange(self.StationarizingUnitsInt)
			)
		)

		#debug
		'''
		self.debug(
			[
				'We set a one root get',
				('self.',self,[
						'StabilizedIndexIntsTuplesList'
					])	
			]
		)
		self.getGlobalPerturbationRootFloatsTuple(
							(0.1,2.*np.pi*1.)
						)
		'''

		#import
		from numpy import linalg

		#set
		self.StabilizedDeterminantFunctionVariable=linalg.det

		#/################/#
		# Look for a rate instability
		#

		#debug
		'''
		self.debug(
			[
				"Ok first we look for a rate instability"
			]
		)
		'''

		#set
		self.StabilizedLifersVariable = self.TeamDict['Populations'].ManagementDict.values()

		#map
		self.StabilizedMeanPerturbationNullFloatsList=map(
			lambda __DeriveStabilizer:
			__DeriveStabilizer.lif(
				_ComputeStationaryBool=False,
				_PerturbationLambdaVariable=0.,
				_PerturbationMethodStr='Brunel',
				_ComputeNoisePerturbationBool=False
			).LifedPerturbationMeanComplexVariable,
			self.StabilizedLifersVariable
		) if self.StationarizingInteractionStr=="Spike" else [1.]*self.StationarizingUnitsInt

		#debug
		'''
		self.debug(
			[
				('self.',self,[
						'StabilizedMeanPerturbationNullFloatsList'
					])
			]
		)
		'''
			
		#set
		self.StabilizedNeuralPerturbationComplexesArrayesArray=np.zeros(
			self.StationarizingUnitsInt,
			dtype=complex
		)
					
		#Check
		if self.StabilizingComputeBool:

			#get
			self.StabilizedNeuralPerturbationMethodVariable=getattr(
				self,
				'getNeuralNullPerturbationVariable'
			)

			#get
			StabilizedRateDetermintantFloatsTuple=self.getGlobalPerturbationRootFloatsTuple(
				(0.,0.)
			)

			#get
			self.StabilizedIsStableBool=StabilizedRateDetermintantFloatsTuple[0]>0.
			self.StabilizedRateInstabilityBool=not self.StabilizedIsStableBool

			#debug
			'''
			self.debug(
				[
					'Is it rate instable ?',
					"StabilizedRateDetermintantFloatsTuple is "+str(StabilizedRateDetermintantFloatsTuple),
					('self.',self,[
							'StabilizedTotalPerturbationComplexesArray',
							'StabilizedIsStableBool'
						])
				]
			)
			'''

			#/################/#
			# Look for a hopf instability
			#

			#Check
			if self.StabilizedIsStableBool:

				#import 
				import scipy.optimize


				#get
				self.StabilizedNeuralPerturbationMethodVariable=getattr(
					self,
					'get'+self.StationarizingInteractionStr+'NeuralPerturbationVariable'
				)

				#debug
				'''
				self.debug(
					[
						"There is no rate instability so we do a Hopf scan analysis",
						('self.',self,['StabilizingScanFrequencyVariable'])
					]
				)
				'''

				#type
				StabilizedScanType=type(self.StabilizingScanFrequencyVariable)

				#Check
				if StabilizedScanType==None.__class__:

					#Check
					StabilizedFirstList=list(np.logspace(0,3,10))
					StabilizedSecondList=StabilizedFirstList[:]
					StabilizedSecondList.reverse()
					StabilizedSecondList=map(lambda __Variable:-__Variable,StabilizedSecondList)

					#set
					self.StabilizedStabilityScanFrequencyFloatsArray=np.array(
						StabilizedSecondList+StabilizedFirstList
					)

				elif StabilizedScanType in [np.float64,float]:

					#Check
					self.StabilizedStabilityScanFrequencyFloatsArray=np.array(
						[self.StabilizingScanFrequencyVariable]
					)

				else:

					#Check
					self.StabilizedStabilityScanFrequencyFloatsArray=np.array(
						self.StabilizingScanFrequencyVariable
					)

				#debug
				'''
				self.debug(
					[
						('self.',self,['StabilizedStabilityScanFrequencyFloatsArray'])
					]
				)
				'''


				#check
				'''
				if len(self.StabilizedStabilityScanFrequencyFloatsArray)==1:

					#debug
					self.debug(
						[
							"We just debug here"
						]
					)

					#try just the first
					self.getGlobalPerturbationRootFloatsTuple(
						(-0.1,2.*np.pi*self.StabilizedStabilityScanFrequencyFloatsArray[0])
					)
				'''

				#debug
				'''
				self.debug(
					[
						"Ok now we gradient"
					]
				)
				'''

				#loop
				for __ScanFrequencyFloat in self.StabilizedStabilityScanFrequencyFloatsArray:
				#for __ScanFrequencyFloat in [100.]:

					#debug
					'''
					self.debug(
						[
							'We try to find an instability around '+str(__ScanFrequencyFloat)+'Hz'
						]
					)
					'''

					#Get the solve of the ScipyOptimizeRoot
					StabilizedOptimizeRoot=scipy.optimize.root(
							self.getGlobalPerturbationRootFloatsTuple,
							(-0.1,2.*np.pi*__ScanFrequencyFloat),
							#method='lm',
							#tol=0.001
							options={
										#'maxiter':1000,
										#'ftol':0.001,
										#'direc':np.array([-0.1,0.1])
									},
						)

					#set
					StabilizedErrorFloat=np.sum(StabilizedOptimizeRoot.fun**2)

					#debug
					'''
					self.debug(
						[
							'StabilizedOptimizeRoot is ',
							str(StabilizedOptimizeRoot),
							"StabilizedErrorFloat is ",
							str(StabilizedErrorFloat)
						]
					)
					'''

					#set
					self.StabilizedOptimizeRoot=StabilizedOptimizeRoot

					#Check
					if StabilizedOptimizeRoot.success and StabilizedErrorFloat<0.001:

						#debug
						'''
						self.debug(
							[
								"It is a success",
								('self.',self,[
										'StabilizedBiggestLambdaFloatsTuple',
									]),
								"StabilizedOptimizeRoot.x is "+str(StabilizedOptimizeRoot.x)
							]
						)
						'''

						#Check
						if StabilizedOptimizeRoot.x[0]>0.:

							#set
							self.StabilizedIsStableBool=False

							#set
							self.StabilizedInstabilityStr="Hopf"

							#set
							self.StabilizedInstabilityLambdaFloatsTuple=tuple(
								StabilizedOptimizeRoot.x
							)

							self.StabilizedBiggestLambdaFloatsTuple=self.StabilizedInstabilityLambdaFloatsTuple

							#set
							self.StabilizedInstabilityFrequencyFloat=self.StabilizedInstabilityLambdaFloatsTuple[1]/(
								2.*np.pi
							)

							#break
							break

						elif len(
							self.StabilizedBiggestLambdaFloatsTuple
						)==0 or StabilizedOptimizeRoot.x[0]>self.StabilizedBiggestLambdaFloatsTuple[0]:

							#Check
							self.StabilizedBiggestLambdaFloatsTuple=tuple(
								StabilizedOptimizeRoot.x
							)