コード例 #1
0
ファイル: AR_tests.py プロジェクト: smoitra87/ssystem
	def test_parse_modelspace(self) :
		""" Test the _parse_modelspace command """
		self.ss = Chou2006()
		self.ar = ARSolver(self.ss)
		modelspace = self.ss.constraint.modelspace


		# Test the alphas
		modelspace.alpha['defaultLowerBound'] = 0.5
		modelspace.alpha['defaultUpperBound'] = 30.0

		self.ar._parse_modelspace()
		assert_f =  lambda t : eq_(t,(0.5,30.0))
		map(assert_f,self.ar.modelspace['alpha'])

		modelspace.alpha['alpha_1'] = 'nonZero'
		modelspace.alpha['alpha_3'] = (1.0,20.0)
		self.ar._parse_modelspace()
		eq_(self.ar.modelspace['alpha'][0],'nonZero')
		eq_(self.ar.modelspace['alpha'][1],(0.5,30.0))
		eq_(self.ar.modelspace['alpha'][2],(1.0,20.0))
		eq_(self.ar.modelspace['alpha'][3],(0.5,30.0))

		# Test the betas
		modelspace.beta['defaultLowerBound'] = 0.5
		modelspace.beta['defaultUpperBound'] = 30.0

		self.ar._parse_modelspace()
		assert_f =  lambda t : eq_(t,(0.5,30.0))
		map(assert_f,self.ar.modelspace['beta'])

		modelspace.beta['beta_1'] = 'nonZero'
		modelspace.beta['beta_3'] = 'nonZero'
		self.ar._parse_modelspace()
		eq_(self.ar.modelspace['beta'][0],'nonZero')
		eq_(self.ar.modelspace['beta'][1],(0.5,30.0))
		eq_(self.ar.modelspace['beta'][2],'nonZero')
		eq_(self.ar.modelspace['beta'][3],(0.5,30.0))
			
		# Test g
		modelspace.g['defaultLowerBound'] = 0.5
		modelspace.g['defaultUpperBound'] = 30.0
		self.ar._parse_modelspace()
		assert_f =  lambda t : eq_(t,(0.5,30.0))
		assert_f2 = lambda t : map(assert_f,t)
		map(assert_f2,self.ar.modelspace['g'])

		modelspace.g['g_1_1'] = 'nonZero'
		modelspace.g['g_3_2'] = (0.33,20.0)
		self.ar._parse_modelspace()
		eq_(self.ar.modelspace['g'][0][0],'nonZero')
		eq_(self.ar.modelspace['g'][1][0],(0.5,30.0))
		eq_(self.ar.modelspace['g'][2][1],(0.33,20.0))
		eq_(self.ar.modelspace['g'][3][1],(0.5,30.0))
コード例 #2
0
ファイル: AR_tests.py プロジェクト: smoitra87/ssystem
	def test_partialinfo1(self) :
		""" Run AR (slow) on eqn 1 under partial info """
		ss = Chou2006()
		ss.exptype = "partialinfo"
		ss.equations = [1]
		initsol = ss.constraint.initsol
		initsol.beta['beta_1'] = 20.0
		initsol.h['h_1_1'] = 0.1
		ar = ARSolver(ss)
		eq_(ar.initsol['beta'][0],20.0)
		eq_(ar.initsol['h'][0][0],0.1)
コード例 #3
0
ファイル: ALR_tests.py プロジェクト: smoitra87/ssystem
 def test_noinfo2(self):
     """ Run ALR eqn 1 under noinfo with tol 10e-7 """
     ss = Chou2006()
     ss.exptype = "noinfo"
     ss.equations = [1]
     ar = ALRSolver(ss)
     ar.solve(l1penalty=0.0, maxiter=10000, tol=10e-7)
     assert len(ar.all_exp_art) == 1
     assert len(ar.all_exp_art[0]['eqns']) == 1
     art = ar.all_exp_art[0]['eqns'][0]
     params = art.params[-1]
     assert params is None
