Пример #1
0
    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()
Пример #2
0
    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()
Пример #3
0
    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()
Пример #4
0
    data.cache()

    # compute mean map
    vals = stats(data,"mean")
    save(vals,outputdir,"mean_vals","matlab")

    # compute local cor
    if args.neighbourhood != 0:
        cor = localcorr(data,args.neighbourhood)
        save(cor,outputdir,"local_corr","matlab")

    # if stim argument is not default
    if args.stim != '-':
        # parse into different stim names
        p = re.compile('-')
        stims = p.split(args.stim)

        # compute regression
        for i in range(len(stims)):
            modelfile = os.path.join(args.datafolder, args.basename + stims[i])
            stats, betas = regress(data, modelfile, args.regressmode)
            tune = tuning(betas,modelfile, args.tuningmode)
            out_name = "stats_" + stims[i]
            save(stats, outputdir, out_name, "matlab")
            out_name = "tune_" + stims[i]
            save(tune, outputdir, out_name, "matlab")




Пример #5
0
 def test_mean_regression(self):
     data = get_data_regression(self)
     betas, stats, comps, latent, scores, traj, r = regress(data, FISH_LINEAR_MODEL, "mean")
     stats.collect()
     scores.collect()
     r.collect()
Пример #6
0
 def test_bilinear_regression(self):
     data = get_data_regression(self)
     betas, stats, comps, latent, scores, traj, r = regress(data, FISH_BILINEAR_MODEL, "bilinear")
     stats.collect()
     scores.collect()
     r.collect()
Пример #7
0
 def test_linear_shuffle_regression(self):
     data = get_data_regression(self)
     betas, stats, comps, latent, scores, traj, r = regress(data, FISH_LINEAR_MODEL, "linear-shuffle")
     stats.collect()
     scores.collect()
     r.collect()
Пример #8
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()


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,