def test_linear_regress(self): data = self.sc.parallelize([(1, array([1.5, 2.3, 6.2, 5.1, 3.4, 2.1]))]) x = array([array([1, 0, 0, 0, 0, 0]), array([0, 1, 0, 0, 0, 0])]) model = RegressionModel.load(x, "linear") betas, stats, resid = model.fit(data) assert allclose(betas.map(lambda (_, v): v).collect()[0], array([-2.7, -1.9])) assert allclose(stats.map(lambda (_, v): v).collect()[0], array([0.42785299])) assert allclose(resid.map(lambda (_, v): v).collect()[0], array([0, 0, 2, 0.9, -0.8, -2.1])) stats, betas = regress(data, x, "linear") stats.collect() betas.collect() stats, comps, latent, scores, traj = regresswithpca(data, x, "linear") stats.collect() scores.collect()
def test_blinear_regress(self): data = self.sc.parallelize([(1, array([1.5, 2.3, 6.2, 5.1, 3.4, 2.1]))]) x1 = array([array([1, 0, 1, 0, 1, 0]), array([0, 1, 0, 1, 0, 1])]) x2 = array([array([1, 1, 0, 0, 0, 0]), array([0, 0, 1, 1, 0, 0]), array([0, 0, 0, 0, 1, 1])]) model = RegressionModel.load((x1, x2), "bilinear") betas, stats, resid = model.fit(data) tol = 1e-4 # to handle rounding errors assert allclose(betas.map(lambda (_, v): v).collect()[0], array([-3.1249, 5.6875, 0.4375]), atol=tol) assert allclose(stats.map(lambda (_, v): v).collect()[0], array([0.6735]), tol) assert allclose(resid.map(lambda (_, v): v).collect()[0], array([0, -0.8666, 0, 1.9333, 0, -1.0666]), atol=tol) stats, betas = regress(data, (x1, x2), "bilinear") stats.collect() betas.collect() stats, comps, latent, scores, traj = regresswithpca(data, (x1, x2), "bilinear") stats.collect() scores.collect()
def test_linear_regress(self): data = self.sc.parallelize([(1, array([1.5, 2.3, 6.2, 5.1, 3.4, 2.1]))]) x = array([array([1, 0, 0, 0, 0, 0]), array([0, 1, 0, 0, 0, 0])]) model = RegressionModel.load(x, "linear") betas, stats, resid = model.fit(data) assert (allclose( betas.map(lambda (_, v): v).collect()[0], array([-2.7, -1.9]))) assert (allclose( stats.map(lambda (_, v): v).collect()[0], array([0.42785299]))) assert (allclose( resid.map(lambda (_, v): v).collect()[0], array([0, 0, 2, 0.9, -0.8, -2.1]))) stats, betas = regress(data, x, "linear") stats.collect() betas.collect() stats, comps, latent, scores, traj = regresswithpca(data, x, "linear") stats.collect() scores.collect()
betas, stats, resid = model.fit(data) tol = 1E-4 # to handle rounding errors assert (allclose(betas.map(lambda (_, v): v).collect()[0], array([-3.1249, 5.6875, 0.4375]), atol=tol)) assert (allclose( stats.map(lambda (_, v): v).collect()[0], array([0.6735]), tol)) assert (allclose(resid.map(lambda (_, v): v).collect()[0], array([0, -0.8666, 0, 1.9333, 0, -1.0666]), atol=tol)) stats, betas = regress(data, (x1, x2), "bilinear") stats.collect() betas.collect() stats, comps, latent, scores, traj = regresswithpca( data, (x1, x2), "bilinear") stats.collect() scores.collect() class TestTuning(RegressionTestCase): """Test accuracy of gaussian and circular tuning by building small stimulus arrays and testing on small data against ground truth (ground truth for gaussian tuning derived by doing the algebra in MATLAB, ground truth for circular tuning derived from MATLAB's circular statistics toolbox circ_mean and circ_kappa functions) Also tests that main analysis script runs without crashing