コード例 #4
0
ファイル: AR_tests.py プロジェクト: smoitra87/ssystem
	def test_parse_initsol(self) :
		""" Test the _parse_initsol command """
		self.ss = Chou2006()
		self.ar = ARSolver(self.ss)
		initsol = self.ss.constraint.initsol

		# Test the alphas
		initsol.alpha['defaultInitialValue'] = 0.5
		self.ar._parse_initsol()
		assert_f =  lambda t : assert_almost_equal(t,0.5,places=2)
		map(assert_f,self.ar.initsol['alpha'])


		initsol.alpha['alpha_1'] = 5.0
		initsol.alpha['alpha_3'] = 20.0
		self.ar._parse_initsol()
		assert_almost_equal(self.ar.initsol['alpha'][0],5.0,places=2)
		assert_almost_equal(self.ar.initsol['alpha'][1],0.5,places=2)
		assert_almost_equal(self.ar.initsol['alpha'][2],20.0,places=2)
		assert_almost_equal(self.ar.initsol['alpha'][3],0.5,places=2)

		# Test the betas
		initsol.beta['defaultInitialValue'] = 0.5
		self.ar._parse_initsol()
		assert_f =  lambda t : assert_almost_equal(t,0.5,places=2)
		map(assert_f,self.ar.initsol['beta'])


		initsol.beta['beta_1'] = 5.0
		initsol.beta['beta_3'] = 20.0
		self.ar._parse_initsol()
		assert_almost_equal(self.ar.initsol['beta'][0],5.0,places=2)
		assert_almost_equal(self.ar.initsol['beta'][1],0.5,places=2)
		assert_almost_equal(self.ar.initsol['beta'][2],20.0,places=2)
		assert_almost_equal(self.ar.initsol['beta'][3],0.5,places=2)
	
		# Test g
		initsol.g['defaultInitialValue'] = 0.5
		self.ar._parse_initsol()
		assert_f =  lambda t : assert_almost_equal(t,0.5,places=2)
		map(assert_f,self.ar.initsol['g'].ravel())

		initsol.g['g_1_1'] = 0.45
		initsol.g['g_3_2'] = 0.33
		self.ar._parse_initsol()
		assert_almost_equal(self.ar.initsol['g'][0][0],0.45,places=2)
		assert_almost_equal(self.ar.initsol['g'][2][1],0.33,places=2)
		eq_(self.ar.initsol['g'][1][0],0.5)
		eq_(self.ar.initsol['g'][3][1],0.5)
コード例 #5
0
ファイル: AR_tests.py プロジェクト: smoitra87/ssystem
	def test_noinfo2(self) : 
		""" Run AR all equations under no info """
		ss = Chou2006()
		ss.exptype = "noinfo"
		ss.equations = [1,2,3,4]
		ar = ARSolver(ss)
		ar.solve(maxiter=10000,tol=10e-7)
		eq_(len(ar.all_exp_art),1)
		print ar.all_exp_art[0]['eqns']
		eq_(len(ar.all_exp_art[0]['eqns']),4)
		art = ar.all_exp_art[0]['eqns'][0]		
		sol = {'alpha': 12,
			 'beta': 10,
			 'g': np.array([ 0,0,-0.8,0]),
			 'h': np.array([ 0.5,0,0,0])}
コード例 #6
0
ファイル: AR_tests.py プロジェクト: smoitra87/ssystem
	def test_noinfo1(self) : 
		""" Run AR eqn 1 under no info """
		ss = Chou2006()
		ss.exptype = "noinfo"
		ss.equations = [1]
		ar = ARSolver(ss)
		ar.solve(maxiter=10000,tol=10e-7)
		assert len(ar.all_exp_art) == 1
		assert len(ar.all_exp_art[0]['eqns']) == 1
		art = ar.all_exp_art[0]['eqns'][0]		
		sol = {'alpha': 12,
			 'beta': 10,
			 'g': np.array([ 0,0,-0.8,0]),
			 'h': np.array([ 0.5,0,0,0])}
		params = art.params[-1]
		assert np.allclose(sol['alpha'],params['alpha'],atol=0.5)	
		assert np.allclose(sol['beta'],params['beta'],atol=0.5)	
		assert np.allclose(sol['g'],params['g'],atol=0.2)	
		assert np.allclose(sol['h'],params['h'],atol=0.2)	
コード例 #7
0
ファイル: AR_tests.py プロジェクト: smoitra87/ssystem
	def test_fullinfo2(self) : 
		""" RUN AR (slow)  eqn 2 under full info """	
		ss = Chou2006()
		ss.exptype = "fullinfo"
		ss.equations = [2]
		ar = ARSolver(ss)
		ar.solve(maxiter=10000,tol=10e-6)
		assert len(ar.all_exp_art) == 1
		assert len(ar.all_exp_art[0]['eqns']) == 1
		art = ar.all_exp_art[0]['eqns'][0]		
		sol = {'alpha': 7.8801765469678156,
			 'beta': 2.8893110127454427,
			 'g': np.array([ 0.51119746]),
			 'h': np.array([ 0.76771705])}
		params = art.params[-1]
		assert np.allclose(sol['alpha'],params['alpha'],atol=1)	
		assert np.allclose(sol['beta'],params['beta'],atol=1.5)	
		assert np.allclose(sol['g'],params['g'],atol=0.5)	
		assert np.allclose(sol['h'],params['h'],atol=0.5)	
