deephyper.ensemble.EnsemblePredictor#

class deephyper.ensemble.EnsemblePredictor(predictors: Sequence[Predictor | PredictorLoader], aggregator: Aggregator, weights: Sequence[float] = None, evaluator: str | Dict = None)[source]#

Bases: Predictor

A predictor that is itself an ensemble of multiple predictors.

Parameters:
  • predictors (Sequence[Predictor | PredictorLoader]) – the list of predictors to put in the ensemble. The sequence can be composed of Predictor (i.e., the model is already loaded in memory) or PredictorLoader to perform the loading remotely and in parallel. In the later case, the .load() function is called for each inference.

  • aggregator (Aggregator) – the aggregation function to fuse the predictions of the predictors into one prediction.

  • weights (Sequence[float], optional) – the weights of the predictors in the aggregation. Defaults to None.

  • evaluator (str | Dict, optional) – The parallel strategy to compute predictions from the list of predictions. If it is a str it must be a possible method of Evaluator.create(..., method=...). If it is a dict it must have two keys method and method_kwargs such as Evaluator.create(...). Defaults to None which is equivalent to evaluator="serial" for serial evaluations.

Raises:

ValueError – when the type of the evaluator argument is not str or dict.

Methods

init_evaluator

Initialize an evaluator for the ensemble.

predict

Compute the prediction of the ensemble.

predictions_from_predictors

Compute the predictions of a list of predictors.

init_evaluator()[source]#

Initialize an evaluator for the ensemble.

Returns:

An evaluator instance.

Return type:

Evaluator

predict(X: ndarray)[source]#

Compute the prediction of the ensemble.

Parameters:

X (np.ndarray) – the input query for the prediction.

Returns:

the target prediction.

Return type:

np.ndarray

predictions_from_predictors(X: ndarray, predictors: Sequence[Predictor | PredictorLoader])[source]#

Compute the predictions of a list of predictors.

Parameters:
  • X (np.ndarray) – the input query for the predictions.

  • predictors (Sequence[Predictor]) – the list of predictors to compute the predictions.

Returns:

the sequence of predictions in the same order that the list of predictors.

Return type:

List[np.ndarray]