Ejemplo n.º 1
0
 def test_gaussian_tuning_model(self):
     data = self.sc.parallelize([(1, array([1.5, 2.3, 6.2, 5.1, 3.4, 2.1]))])
     s = array([0.1, 0.2, 0.3, 0.4, 0.5, 0.6])
     model = TuningModel.load(s, "gaussian")
     params = model.fit(data)
     tol = 1e-4  # to handle rounding errors
     assert allclose(params.map(lambda (_, v): v).collect()[0], array([0.36262, 0.01836]), atol=tol)
Ejemplo n.º 2
0
 def test_circular_tuning_model(self):
     data = self.sc.parallelize([(1, array([1.5, 2.3, 6.2, 5.1, 3.4, 2.1]))])
     s = array([-pi / 2, -pi / 3, -pi / 4, pi / 4, pi / 3, pi / 2])
     model = TuningModel.load(s, "circular")
     params = model.fit(data)
     tol = 1e-4  # to handle rounding errors
     assert allclose(params.map(lambda (_, v): v).collect()[0], array([0.10692, 1.61944]), atol=tol)
Ejemplo n.º 3
0
def tuning(data, tuningmodelfile, tuningmode, regressmodelfile=None, regressmode=None):
    """Estimate parameters of a tuning curve model,
    optionally preceeded by regression

    :param data: RDD of data points as key value pairs
    :param tuningmodelfile: model parameters for tuning (string with file location, array, or tuple)
    :param: tuningmode: form of tuning ("gaussian" or "circular")
    :param regressmodelfile: model parameters for regression (default=None)
    :param regressmode: form of regression ("linear" or "bilinear") (default=None)

    :return params: tuning curve parameters
    """
    # create tuning model
    tuningmodel = TuningModel.load(tuningmodelfile, tuningmode)

    # get tuning curves
    if regressmodelfile is not None:
        # use regression results
        regressmodel = RegressionModel.load(regressmodelfile, regressmode)
        betas, stats, resid = regressmodel.fit(data)
        params = tuningmodel.fit(betas)
    else:
        # use data
        params = tuningmodel.fit(data)

    return params
Ejemplo n.º 4
0
def tuning(data,
           tuningmodelfile,
           tuningmode,
           regressmodelfile=None,
           regressmode=None):
    """Estimate parameters of a tuning curve model,
    optionally preceeded by regression

    :param data: RDD of data points as key value pairs
    :param tuningmodelfile: model parameters for tuning (string with file location, array, or tuple)
    :param: tuningmode: form of tuning ("gaussian" or "circular")
    :param regressmodelfile: model parameters for regression (default=None)
    :param regressmode: form of regression ("linear" or "bilinear") (default=None)

    :return params: tuning curve parameters
    """
    # create tuning model
    tuningmodel = TuningModel.load(tuningmodelfile, tuningmode)

    # get tuning curves
    if regressmodelfile is not None:
        # use regression results
        regressmodel = RegressionModel.load(regressmodelfile, regressmode)
        betas, stats, resid = regressmodel.fit(data)
        params = tuningmodel.fit(betas)
    else:
        # use data
        params = tuningmodel.fit(data)

    return params
Ejemplo n.º 5
0
def tuning(data, tuningmodelfile, tuningmode, regressmodelfile=None, regressmode=None):
    """estimate parameters of a tuning curve model,
    optionally preceeded by regression

    arguments:
    data - RDD of data points
    tuningmodelfile - model parameters (string with file location, array, or tuple)
    tuningmode - form of tuning ("gaussian" or "circular")
    regressmodelfile - model parameters (default=None)
    regressmode - form of regression ("linear" or "bilinear") (default=None)

    returns:
    params - tuning curve parameters
    """
    # create tuning model
    tuningmodel = TuningModel.load(tuningmodelfile, tuningmode)

    # get tuning curves
    if regressmodelfile is not None:
        # use regression results
        regressmodel = RegressionModel.load(regressmodelfile, regressmode)
        betas, stats, resid = regressmodel.fit(data)
        params = tuningmodel.fit(betas)
    else:
        # use data
        params = tuningmodel.fit(data)

    return params
Ejemplo n.º 6
0
 def test_gaussian_tuning_model(self):
     data = self.sc.parallelize([(1, array([1.5, 2.3, 6.2, 5.1, 3.4,
                                            2.1]))])
     s = array([0.1, 0.2, 0.3, 0.4, 0.5, 0.6])
     model = TuningModel.load(s, "gaussian")
     params = model.fit(data)
     tol = 1E-4  # to handle rounding errors
     assert (allclose(params.map(lambda (_, v): v).collect()[0],
                      array([0.36262, 0.01836]),
                      atol=tol))
Ejemplo n.º 7
0
 def test_circular_tuning_model(self):
     data = self.sc.parallelize([(1, array([1.5, 2.3, 6.2, 5.1, 3.4,
                                            2.1]))])
     s = array([-pi / 2, -pi / 3, -pi / 4, pi / 4, pi / 3, pi / 2])
     model = TuningModel.load(s, "circular")
     params = model.fit(data)
     tol = 1E-4  # to handle rounding errors
     assert (allclose(params.map(lambda (_, v): v).collect()[0],
                      array([0.10692, 1.61944]),
                      atol=tol))