MCPcopy
hub / github.com/hyperopt/hyperopt / suggest

Function suggest

hyperopt/tpe.py:830–958  ·  view source on GitHub ↗

Given previous trials and the domain, suggest the best expected hp point according to the TPE-EI algo Args: prior_weight( n_startup_jobs: n_EI_candidates: gamma: verbose: Returns:

(
    new_ids,
    domain,
    trials,
    seed,
    prior_weight=_default_prior_weight,
    n_startup_jobs=_default_n_startup_jobs,
    n_EI_candidates=_default_n_EI_candidates,
    gamma=_default_gamma,
    verbose=True,
)

Source from the content-addressed store, hash-verified

828
829
830def suggest(
831 new_ids,
832 domain,
833 trials,
834 seed,
835 prior_weight=_default_prior_weight,
836 n_startup_jobs=_default_n_startup_jobs,
837 n_EI_candidates=_default_n_EI_candidates,
838 gamma=_default_gamma,
839 verbose=True,
840):
841 """
842 Given previous trials and the domain, suggest the best expected hp point
843 according to the TPE-EI algo
844
845
846 Args:
847 prior_weight(
848 n_startup_jobs:
849 n_EI_candidates:
850 gamma:
851 verbose:
852
853 Returns:
854
855 """
856
857 t0 = time.time()
858 # use build_posterior_wrapper to create the pyll nodes
859 observed, observed_loss, posterior = build_posterior_wrapper(
860 domain, prior_weight, gamma
861 )
862 tt = time.time() - t0
863 if verbose:
864 logger.info("build_posterior_wrapper took %f seconds" % tt)
865
866 # Loop over previous trials to collect best_docs and best_docs_loss
867 best_docs = dict()
868 best_docs_loss = dict()
869 for doc in trials.trials:
870
871 # get either these docs own tid or the one that it's from
872 tid = doc["misc"].get("from_tid", doc["tid"])
873
874 # associate infinite loss to new/running/failed jobs
875 loss = doc["result"].get("loss")
876 loss = float("inf") if loss is None else float(loss)
877
878 # if set, update loss for this tid if it's higher than current loss
879 # otherwise, set it
880 best_docs_loss.setdefault(tid, loss)
881 if loss <= best_docs_loss[tid]:
882 best_docs_loss[tid] = loss
883 best_docs[tid] = doc
884
885 # -- sort docs by order of suggestion
886 # so that linear_forgetting removes the oldest ones
887 tid_docs = sorted(best_docs.items())

Callers

nothing calls this directly

Calls 10

build_posterior_wrapperFunction · 0.85
miscs_to_idxs_valsFunction · 0.85
miscs_update_idxs_valsFunction · 0.85
infoMethod · 0.80
getMethod · 0.80
itemsMethod · 0.80
suggestMethod · 0.80
keysMethod · 0.80
new_resultMethod · 0.80
new_trial_docsMethod · 0.80

Tested by

no test coverage detected