|
9 | 9 | import pendulum |
10 | 10 | import pandas as pd |
11 | 11 | import tensorflow as tf |
12 | | -from cerebros.simplecerebrosrandomsearch.simple_cerebros_random_search\ |
13 | | - import SimpleCerebrosRandomSearch |
14 | | -from cerebros.units.units import DenseUnit |
15 | | -from cerebros.denseautomlstructuralcomponent.dense_automl_structural_component\ |
16 | | - import zero_7_exp_decay, zero_95_exp_decay, simple_sigmoid |
| 12 | + |
17 | 13 | from ast import literal_eval |
18 | 14 |
|
| 15 | +from copy import copy |
| 16 | +from gc import collect |
| 17 | + |
19 | 18 | # Define constants |
20 | 19 | LABEL_COLUMN = 'price' |
21 | 20 | NUMBER_OF_TRAILS_PER_BATCH = 2 |
|
43 | 42 | OUTPUT_SHAPES = [1] |
44 | 43 |
|
45 | 44 | def objective(trial): |
| 45 | + from cerebros.simplecerebrosrandomsearch.simple_cerebros_random_search\ |
| 46 | + import SimpleCerebrosRandomSearch |
| 47 | + from cerebros.units.units import DenseUnit |
| 48 | + from cerebros.denseautomlstructuralcomponent.dense_automl_structural_component\ |
| 49 | + import zero_7_exp_decay, zero_95_exp_decay, simple_sigmoid |
46 | 50 | # Define hyperparameter space |
47 | | - minimum_levels = trial.suggest_int('minimum_levels', 1, 5) |
48 | | - maximum_levels = trial.suggest_int('maximum_levels', minimum_levels, 5) |
| 51 | + minimum_levels = trial.suggest_int('minimum_levels', 1, 4) |
| 52 | + maximum_levels = trial.suggest_int('maximum_levels', minimum_levels, 4) |
49 | 53 | minimum_units_per_level = trial.suggest_int('minimum_units_per_level', 1, 5) |
50 | 54 | maximum_units_per_level = trial.suggest_int('maximum_units_per_level', minimum_units_per_level, 5) |
51 | 55 | minimum_neurons_per_unit = trial.suggest_int('minimum_neurons_per_unit', 1, 5) |
52 | 56 | maximum_neurons_per_unit = trial.suggest_int('maximum_neurons_per_unit', minimum_neurons_per_unit, 5) |
53 | 57 | activation = trial.suggest_categorical('activation', ['relu', 'elu', 'gelu', 'swish', 'softplus']) |
54 | | - predecessor_level_connection_affinity_factor_first = trial.suggest_loguniform('predecessor_level_connection_affinity_factor_first', 0.1, 40.0) |
55 | | - predecessor_level_connection_affinity_factor_main = trial.suggest_loguniform('predecessor_level_connection_affinity_factor_main', 0.1, 40.0) |
| 58 | + predecessor_level_connection_affinity_factor_first = trial.suggest_float('predecessor_level_connection_affinity_factor_first', 0.1, 40.0, log=True) |
| 59 | + predecessor_level_connection_affinity_factor_main = trial.suggest_float('predecessor_level_connection_affinity_factor_main', 0.1, 40.0, log=True) |
56 | 60 | max_consecutive_lateral_connections = trial.suggest_int('max_consecutive_lateral_connections', 1, 35) |
57 | | - p_lateral_connection = trial.suggest_loguniform('p_lateral_connection', 0.1, 35) |
| 61 | + p_lateral_connection = trial.trial.suggest_float('p_lateral_connection', 0.1, 35, log=True) |
58 | 62 | num_lateral_connection_tries_per_unit = trial.suggest_int('num_lateral_connection_tries_per_unit', 1, 35) |
59 | | - learning_rate = trial.suggest_loguniform('learning_rate', 10**-6, 0.6) |
| 63 | + learning_rate = trial.trial.suggest_float('learning_rate', 10**-6, 0.6, log=True) |
60 | 64 | epochs = trial.suggest_int('epochs', 1, 150) |
61 | 65 | batch_size = trial.suggest_int('batch_size', 1, 800) |
62 | 66 |
|
@@ -113,7 +117,23 @@ def objective(trial): |
113 | 117 | meta_trial_number=meta_trial_number) |
114 | 118 |
|
115 | 119 | result = cerebros.run_random_search() |
116 | | - return result |
| 120 | + |
| 121 | + # Make a copy of the result so it isn't lost in garbage collection. |
| 122 | + |
| 123 | + result_0 = copy(result) |
| 124 | + |
| 125 | + # Garbage collection to create a clen state for |
| 126 | + # the next run and to prevent memory leakage |
| 127 | + del(result) |
| 128 | + del(cerebros) |
| 129 | + del(SimpleCerebrosRandomSearch) |
| 130 | + del(DenseUnit) |
| 131 | + del(zero_7_exp_decay) |
| 132 | + del(zero_95_exp_decay) |
| 133 | + del(simple_sigmoid) |
| 134 | + collect() |
| 135 | + |
| 136 | + return result_0 |
117 | 137 |
|
118 | 138 | def main(): |
119 | 139 | study = optuna.create_study(direction='minimize') |
|
0 commit comments