deephyper.ensemble.selector.OnlineSelector#

class deephyper.ensemble.selector.OnlineSelector(y: ndarray, selector: Selector, ensemble: EnsemblePredictor, load_predictor_func: Callable)[source]#

Bases: Callback

This class performs ensemble selection after each hyperparameter optimization job completion.

The run-function passed to the Evaluator should return in its output the "online_selector" key. This key has for value a dictionnary that includes both the "y_pred" key (i.e., predictions of the predictor on which the selection algorithm is applied) and the "y_pred_idx" key (i.e., indexes of the considered sampled in y used to score the selection):

def run(job):
    ...
    return {
        "objective": objective,
        "online_selector": {"y_pred": y_pred, "y_pred_idx": idx},
    }

the y_pred and y_pred_idx have same first dimension.

Then, we can create an instance of OnlineSelector:

from deephyper.ensemble.aggregator import MeanAggregator
from deephyper.ensemble.loss import SquaredError
from deephyper.ensemble.selector import GreedySelector

online_selector = OnlineSelector(
    y=valid_y,
    selector=GreedySelector(
        loss_func=SquaredError(),
        aggregator=MeanAggregator(),
        k=20,
    ),
)

Winally pass this callback to the Evaluator used for hyperparameter optimization:

evaluator = Evaluator.create(
    run,
    method_kwargs={
        "callbacks": [
            online_selector,
        ],
    },
)
Parameters:
  • y (np.ndarray) – the data to use for the selector.

  • selector (Selector) – the selection strategy to use.

Methods

on_done

Called each time a Job is completed by the Evaluator.

on_done_other

Called each time a Job is collected from an other process.

on_launch

Called each time a Job is created by the Evaluator.

Attributes

ensemble

The ensemble with adapted .predictors and .weights from the latest selection.

selected_predictors_job_ids

List of job.id corresponding to the selected set of predictors.

y

the data to use for the selector.

selector

the ensemble selection algorithm.

y_predictors_job_ids

the list of received job.id from completed hyperparameters optimization jobs.

y_predictors

the list of received predictions mapped to the same shape as y.

selected_predictors_indexes

the list of indexes of the first dimension of y_predictors from the selector.

selected_predictors_weights

the weights of selected predictors.

property ensemble#

The ensemble with adapted .predictors and .weights from the latest selection.

on_done(job)[source]#

Called each time a Job is completed by the Evaluator.

Parameters:

job (Job) – The completed job.

on_done_other(job)[source]#

Called each time a Job is collected from an other process.

Parameters:

job (Job) – The completed Job.

on_launch(job)#

Called each time a Job is created by the Evaluator.

Parameters:

job (Job) – The created job.

selected_predictors_indexes: List[int]#

the list of indexes of the first dimension of y_predictors from the selector.

property selected_predictors_job_ids: List[str]#

List of job.id corresponding to the selected set of predictors.

selected_predictors_weights: List[float]#

the weights of selected predictors.

selector: Selector#

the ensemble selection algorithm.

y: ndarray#

the data to use for the selector.

y_predictors: List[MaskedArray]#

the list of received predictions mapped to the same shape as y.

y_predictors_job_ids: List[str]#

the list of received job.id from completed hyperparameters optimization jobs.