コード例 #8
0
ファイル: AR_tests.py プロジェクト: smoitra87/ssystem
	def test_fullinfo1(self) : 
		""" RUN AR (slow)  eqn 1 under full info """	
		ss = Chou2006()
		ss.exptype = "fullinfo"
		ss.equations = [1]
		ar = ARSolver(ss)
		ar.solve(maxiter=10000,tol=10e-6)
		assert len(ar.all_exp_art) == 1
		assert len(ar.all_exp_art[0]['eqns']) == 1
		art = ar.all_exp_art[0]['eqns'][0]			
		sol =  	{'alpha': 11.177018643003306,
		 'beta': 8.7027543289527056,
		 'g': np.array([-1.0236953]),
		 'h': np.array([ 0.62268492])}
		params = art.params[-1]
		assert np.allclose(sol['alpha'],params['alpha'],atol=1)	
		assert np.allclose(sol['beta'],params['beta'],atol=1.5)	
		assert np.allclose(sol['g'],params['g'],atol=0.5)	
		assert np.allclose(sol['h'],params['h'],atol=0.5)	
コード例 #9
0
ファイル: AR_tests.py プロジェクト: smoitra87/ssystem
	def test_core_init_params(self) : 
		""" Test _core_init_params"""
		self.ss = Chou2006()
		self.ss.exptype= "fullinfo"
		self.ss.equations = [1,3]
		self.ss.constraint.initsol.beta['beta_1'] = 7.0
		self.ss.constraint.initsol.h['h_1_1'] = 1.2
		self.ar = ARSolver(self.ss)
	
		(a_list,b_list,g_list,h_list) = self.ar._core_init_params()

		print a_list
		print b_list
		print g_list
		print h_list
		#assert False
		eq_(a_list,[5.0,5.0])
		eq_(b_list,[7.0,5.0])
		ass_f = lambda t : eq_(np.allclose(t[0],t[1]),True)
		map(ass_f,zip(h_list,[np.array([1.2]),np.array([1.0,1.0])]))
		map(ass_f,zip(g_list,[np.array([1.0]),np.array([1.0])]))
コード例 #10
0
ファイル: ALR_tests.py プロジェクト: smoitra87/ssystem
 def setUp(self):
     self.ss = Chou2006()
     self.ar = ARSolver(self.ss)
コード例 #11
0
 def setUp(self):
     """Setup fixture for the test"""
     self.ss = Chou2006()  # create ss instance
コード例 #12
0
ファイル: run_ss.py プロジェクト: smoitra87/ssystem
#! / usr/bin/env python
""" Run the ssystem script"""

import ssystem
from ssystem import base
from ssystem.other_models import Chou2006

#ss_dict = ssystem.cparser.parse("ssystem/allProblems/ss_5genes1");
#ss = base.SSystem(ss_dict)

c = Chou2006()
コード例 #13
0
ファイル: AR_tests.py プロジェクト: smoitra87/ssystem
	def test_core_calc_design(self) : 
		""" Test the design matrix"""
		
		# Test under the case of fullinfo
		
		# Generate dummy data
		ss = Chou2006()
		ss.exptype = "fullinfo"
		ss.equations = [1]
		ar = ARSolver(ss)

		prof = ss.experiments[0].profile
					

		reg_p = [3]
		reg_d = [1]
		
		Lp = np.ones(prof.n_sample)
		Ld = np.ones(prof.n_sample)
		
		X_p = [np.log(prof.var[:,2])]
		X_d = [np.log(prof.var[:,0])]

		Lp = np.vstack((Lp,np.array(X_p))).T
		Ld = np.vstack((Ld,np.array(X_d))).T

		Cp = np.dot(LA.inv(np.dot(Lp.T,Lp)),Lp.T)
		Cd = np.dot(LA.inv(np.dot(Ld.T,Ld)),Ld.T)


		lp_list1,ld_list1 = [Lp],[Ld]
		cp_list1,cd_list1 = [Cp],[Cd]	
	
		# Generate code results
		lp_list2,ld_list2,cp_list2,cd_list2 = ar._core_calc_design(prof)

		eq_(len(lp_list2),1)		
		eq_(len(ld_list2),1)
		eq_(len(cp_list2),1)		
		eq_(len(cd_list2),1)
		assert np.allclose(Lp,lp_list2[0])
		assert np.allclose(Ld,ld_list2[0])
		assert np.allclose(Cp,cp_list2[0])
		assert np.allclose(Cd,cd_list2[0])

		# Test under the case of no info
		ss = Chou2006()
		ss.exptype = "noinfo"
		ss.equations = [1,2]
		ar = ARSolver(ss)

		prof = ss.experiments[0].profile
					
		lp_list1,ld_list1 = [],[]
		cp_list1,cd_list1 = [],[]	

		reg_p = [1,2,3,4]
		reg_d = [1,2,3,4]
		
		Lp = np.ones(prof.n_sample)
		Ld = np.ones(prof.n_sample)
		
		X_p = np.log(prof.var.T)
		X_d = np.log(prof.var.T)

		print "X_p.shape", X_p.shape
		print "X_d.shape", X_d.shape

		Lp = np.vstack((Lp,X_p)).T
		Ld = np.vstack((Ld,X_d)).T

		Cp = np.dot(LA.inv(np.dot(Lp.T,Lp)),Lp.T)
		Cd = np.dot(LA.inv(np.dot(Ld.T,Ld)),Ld.T)


		lp_list1,ld_list1 = [Lp,Lp],[Ld,Ld]
		cp_list1,cd_list1 = [Cp,Cp],[Cd,Cd]	
	
		# Generate code results
		lp_list2,ld_list2,cp_list2,cd_list2 = ar._core_calc_design(prof)

		eq_(len(lp_list2),2)		
		eq_(len(ld_list2),2)
		eq_(len(cp_list2),2)		
		eq_(len(cd_list2),2)
		assert np.allclose(Lp,lp_list2[0])
		assert np.allclose(Ld,ld_list2[0])
		assert np.allclose(Cp,cp_list2[0])
		assert np.allclose(Cd,cd_list2[0])
		assert np.allclose(Lp,lp_list2[1])
		assert np.allclose(Ld,ld_list2[1])
		assert np.allclose(Cp,cp_list2[1])
		assert np.allclose(Cd,cd_list2[1])
