Ejemplo n.º 1
0
	def normal(self, mean, covariance, x=None):
		"""
		sample from a normal distribution or specify `x` for the likelihood of
		that point under the model.
		
		Parameters
		----------
		mean : matrix
			mean of a multivariate normal distribution written as a nx1 matrix
		covariance: matrix
			covariance matrix of a multivariate normal distribution
		x : matrix (None)
			point at which to evaluate the normal distribution
		
		Notes
		----------
		If you specify x then this function returns the likelihood 
		p(x|mean,covariance). If you leave x unspecified then this will return
		a sample from the normal distribution specified by the mean and
		covariance.
		"""
		if x is not None:
			# TODO what's the normalising constant of a multivariate G?
			const = 1.0 
			return const * pb.exp(-0.5*(x-mean).T * covariance.I * (x-mean))
		else:
			return pb.multivariate_normal(mean.A.flatten(),covariance,[1]).T
#Define sensor geometry
sensor_center=pb.matrix([[0],[0]])
sensor_width=0.9**2 
sensor_kernel=basis(sensor_center,sensor_width,dimension)

#Define sigmoidal activation function and inverse synaptic time constant
fmax=10
v0=2
varsigma=0.8
act_fun=ActivationFunction(v0,fmax,varsigma)
#inverse synaptic time constant
zeta=100
#define field initialasation and number of iterations for estimation
mean=[0]*len(Phi)
P0=10*pb.eye(len(mean))
x0=pb.matrix(pb.multivariate_normal(mean,P0,[1])).T
number_of_iterations=10
#ignore first 100 observations allowing the model's initial transients to die out
First_n_observations=100

#populate the model
NF_model=NF(NF_Connectivity_kernel,sensor_kernel,obs_locns,observation_locs_mm,gamma,gamma_weight,Sigma_varepsilon,act_fun,zeta,Ts,field_space,spacestep)
IDE_model=IDE(IDE_Connectivity_kernel,IDE_field,sensor_kernel,obs_locns,gamma,gamma_weight,Sigma_varepsilon,act_fun,x0,P0,zeta,Ts,field_space,spacestep)
#generate the Neural Field model
NF_model.gen_ssmodel()
V,Y=NF_model.simulate(T)
#generate the reduced model (state space model)
IDE_model.gen_ssmodel()
#estimate the states, the connectivity kernel parameters and the synaptic dynamics
ps_estimate=para_state_estimation(IDE_model)
ps_estimate.itrerative_state_parameter_estimation(Y[First_n_observations:],number_of_iterations)
sensor_kernel=basis(sensor_center,sensor_width,dimension)


#Define sigmoidal activation function and inverse synaptic time constant
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fmax=1
v0=1.8
varsigma=0.56
act_fun=ActivationFunction.ActivationFunction(v0,fmax,varsigma)
#inverse synaptic time constant
zeta=100
#define field initialasation and number of iterations for estimation
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mean=[0]*len(Phi)
P0=10*pb.eye(len(mean))
x0=pb.multivariate_normal(mean,P0,[1]).T
number_of_iterations=10
#ignore first 100 observations allowing the model's initial transients to die out
First_n_observations=100
#populate the model
NF_model=NF(NF_Connectivity_kernel,sensor_kernel,obs_locns,gamma,gamma_weight,Sigma_varepsilon,act_fun,zeta,Ts,field_space_x_y,spacestep)
IDE_model=IDE(IDE_Connectivity_kernel,field,sensor_kernel,obs_locns,gamma,gamma_weight,Sigma_varepsilon,act_fun,x0,P0,zeta,Ts,field_space_x_y,spacestep)
#generate Neural Field model
NF_model.gen_ssmodel()
V,Y=NF_model.simulate(T)
#generate the reduced model (state space model)
IDE_model.gen_ssmodel()
#estimate the states, the connectivity kernel parameters and the synaptic dynamics
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ps_estimate=para_state_estimation(IDE_model)
ps_estimate.itrerative_state_parameter_estimation(Y[First_n_observations:],number_of_iterations)