Beispiel #1
0
def fitKernel(x, y, maxLag, maxLead=0, padding=False, mask=None): 
    
    regMat, yMask = kerToReg(x, maxLag, maxLead, padding, mask)
    model = RegressionModel.load(regMat, "linear")   
    #TODO: when Series.selectByIndex is available, it should be used here instead of Series.applyValues
    yMasked = y.applyValues(lambda v: v[yMask])
    return model.fit(yMasked)
    def perform_regression(self, regressor_list):
        regressor_list = zscore(regressor_list, axis=1)
        regression_results = RegressionModel.load(regressor_list, "linear").fit(self.data)
        b = regression_results.select("betas").pack()
        rsq = regression_results.select("stats").pack()

        return regression_results, b, rsq
    def perform_regression(self, regressor_list):
        regressor_list = zscore(regressor_list, axis=1)
        regression_results = RegressionModel.load(regressor_list,
                                                  'linear').fit(self.data)
        b = regression_results.select('betas').pack()
        rsq = regression_results.select('stats').pack()

        return regression_results, b, rsq
Beispiel #4
0
"""
Example standalone app for mass-univariate regression
"""

import optparse
from thunder import ThunderContext, RegressionModel


if __name__ == "__main__":
    parser = optparse.OptionParser(description="fit a regression model",
                                   usage="%prog datafile modelfile outputdir [options]")
    parser.add_option("--regressmode", choices=("mean", "linear", "bilinear"),
                      default="linear", help="form of regression")

    opts, args = parser.parse_args()
    try:
        datafile = args[0]
        modelfile = args[1]
        outputdir = args[2]
    except IndexError:
        parser.print_usage()
        raise Exception("too few arguments")

    tsc = ThunderContext.start(appName="regress")

    data = tsc.loadText(datafile)
    result = RegressionModel.load(modelfile, opts.regressmode).fit(data)

    outputdir += "-regress"
    tsc.export(result.select('stats'), outputdir, "stats", "matlab")
    tsc.export(result.select('betas'), outputdir, "betas", "matlab")