コード例 #14
0
ファイル: AR_tests.py プロジェクト: smoitra87/ssystem
	def test_regressors(self) : 
		""" Test _set_regressors code """

		# Test for fullinfo and 1st and 3rd eqn
		self.ss = Chou2006()
		self.ss.exptype = "fullinfo"
		self.ss.equations = [1,3]
		self.ar = ARSolver(self.ss)

		eq_(len(self.ar.regressors),2)		

		eq_(self.ar.regressors[0]['degrad'],[1])
		eq_(self.ar.regressors[0]['prod'],[3])
		eq_(self.ar.regressors[1]['degrad'],[3,4])
		eq_(self.ar.regressors[1]['prod'],[2])
	
		# Test for fullinfo and all eqns	
		self.ss = Chou2006()
		self.ss.exptype = "fullinfo"
		self.ar = ARSolver(self.ss)	

		eq_(self.ar.regressors[0]['degrad'],[1])
		eq_(self.ar.regressors[0]['prod'],[3])
		eq_(self.ar.regressors[1]['degrad'],[2])
		eq_(self.ar.regressors[1]['prod'],[1])
		eq_(self.ar.regressors[2]['degrad'],[3,4])
		eq_(self.ar.regressors[2]['prod'],[2])
		eq_(self.ar.regressors[3]['degrad'],[4])
		eq_(self.ar.regressors[3]['prod'],[1])

		# Test for partial info and all equations	
		self.ss = Chou2006()
		self.ss.exptype = "partialinfo"
		self.ar = ARSolver(self.ss)	

		eq_(self.ar.regressors[0]['degrad'],[1,3])
		eq_(self.ar.regressors[0]['prod'],[1,3])
		eq_(self.ar.regressors[1]['degrad'],[1,2])
		eq_(self.ar.regressors[1]['prod'],[1,2])
		eq_(self.ar.regressors[2]['degrad'],[2,3,4])
		eq_(self.ar.regressors[2]['prod'],[2,3,4])
		eq_(self.ar.regressors[3]['degrad'],[1,4])
		eq_(self.ar.regressors[3]['prod'],[1,4])

		# Test for no info and all equations
		self.ss = Chou2006()
		self.ss.exptype = "noinfo"
		self.ar = ARSolver(self.ss)	

		for ii in range(4) : 
			eq_(self.ar.regressors[ii]['degrad'],[1,2,3,4])
			eq_(self.ar.regressors[ii]['prod'],[1,2,3,4])

		# Test for no info and 1st and 3rd equations
		self.ss = Chou2006()
		self.ss.exptype = "noinfo"
		self.ss.equations = [1,3]
		self.ar = ARSolver(self.ss)	

		eq_(len(self.ar.regressors),2)

		for ii in range(2) : 
			eq_(self.ar.regressors[ii]['degrad'],[1,2,3,4])
			eq_(self.ar.regressors[ii]['prod'],[1,2,3,4])