Пример #1
0
    def testMG(self, plot=False):
        c = config.copy()
        c["source"] = {"class": OpMackeyGlass}
        c["train"]["layer_sizes"] = (5,)
        c["train"]["layer_classes"] = (mlp.Sigmoid,)
        init_1 = {"class": PCAWeightInitializer}
        init_2 = {"class": LeastSquaresWeightInitializer}
        c["train"]["weight_initializer"] = (init_1, init_2)
        c["train"]["learning_rate"] = .2
        c["features"] = {"class": OpRecent, "window_size": 16}
        c["target"] = {"class": OpExponentiallySegmentedPattern,
                       "baseline_size": 8,
                       "num_segments": 1}
        w = Workflow.build(c, workingdir=self.wd)
        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            w.run()

        if plot:
            plt.figure()
            pred = w._predictionCache.Output[...].wait().squeeze()
            target = w._target.Output[...].wait().squeeze()
            orig = w._source.Output[...].wait().squeeze()
            plt.plot(target, 'b')
            plt.plot(pred, 'r+')
            plt.plot(orig, 'k.')
            plt.legend(("ground truth", "prediction", "original data"))
Пример #2
0
 def testRun(self, plot=False):
     c = config.copy()
     c["train"]["layer_sizes"] = (20, 10)
     c["train"]["layer_classes"] = (mlp.Sigmoid, mlp.Sigmoid)
     w = Workflow.build(c, workingdir=self.wd)
     with warnings.catch_warnings():
         warnings.simplefilter("ignore")
         w.run()
     return w
Пример #3
0
 def testRF(self):
     d = tempfile.mkdtemp()
     try:
         c = config.copy()
         c["train"] = {"class": OpRFTrain}
         c["predict"] = {"class": OpRFPredict}
         w = Workflow.build(c, workingdir=d)
         w.run()
     except:
         raise
     finally:
         shutil.rmtree(d)
Пример #4
0
    def testIncompatible(self):
        c = config.copy()

        def foo():
            with self.assertRaises(IncompatibleTargets):
                w = Workflow.build(c, workingdir=self.wd)
                w.run()

        c["target"] = {"class": OpFeatures}
        foo()
        c["target"] = {"class": OpRegTarget}
        c["train"] = {"class": OpRFTrain}
        foo()
        c["train"] = {"class": OpSVMTrain}
        c["predict"] = {"class": OpRFPredict}
        foo()
        c["predict"] = {"class": OpSVMPredict}
        c["report"] = {"class": OpClassificationReport}
        foo()
        c["report"] = {"class": OpRegressionReport}
        Workflow.build(c, workingdir=self.wd)
Пример #5
0
 def testNormTarget(self, plot=False):
     c = config.copy()
     c["source"] = {"class": OpRandomUnitSquare,
                    "shape": (10000, 2)}
     c["train"]["layer_sizes"] = (1,)
     c["train"]["layer_classes"] = (mlp.Sigmoid,)
     c["features"] = {"class": OpFeatures}
     c["target"] = {"class": OpNormTarget}
     w = Workflow.build(c, workingdir=self.wd)
     with warnings.catch_warnings():
         warnings.simplefilter("ignore")
         w.run()
Пример #6
0
 def testDNN(self):
     d = tempfile.mkdtemp()
     try:
         c = config.copy()
         c["train"] = {"class": OpDeepTrain,
                       "num_hidden_layers": 2,
                       "size_hidden_layers": (2, 2)}
         c["predict"] = {"class": OpMLPPredict}
         w = Workflow.build(c, workingdir=d)
         with warnings.catch_warnings():
             warnings.simplefilter("ignore")
             w.run()
     except:
         raise
     finally:
         shutil.rmtree(d)
Пример #7
0
 def testMLP(self):
     d = tempfile.mkdtemp()
     try:
         c = config.copy()
         c["train"] = {"class": OpMLPTrain,
                       "layer_classes": (mlp.Sigmoid,),
                       "layer_sizes": (5,)}
         c["predict"] = {"class": OpMLPPredict}
         w = Workflow.build(c, workingdir=d)
         with warnings.catch_warnings():
             warnings.simplefilter("ignore")
             w.run()
     except:
         raise
     finally:
         shutil.rmtree(d)
Пример #8
0
def main(args):
    conf = _get_conf(args)

    tempdir = args.workingdir
    if tempdir is None:
        prefix = "{}_{:%Y-%m-%d_%H-%M}".format(args.mode, datetime.now())
        tempdir = tempfile.mkdtemp(prefix=prefix)

    workflow = Workflow.build(conf, workingdir=tempdir)
    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        workflow.run()

    if args.plot:
        assert _plot_available, "matplotlib is needed for option --plot"
        ground_truth = workflow.Target[...].wait()
        prediction = workflow.Prediction[...].wait()
        plt.figure()
        plt.hold(True)
        plt.plot(ground_truth, 'b')
        plt.plot(prediction, 'r')
        plt.hold(False)
        plt.show()
    print("output written to dir {}".format(tempdir))
Пример #9
0
def run(args):
    c = getConfig(args)
    c["workingdir"] = args.workingdir
    w = Workflow.build(c)
    w.run()
    print("Working directory: {}".format(w._workingdir))
Пример #10
0
 def foo():
     with self.assertRaises(IncompatibleTargets):
         w = Workflow.build(c, workingdir=self.wd)
         w.run()
Пример #11
0
 def testBasic(self):
     w = Workflow.build(config, workingdir=self.wd)
     w.run()