def run_search(): searchers = (RandomSearcher(get_space, space_sample_validation_fn=lambda s: True), MCTSSearcher(get_space, max_node_space=10), EvolutionSearcher(get_space, 5, 3, regularized=False)) for searcher in searchers: for i in range(100): space_sample = searcher.sample() assert space_sample.all_assigned == True print(searcher.__class__.__name__, i, space_sample.params_summary()) searcher.update_result(space_sample, np.random.uniform(0.1, 0.9))
from deeptables.datasets import dsutils from deeptables.models.hyper_dt import * from deeptables.utils import consts from hypernets.core.callbacks import SummaryCallback, FileStorageLoggingCallback from hypernets.core.searcher import OptimizeDirection from hypernets.core.trial import DiskTrialStore from hypernets.searchers.evolution_searcher import EvolutionSearcher homedir = f'{consts.PROJECT_NAME}_run_dt_{time.strftime("%Y%m%d%H%M%S")}' disk_trial_store = DiskTrialStore(f'hotexamples_com/trial_store') # searcher = MCTSSearcher(mini_dt_space, max_node_space=0,optimize_direction=OptimizeDirection.Maximize) # searcher = RandomSearcher(mini_dt_space, optimize_direction=OptimizeDirection.Maximize) searcher = EvolutionSearcher(mini_dt_space, 200, 100, regularized=True, candidates_size=30, optimize_direction=OptimizeDirection.Maximize) hdt = HyperDT(searcher, callbacks=[ SummaryCallback(), FileStorageLoggingCallback(searcher, output_dir=f'hotexamples_com/hyn_logs') ], reward_metric='AUC', earlystopping_patience=1) space = mini_dt_space() assert space.combinations == 589824 space2 = default_dt_space()
def test_set_random_state(self): from hypernets.core import set_random_state set_random_state(9527) searcher = EvolutionSearcher( get_space, 5, 3, regularized=False, optimize_direction=OptimizeDirection.Maximize) vectors = [] for i in range(1, 10): vectors.append(searcher.sample().vectors) assert vectors == [[98, 0, 0, 0.96], [9, 0, 0, 0.93], [60, 0, 1, 0.24], [54, 0, 1, 0.7], [25, 0, 1, 0.73], [67, 1, 1, 0.43], [57, 1, 1, 0.05], [49, 0, 0, 0.71], [71, 1, 1, 0.49]] set_random_state(None) searcher = EvolutionSearcher( get_space, 5, 3, regularized=False, optimize_direction=OptimizeDirection.Maximize) vectors = [] for i in range(1, 10): vectors.append(searcher.sample().vectors) assert vectors != [[98, 0, 0, 0.96], [9, 0, 0, 0.93], [60, 0, 1, 0.24], [54, 0, 1, 0.7], [25, 0, 1, 0.73], [67, 1, 1, 0.43], [57, 1, 1, 0.05], [49, 0, 0, 0.71], [71, 1, 1, 0.49]] set_random_state(9527) searcher = EvolutionSearcher( get_space, 5, 3, regularized=False, optimize_direction=OptimizeDirection.Maximize) vectors = [] for i in range(1, 10): vectors.append(searcher.sample().vectors) assert vectors == [[98, 0, 0, 0.96], [9, 0, 0, 0.93], [60, 0, 1, 0.24], [54, 0, 1, 0.7], [25, 0, 1, 0.73], [67, 1, 1, 0.43], [57, 1, 1, 0.05], [49, 0, 0, 0.71], [71, 1, 1, 0.49]] set_random_state(1) searcher = EvolutionSearcher( get_space, 5, 3, regularized=False, optimize_direction=OptimizeDirection.Maximize) vectors = [] for i in range(1, 10): vectors.append(searcher.sample().vectors) assert vectors == [[38, 1, 0, 0.93], [10, 1, 1, 0.15], [17, 1, 0, 0.39], [7, 1, 0, 0.85], [19, 0, 1, 0.44], [29, 1, 0, 0.67], [88, 1, 1, 0.43], [95, 0, 0, 0.8], [10, 1, 1, 0.09]] set_random_state(None)