Beispiel #1
0
    def test_search_space(self):
        from deephyper.benchmark.problem import NaProblem

        pb = NaProblem()

        with pytest.raises(SearchSpaceBuilderIsNotCallable):
            pb.search_space(func="a")

        def dummy(a, b):
            return

        with pytest.raises(SearchSpaceBuilderMissingParameter):
            pb.search_space(func=dummy)

        def dummy(input_shape, output_shape):
            return

        with pytest.raises(SearchSpaceBuilderMissingDefaultParameter):
            pb.search_space(func=dummy)

        def dummy(input_shape=(1, ), output_shape=(1, )):
            return

        pb.search_space(func=dummy)
Beispiel #2
0
    def test_create(self):
        from deephyper.benchmark.problem import NaProblem

        NaProblem()
Beispiel #3
0
    def test_full_problem(self):
        from deephyper.problem import NaProblem
        from deephyper.nas.preprocessing import minmaxstdscaler

        pb = NaProblem()

        def load_data(prop):
            return ([[10]], [1]), ([10], [1])

        pb.load_data(load_data, prop=1.0)

        pb.preprocessing(minmaxstdscaler)

        def search_space(input_shape=(1,), output_shape=(1,)):
            return

        pb.search_space(search_space)

        pb.hyperparameters(
            batch_size=64,
            learning_rate=0.001,
            optimizer="adam",
            num_epochs=10,
            loss_metric="mse",
        )

        with pytest.raises(NaProblemError):
            pb.objective("r2")

        pb.loss("mse")
        pb.metrics(["r2"])

        possible_objective = ["loss", "val_loss", "r2", "val_r2"]
        for obj in possible_objective:
            pb.objective(obj)

        pb.post_training(
            num_epochs=2000,
            metrics=["mse", "r2"],
            callbacks=dict(
                ModelCheckpoint={
                    "monitor": "val_r2",
                    "mode": "max",
                    "save_best_only": True,
                    "verbose": 1,
                },
                EarlyStopping={
                    "monitor": "val_r2",
                    "mode": "max",
                    "verbose": 1,
                    "patience": 50,
                },
            ),
        )
Beispiel #4
0
    def test_full_problem(self):
        from deephyper.benchmark import NaProblem
        from deephyper.search.nas.model.preprocessing import minmaxstdscaler

        pb = NaProblem()

        def load_data(prop):
            return ([[10]], [1]), ([10], [1])

        pb.load_data(load_data, prop=1.)

        pb.preprocessing(minmaxstdscaler)

        def search_space(input_shape=(1,), output_shape=(1,)):
            return

        pb.search_space(search_space)

        pb.hyperparameters(
            batch_size=64,
            learning_rate=0.001,
            optimizer='adam',
            num_epochs=10,
            loss_metric='mse',
        )

        with pytest.raises(NaProblemError):
            pb.objective('r2')

        pb.loss('mse')
        pb.metrics(['r2'])

        possible_objective = ['loss', 'val_loss', 'r2', 'val_r2']
        for obj in possible_objective:
            pb.objective(obj)

        wrong_objective = ['mse', 'wrong', 'r2__last__max', 'val_mse']
        for obj in wrong_objective:
            with pytest.raises(WrongProblemObjective):
                pb.objective(obj)

        pb.post_training(
            num_epochs=2000,
            metrics=['mse', 'r2'],
            callbacks=dict(
                ModelCheckpoint={
                    'monitor': 'val_r2',
                    'mode': 'max',
                    'save_best_only': True,
                    'verbose': 1
                },
                EarlyStopping={
                    'monitor': 'val_r2',
                    'mode': 'max',
                    'verbose': 1,
                    'patience': 50
                })
        )