示例#1
0
文件: core.py 项目: mdurante1/scLVM
	def fitFactor(self,idx=None,X0=None,k=1,standardize=False, use_ard=False, interaction=True, initMethod='fast'):
		"""
		Args:
			idx:			index of the genes involved
							(e.g., for capturing cell cycle, index of cell cycle genes)
			X0:			known factor(s) on which to condition on when fitting the GPLVM
			k:				number of latent factors
			standardize:	if True, rescale gene expression by std prior to fitting GPLVM
							(data are always mean-centered)
			use_ard:		use automatic relevance detection (switch off unimportant factors)
		Returns:
			X:				hidden variable
			Kconf:			similarity matrix based on the confounding effect (XX.T)
			varGPLVM:		variance contributions of latent factors and residual biological noise
		"""
		assert idx!=None, 'scLVM:: specify idx'
		if use_ard==True and  k<2:
			warnings.formatwarning = warning_on_one_line
			warnings.warn('when using ARD consider choosing k>1')
		if X0!=None:
			assert use_ard == False, 'scLVM:: when fitting conditional GPLVM, use_ard has to be False'		

		Yconf = self.Y[:,idx]
		Yconf-= Yconf.mean(0)
		Kint = None
		if X0==None:
			#use PANAMA
			# prepare data
			# fit gplvm
			panama = PANAMA.PANAMA(Y=Yconf,use_Kpop=False,standardize=standardize)
			panama.train(rank=k,LinearARD=use_ard)			
			X	 = panama.get_Xpanama()
			Kconf = panama.get_Kpanama()
			var = panama.get_varianceComps()
			if use_ard==False:
				varGPLVM = {'K':var['Kpanama'],'noise':var['noise']}
			else:
				varGPLVM = {'X_ARD':var['LinearARD'],'noise':var['noise']}
		else:
			# use gpCLVM
			gp = gpCLVM(Y=Yconf,X0=X0,k=k,standardize=standardize,interaction=interaction)
			params0 = gp.initParams(method=initMethod)
			conv = gp.optimize(params0)
			X = gp.getX()
			Kconf = gp.getK()
			if interaction==True:
				Kint = gp.getKi()
			varGPLVM = gp.getVarianceComps()
		return X,Kconf,Kint,varGPLVM
示例#2
0
文件: core.py 项目: xuxaxy/scLVM
	def fitFactor(self,idx=None,X0=None,k=1,standardize=False, use_ard=False, interaction=True, initMethod='fast'):
		"""
		Args:
			idx:			index of the genes involved
							(e.g., for capturing cell cycle, index of cell cycle genes)
			X0:			known factor(s) on which to condition on when fitting the GPLVM
			k:				number of latent factors
			standardize:	if True, rescale gene expression by std prior to fitting GPLVM
							(data are always mean-centered)
			use_ard:		use automatic relevance detection (switch off unimportant factors)
		Returns:
			X:				hidden variable
			Kconf:			similarity matrix based on the confounding effect (XX.T)
			varGPLVM:		variance contributions of latent factors and residual biological noise
		"""
		assert idx!=None, 'scLVM:: specify idx'
		if use_ard==True and  k<2:
			warnings.formatwarning = warning_on_one_line
			warnings.warn('when using ARD consider choosing k>1')
		if X0!=None:
			assert use_ard == False, 'scLVM:: when fitting conditional GPLVM, use_ard has to be False'		

		Yconf = self.Y[:,idx]
		Yconf-= Yconf.mean(0)
		Kint = None
		if X0==None:
			#use PANAMA
			# prepare data
			# fit gplvm
			panama = PANAMA.PANAMA(Y=Yconf,use_Kpop=False,standardize=standardize)
			panama.train(rank=k,LinearARD=use_ard)			
			X	 = panama.get_Xpanama()
			Kconf = panama.get_Kpanama()
			var = panama.get_varianceComps()
			if use_ard==False:
				varGPLVM = {'K':var['Kpanama'],'noise':var['noise']}
			else:
				varGPLVM = {'X_ARD':var['LinearARD'],'noise':var['noise']}
		else:
			# use gpCLVM
			gp = gpCLVM(Y=Yconf,X0=X0,k=k,standardize=standardize,interaction=interaction)
			params0 = gp.initParams(method=initMethod)
			conv = gp.optimize(params0)
			X = gp.getX()
			Kconf = gp.getK()
			if interaction==True:
				Kint = gp.getKi()
			varGPLVM = gp.getVarianceComps()
		return X,Kconf,Kint,varGPLVM
示例#3
0
	pdb.set_trace()

	# initialization method
	init_method = 'null' #['fast','regressOut','random','null']
	Ycc = Y_X0+1e-2*SP.randn(N,G)	# cell cycle contributions for regressOut
	X_init = X_true+1e-2*SP.randn(N,k) # initial Xs for regressOut
	varXX = 0.3 # variance explained by the normalized XX.T
	varX0X0 = 0.3 # variance explained by known factor
	nois = 0.7 # variance explained by noise

	if 1:
		"""
		gp with interaction term
		"""
		gp = gpCLVM(Y=Y,X0=X0,k=k)
		params0 = gp.initParams(method=init_method,Ycc=Ycc,X=X_init,varXX=varXX,varX0X0=varX0X0,nois=nois)
		# gp.fix_a(flag=True)
		conv = gp.optimize(params0)

		X = gp.getX() # inferred hidden factor
		K = gp.getK() # matrix from inferred inferred factor
		Ki = gp.getKi() # interaction matrix
		var = gp.getVarianceComps() # variance components

		if 1:
			""" plot """
			PL.subplot(2,2,1)
			PL.plot(X_true.ravel(),X.ravel(),'.k')
			PL.xlabel('true X')
			PL.ylabel('fitted X')