Beispiel #5
0
"""

import optparse
from thunder import ThunderContext, RegressionModel

if __name__ == "__main__":
    parser = optparse.OptionParser(
        description="fit a regression model",
        usage="%prog datafile modelfile outputdir [options]")
    parser.add_option("--regressmode",
                      choices=("mean", "linear", "bilinear"),
                      default="linear",
                      help="form of regression")

    opts, args = parser.parse_args()
    try:
        datafile = args[0]
        modelfile = args[1]
        outputdir = args[2]
    except IndexError:
        parser.print_usage()
        raise Exception("too few arguments")

    tsc = ThunderContext.start(appName="regress")

    data = tsc.loadText(datafile)
    result = RegressionModel.load(modelfile, opts.regressmode).fit(data)

    outputdir += "-regress"
    tsc.export(result.select('stats'), outputdir, "stats", "matlab")
    tsc.export(result.select('betas'), outputdir, "betas", "matlab")
Beispiel #6
0
from thunder import ThunderContext, RegressionModel, PCA


if __name__ == "__main__":
    parser = optparse.OptionParser(description="fit a regression model",
                                   usage="%prog datafile modelfile outputdir [options]")
    parser.add_option("--regressmode", choices=("mean", "linear", "bilinear"), help="form of regression")
    parser.add_option("--k", type=int, default=2)

    opts, args = parser.parse_args()
    try:
        datafile = args[0]
        modelfile = args[1]
        outputdir = args[2]
    except IndexError:
        parser.print_usage()
        raise Exception("too few arguments")

    tsc = ThunderContext.start(appName="regresswithpca")

    data = tsc.loadSeries(datafile)
    model = RegressionModel.load(modelfile, opts.regressmode)  # do regression
    betas, stats, resid = model.fit(data)
    pca = PCA(opts.k).fit(betas)  # do PCA
    traj = model.fit(data, pca.comps)  # get trajectories

    outputdir += "-regress"
    tsc.export(pca.comps, outputdir, "comps", "matlab")
    tsc.export(pca.latent, outputdir, "latent", "matlab")
    tsc.export(pca.scores, outputdir, "scores", "matlab")
    tsc.export(traj, outputdir, "traj", "matlab")
Beispiel #7
0
if __name__ == "__main__":
    parser = optparse.OptionParser(
        description="fit a regression model",
        usage="%prog datafile modelfile outputdir [options]")
    parser.add_option("--regressmode",
                      choices=("mean", "linear", "bilinear"),
                      help="form of regression")
    parser.add_option("--k", type=int, default=2)

    opts, args = parser.parse_args()
    try:
        datafile = args[0]
        modelfile = args[1]
        outputdir = args[2]
    except IndexError:
        parser.print_usage()
        raise Exception("too few arguments")

    tsc = ThunderContext.start(appName="regresswithpca")

    data = tsc.loadSeries(datafile)
    model = RegressionModel.load(modelfile, opts.regressmode)  # do regression
    betas, stats, resid = model.fit(data)
    pca = PCA(opts.k).fit(betas)  # do PCA
    traj = model.fit(data, pca.comps)  # get trajectories

    outputdir += "-regress"
    export(pca.comps, outputdir, "comps", "matlab")
    export(pca.latent, outputdir, "latent", "matlab")
    export(pca.scores, outputdir, "scores", "matlab")
    export(traj, outputdir, "traj", "matlab")
Beispiel #8
0
"""
Example standalone app for mass-unvariate regression combined with PCA
"""

import argparse
from thunder import ThunderContext, RegressionModel, PCA, export


if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="fit a regression model")
    parser.add_argument("datafile", type=str)
    parser.add_argument("modelfile", type=str)
    parser.add_argument("outputdir", type=str)
    parser.add_argument("regressmode", choices=("mean", "linear", "bilinear"), help="form of regression")
    parser.add_argument("--k", type=int, default=2)

    args = parser.parse_args()

    tsc = ThunderContext.start(appName="regresswithpca")

    data = tsc.loadSeries(args.datafile)
    model = RegressionModel.load(args.modelfile, args.regressmode)  # do regression
    betas, stats, resid = model.fit(data)
    pca = PCA(args.k).fit(betas)  # do PCA
    traj = model.fit(data, pca.comps)  # get trajectories

    outputdir = args.outputdir + "-regress"
    export(pca.comps, outputdir, "comps", "matlab")
    export(pca.latent, outputdir, "latent", "matlab")
    export(pca.scores, outputdir, "scores", "matlab")
    export(traj, outputdir, "traj", "matlab")
Beispiel #9
0
"""
Example standalone app for mass-univariate regression
"""

import argparse
from thunder import ThunderContext, RegressionModel, export


if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="fit a regression model")
    parser.add_argument("datafile", type=str)
    parser.add_argument("modelfile", type=str)
    parser.add_argument("outputdir", type=str)
    parser.add_argument("regressmode", choices=("mean", "linear", "bilinear"), help="form of regression")

    args = parser.parse_args()

    tsc = ThunderContext.start(appName="regress")

    data = tsc.loadText(args.datafile, args.preprocess)
    result = RegressionModel.load(args.modelfile, args.regressmode).fit(data)

    outputdir = args.outputdir + "-regress"
    export(result.select('stats'), outputdir, "stats", "matlab")
    export(result.select('betas'), outputdir, "betas", "matlab")
Beispiel #10
0
"""

import argparse
from thunder import ThunderContext, RegressionModel, PCA, export

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="fit a regression model")
    parser.add_argument("datafile", type=str)
    parser.add_argument("modelfile", type=str)
    parser.add_argument("outputdir", type=str)
    parser.add_argument("regressmode",
                        choices=("mean", "linear", "bilinear"),
                        help="form of regression")
    parser.add_argument("--k", type=int, default=2)

    args = parser.parse_args()

    tsc = ThunderContext.start(appName="regresswithpca")

    data = tsc.loadSeries(args.datafile)
    model = RegressionModel.load(args.modelfile,
                                 args.regressmode)  # do regression
    betas, stats, resid = model.fit(data)
    pca = PCA(args.k).fit(betas)  # do PCA
    traj = model.fit(data, pca.comps)  # get trajectories

    outputdir = args.outputdir + "-regress"
    export(pca.comps, outputdir, "comps", "matlab")
    export(pca.latent, outputdir, "latent", "matlab")
    export(pca.scores, outputdir, "scores", "matlab")
    export(traj, outputdir, "traj", "matlab")