예제 #1
0
	def do_lif(self):
		
		#/##################/#
		# Get the swig function
		#

		#Check
		if self.LifedSwigVariable==None:

			#import
			import sys
			from os.path import dirname
			sys.path.append(dirname(__file__))
			import CIntegrateAndFireTransferFunction

			#get
			self.LifedSwigVariable=CIntegrateAndFireTransferFunction.CIntegrateAndFireTransferFunctionClass()

		#debug
		'''
		self.debug(
			[
				'We have getted dthe Lif swig variable',
				('self.',self,[
						'LifedSwigVariable'
					])
			]
		)
		'''

		#/##################/#
		# Look if the stationary point was already computed
		#

		#debug
		'''
		self.debug(
			[
				"The stationary point was computed ?",
				('self.',self,['LifingComputeStationaryBool'])
			]
		)
		'''

		#set
		self.LifedSwigVariable.IntDict['ComputeStationary']=int(
			self.LifingComputeStationaryBool
		)

		#Check
		if self.LifingComputeStationaryBool:

			#debug
			'''
			self.debug(
				[
					'We lif compute stationary here',
					('self.',self,[
							'LifingConstantTimeFloat',
							'LifingRefractoryPeriodFloat',
							'LifingStationaryRateFloat',
							'LifingRestFloat',
							'LifingStationaryExternalCurrentNoiseFloat',
							'LifingResetFloat',
							'LifingThresholdFloat'
						])
				]
			)
			'''

			#Set inside the Swig
			self.LifedSwigVariable.setDicts(
				*getCArgsFromDict(
					getFilterDictByType(**{
							'ConstantTime':self.LifingConstantTimeFloat,
							'RefractoryPeriod':self.LifingRefractoryPeriodFloat,
							'VoltageReset':self.LifingResetFloat, 
							'VoltageThreshold':self.LifingThresholdFloat
						}
					)
				)
			)

			#Check
			if self.LifingMeanToRateBool:

				#set
				self.LifedStationaryTotalFloat = self.LifingRestFloat+self.LifingStationaryExternalCurrentMeanFloat

				#Set inside the Swig
				self.LifedSwigVariable.setDicts(
					*getCArgsFromDict(
						getFilterDictByType(**{
								'StationaryCurrent':self.LifedStationaryTotalFloat,
								'VoltageNoise':self.LifingStationaryExternalCurrentNoiseFloat
							}
						)
					)
				)

				#Compute the IntegralLowerBound and the IntegralUpperBound
				self.LifedSwigVariable.computeIntegralLowerBound();
				self.LifedSwigVariable.computeIntegralUpperBound();
		    	
				#set
				self.LifedStationaryRateFloat=self.LifedSwigVariable.getLifStationaryRate();

				#debug
				'''
				self.debug(
					[
						"This is rate from current and we have",
						('self.',self,[
								'LifingConstantTimeFloat',
								'LifingRefractoryPeriodFloat',
								'LifingRestFloat',
								'LifingResetFloat',
								'LifingThresholdFloat',
								'LifingStationaryExternalCurrentNoiseFloat',
								'LifedStationaryTotalFloat',
								'LifedStationaryRateFloat'
							])
					]
				)
				'''
				
			#Check
			else:

				#debug
				'''
				self.debug(
					[
						"This is current from rate",
						('self',self,[
								'LifingStationaryRateFloat'
							])
					]
				)
				'''

				#temp
				LifedTempRateFloat=self.LifingStationaryRateFloat

				#set
				if self.LifedInverseStationaryFunctionVariable == None:

					#get
					self.LifedInverseStationaryFunctionVariable=SYS.getInverseFunction(
						lambda __StationaryCurrentFloat:
						self.mapSetAttr(
								{
									'LifingRestFloat':__StationaryCurrentFloat,
									'LifingStationaryRateFloat':None,
									'LifingMeanToRateBool':True,
									'LifingComputeStationaryBool':True
								}
							).lif(
							).LifedStationaryRateFloat
						)
				
				#set
				self.LifedStationaryTotalFloat = self.LifedInverseStationaryFunctionVariable(
					LifedTempRateFloat
				)

				#set
				self.LifingStationaryRateFloat = LifedTempRateFloat

				#set
				self.LifingMeanToRateBool=False
				
				#set
				self.LifedStationaryRateFloat = None

				#Set inside the Swig
				self.LifedSwigVariable.setDicts(
					*getCArgsFromDict(
						getFilterDictByType(**{
								'StationaryCurrent':self.LifedStationaryTotalFloat,
								'VoltageNoise':self.LifingStationaryExternalCurrentNoiseFloat
							}
						)
					)
				)

				#debug
				'''
				self.debug(
					[
						"In the end of rateToCurrent",
						('self.',self,[
								'LifingStationaryRateFloat',
								'LifedStationaryTotalFloat'
							])
					]
				)
				'''
				
			#set
			self.LifingComputeStationaryBool=False
			self.LifedSwigVariable.IntDict['ComputeStationary']=0

		#debug
		'''
		self.debug(
			[
				"In the end",
				('self.',self,[
					'LifingMeanToRateBool',
					'LifingRestFloat',
					'LifingStationaryRateFloat',
					'LifedStationaryTotalFloat',
					'LifedStationaryRateFloat',
					'LifingComputePerturbationBool'
				])
			]
		)
		'''

		#Check
		if self.LifingComputePerturbationBool:

			#/##################/#
			# Compute a perturbaton
			#

			#debug
			'''
			self.debug(
				[
					"We compute a perturbation",
					('self.',self,[
							'LifingPerturbationFrequencyFloat',
							'LifingPerturbationLambdaVariable'
						])
				]
			)
			'''

			#/##################/#
			# Get the method
			#

			#Check
			if self.LifingPerturbationMethodStr == "Rate":

				#alias
				self.LifedPerturbationMethodVariable = self.setRatePerturbationRate

				#Check
				if self.LifedPerturbationMeanNullFloat==0.:

					#set
					self.LifedPerturbationMeanNullFloat=self.LifedSwigVariable.getLifPerturbationNullRate(
						'StationaryCurrent'
					)

			else:

				#get
				self.LifedPerturbationMethodVariable = getattr(
					self.LifedSwigVariable,
					'set'+self.LifingPerturbationMethodStr+'LifPerturbationRate'
				)


			#/#################/#
			# Check if it is real or complex
			#

			#Choose
			if self.LifingPerturbationLambdaVariable!=None:

				#set
				LifedPerturbationPreVariable=self.LifingPerturbationLambdaVariable

			else:

				#import
				import numpy as np

				#set
				LifedPerturbationPreVariable=2.*np.pi*self.LifingPerturbationFrequencyFloat*1j

			#/#################/#
			# Check if it null perturbation or complex
			#

			#debug
			'''
			self.debug(
				[
					'LifedPerturbationPreVariable is ',str(
						LifedPerturbationPreVariable)
				]
			)
			'''

			#unpack
			if LifedPerturbationPreVariable==0.:

				#debug
				'''
				self.debug(
					[
						"It is a get of real null perturbation"
					]
				)
				'''

				#get
				self.LifedPerturbationMeanComplexVariable=self.LifedSwigVariable.getLifPerturbationNullRate(
						'StationaryCurrent'
					)

				#set
				self.LifedPerturbationMeanNullFloat=self.LifedPerturbationMeanComplexVariable

				#Check
				if self.LifingComputeNoisePerturbationBool:

					#get
					self.LifedPerturbationNoiseComplexVariable=self.LifedSwigVariable.getLifPerturbationNullRate(
							'VoltageNoise'
						)

					#set
					self.LifedPerturbationNoiseNullFloat=self.LifedPerturbationMeanComplexVariable


			else:

				#debug
				'''
				self.debug(
					[
						"It is a complex computation",
						"LifedPerturbationPreVariable is "+str(
							LifedPerturbationPreVariable
						),
						('self.',self,[
									'LifingConstantTimeFloat',
									'LifingRefractoryPeriodFloat',
									'LifingRestFloat',
									'LifingStationaryExternalCurrentMeanFloat',
									'LifingStationaryExternalCurrentNoiseFloat',
									'LifingResetFloat',
									'LifingThresholdFloat',
									'LifedStationaryTotalFloat',
									'LifedStationaryRateFloat',
									'LifingMeanToRateBool'
								])
					]
				)
				'''

				#get
				if self.LifingPerturbationMethodStr != "Rate":
					
					#set
					self.LifedSwigVariable.IntDict['ComputeNoise']=int(
						self.LifingComputeNoisePerturbationBool
					)


				#debug
				'''
				self.debug(
					[
						"Ok we call",
						"LifedPerturbationPreVariable is "+str(LifedPerturbationPreVariable),
						('self.',self,[
								'LifedPerturbationMethodVariable'
							])
					]
				)
				'''
				
				#call
				self.LifedPerturbationMethodVariable(
					LifedPerturbationPreVariable
				)

				#get
				if self.LifingPerturbationMethodStr != "Rate":
					
					#get
					self.LifedPerturbationMeanComplexVariable=self.LifedSwigVariable.ComplexDict["PerturbationMean"]

					#Check			
					if self.LifingComputeNoisePerturbationBool:
						self.LifedPerturbationNoiseComplexVariable=self.LifedSwigVariable.ComplexDict["PerturbationNoise"]

				#debug
				'''
#ImportModules
import ShareYourSystem as SYS
import numpy as np

#get
InverseFunction=SYS.getInverseFunction(np.tanh)

#print
print(
	np.tanh(InverseFunction(0.1)),
	np.tanh(InverseFunction(1.)),
	np.tanh(InverseFunction(2.))
)