コード例 #1
0
    def test_add_starting_points_with_too_many_dim(self):
        from deephyper.problem import HpProblem

        pb = HpProblem()
        pb.add_hyperparameter((-10, 10), "dim0")
        with pytest.raises(ValueError):
            pb.add_starting_point(dim0=0, dim1=2)
コード例 #2
0
    python -m deephyper.search.hps.ambs2 --evaluator threadPool --problem deephyper.benchmark.hps.toy.problem_basic_1.Problem --run deephyper.benchmark.hps.toy.problem_basic_1.run --max-evals 100 --kappa 0.001
"""
import ConfigSpace.hyperparameters as csh
import numpy as np

from deephyper.problem import HpProblem

# Problem definition
Problem = HpProblem()

x_hp = csh.UniformIntegerHyperparameter(name="x", lower=0, upper=10, log=False)
y_hp = csh.UniformIntegerHyperparameter(name="y", lower=0, upper=10, log=False)

Problem.add_hyperparameters([x_hp, y_hp])

Problem.add_starting_point(x=1, y=1)

# Definition of the function which runs the model


def run(param_dict):

    x = param_dict["x"]
    y = param_dict["y"]

    res = x + y

    return res  # the objective


if __name__ == "__main__":
コード例 #3
0
    def test_add_good_reference(self):
        from deephyper.problem import HpProblem

        pb = HpProblem()
        pb.add_hyperparameter((-10, 10), "dim0")
        pb.add_starting_point(dim0=0)
コード例 #4
0
from deephyper.problem import HpProblem
from nas_big_data import RANDOM_STATE
from nas_big_data.albert.load_data import load_data
from sklearn.ensemble import RandomForestClassifier

Problem = HpProblem()

Problem.add_hyperparameter((10, 300), "n_estimators")
Problem.add_hyperparameter(["gini", "entropy"], "criterion")
Problem.add_hyperparameter((1, 50), "max_depth")
Problem.add_hyperparameter((2, 10), "min_samples_split")

# We define a starting point with the defaul hyperparameters from sklearn-learn
# that we consider good in average.
Problem.add_starting_point(n_estimators=100,
                           criterion="gini",
                           max_depth=50,
                           min_samples_split=2)


def test_best():
    """Test data with RandomForest

    """
    fcsv = "results_tune_random_forest.csv"
    csv_path = os.path.join(os.path.dirname(__file__), fcsv)
    df = pd.read_csv(csv_path)
    config = df.iloc[df.objective.argmax()][:-2].to_dict()

    (X_train, y_train), (X_test, y_test) = load_data(use_test=True,
                                                     out_ohe=False)
コード例 #5
0
    def test_add_starting_points_not_in_space_def(self):
        from deephyper.problem import HpProblem

        pb = HpProblem()
        pb.add_hyperparameter((-10, 10), "dim0")
        pb.add_hyperparameter((-10.0, 10.0), "dim1")
        pb.add_hyperparameter(["a", "b"], "dim2")

        with pytest.raises(ValueError):
            pb.add_starting_point(dim0=-11, dim1=0.0, dim2="a")

        with pytest.raises(ValueError):
            pb.add_starting_point(dim0=11, dim1=0.0, dim2="a")

        with pytest.raises(ValueError):
            pb.add_starting_point(dim0=0, dim1=-11.0, dim2="a")

        with pytest.raises(ValueError):
            pb.add_starting_point(dim0=0, dim1=11.0, dim2="a")

        with pytest.raises(ValueError):
            pb.add_starting_point(dim0=0, dim1=0.0, dim2="c")

        pb.add_starting_point(dim0=0, dim1=0.0, dim2="a")
コード例 #6
0
Problem.add_dim('batch_size', (5, 500)) 	  # int in range 5-500
Problem.add_dim('log10_learning_rate', (-5.0, 0.0))  # float lr range from 10^-5 to 1

# one of ['relu', ..., ]
Problem.add_dim('activation', ['relu', 'elu', 'selu', 'tanh'])

optimizer = Problem.add_dim('optimizer', [
    'Adam', 'RMSprop', 'SGD', 'Nadam', 'Adagrad'
])

# Only vary momentum if optimizer is SGD
momentum = Problem.add_dim("momentum", (0.5, 0.9))
Problem.add_condition(cs.EqualsCondition(momentum, optimizer, "SGD"))

# Add a starting point to try first
Problem.add_starting_point(
    units1=16,
    units2=32,
    dropout1=0.0,
    dropout2=0.0,
    batch_size=16,
    activation='relu',
    optimizer='SGD',
    log10_learning_rate=-3.0,
    momentum=0.5,
)


if __name__ == "__main__":
    print(Problem)
コード例 #7
0
from deephyper.problem import HpProblem

Problem = HpProblem()

Problem.add_dim('units', (1, 100))
Problem.add_dim('activation', ['NA', 'relu', 'sigmoid', 'tanh'])
Problem.add_dim('lr', (0.0001, 1.))

Problem.add_starting_point(
    units=10,
    activation='relu',
    lr=0.01)

if __name__ == '__main__':
    print(Problem)
コード例 #8
0
from deephyper.problem import HpProblem

Problem = HpProblem()

Problem.add_dim("lr", [1e-4, 5e-4, .001, .005, .01, .1])
Problem.add_dim("trade_off", [.01, .05, .1, .5, 1])
Problem.add_dim("cycle_length", [2, 4, 5, 8, 10])
Problem.add_dim("weight_decay", [1e-5, 1e-4, 1e-3, 5e-2, .01, .1])

Problem.add_starting_point(lr=1e-4, trade_off=.01, cycle_length=2, weight_decay = 1e-5)

if __name__ == "__main__":
    print(Problem)
コード例 #9
0
"""
python -m deephyper.search.hps.ambs2 --evaluator threadPool --problem deephyper.benchmark.hps.polynome2.Problem --run deephyper.benchmark.hps.polynome2.run --max-evals 100 --kappa 0.001
"""
import numpy as np

from deephyper.benchmark.benchmark_functions_wrappers import polynome_2
from deephyper.problem import HpProblem

# Problem definition
Problem = HpProblem()

num_dim = 10
for i in range(num_dim):
    Problem.add_hyperparameter((-10.0, 10.0), f"e{i}")

Problem.add_starting_point(**{f"e{i}": 10.0 for i in range(num_dim)})

# Definition of the function which runs the model


def run(param_dict):
    f, _, _ = polynome_2()

    num_dim = 10
    x = np.array([param_dict[f"e{i}"] for i in range(num_dim)])

    return f(x)  # the objective


if __name__ == "__main__":
    print(Problem)
コード例 #10
0
from deephyper.problem import HpProblem

Problem = HpProblem()

Problem.add_dim("lr", [1e-4, 5e-4, .001, .005, .01, .1])
Problem.add_dim("trade_off", [.01, .05, .1, .5, 1])
Problem.add_dim("intra_loss_coef", [.01, .05, .1, .5, 1])
Problem.add_dim("inter_loss_coef", [.01, .05, .1, .5, 1])
Problem.add_dim("em_loss_coef", [.01, .05, .1, .5, 1])
Problem.add_dim("cycle_length", [2, 4, 8, 10])
Problem.add_dim("weight_decay", [1e-4, 1e-3, 5e-2, .01, .1])
Problem.add_dim("ad_net_mult_lr", [.01, .05, .1, .5, .75, 1.1, 1.5])
Problem.add_dim("beta_1", [.7, .8, .9])
Problem.add_dim("beta_2", [.8, .9, .99])

Problem.add_starting_point(lr=1e-4, trade_off=.01, intra_loss_coef=.01, inter_loss_coef=.01, em_loss_coef=.01, cycle_length=2, \
 weight_decay = 1e-4, ad_net_mult_lr = .01, beta_1 = .7, beta_2 = .8)

if __name__ == "__main__":
    print(Problem)
コード例 #11
0
from deephyper.problem import HpProblem

Problem = HpProblem()

Problem.add_dim("units", (1, 100))
Problem.add_dim("activation", [None, "relu", "sigmoid", "tanh"])
Problem.add_dim("lr", (0.0001, 1.0))

Problem.add_starting_point(units=10, activation=None, lr=0.01)

if __name__ == "__main__":
    print(Problem)
コード例 #12
0
ファイル: problem.py プロジェクト: felixeperez/deephyper
from deephyper.problem import HpProblem

Problem = HpProblem()
Problem.add_hyperparameter((5, 500), "epochs")
Problem.add_hyperparameter((1, 1000), "nunits_l1")
Problem.add_hyperparameter((1, 1000), "nunits_l2")
Problem.add_hyperparameter(["relu", "elu", "selu", "tanh"], "activation_l1")
Problem.add_hyperparameter(["relu", "elu", "selu", "tanh"], "activation_l2")
Problem.add_hyperparameter((8, 1024), "batch_size")
Problem.add_hyperparameter((0.0, 1.0), "dropout_l1")
Problem.add_hyperparameter((0.0, 1.0), "dropout_l2")

Problem.add_starting_point(
    epochs=5,
    nunits_l1=1,
    nunits_l2=2,
    activation_l1="relu",
    activation_l2="relu",
    batch_size=8,
    dropout_l1=0.0,
    dropout_l2=0.0,
)

if __name__ == "__main__":
    print(Problem)