smac.epm.rf_with_instances module

class smac.epm.rf_with_instances.RandomForestWithInstances(configspace: ConfigSpace.configuration_space.ConfigurationSpace, types: List[int], bounds: List[Tuple[float, float]], seed: int, log_y: bool = False, num_trees: int = 10, do_bootstrapping: bool = True, n_points_per_tree: int = - 1, ratio_features: float = 0.8333333333333334, min_samples_split: int = 3, min_samples_leaf: int = 3, max_depth: int = 1048576, eps_purity: float = 1e-08, max_num_nodes: int = 1048576, instance_features: Optional[numpy.ndarray] = None, pca_components: Optional[int] = None)

Bases: smac.epm.base_rf.BaseModel

Random forest that takes instance features into account.

rf_opts

Random forest hyperparameter

Type

regression.rf_opts

n_points_per_tree
Type

int

rf

Only available after training

Type

regression.binary_rss_forest

hypers

List of random forest hyperparameters

Type

list

unlog_y
Type

bool

seed
Type

int

types
Type

np.ndarray

bounds
Type

list

rng
Type

np.random.RandomState

logger
Type

logging.logger

_init_data_container(X: numpy.ndarray, y: numpy.ndarray) pyrfr.regression.default_data_container

Fills a pyrfr default data container, s.t. the forest knows categoricals and bounds for continous data

Parameters
  • X (np.ndarray [n_samples, n_features]) – Input data points

  • y (np.ndarray [n_samples, ]) – Corresponding target values

Returns

data – The filled data container that pyrfr can interpret

Return type

regression.default_data_container

_predict(X: numpy.ndarray, cov_return_type: Optional[str] = 'diagonal_cov') Tuple[numpy.ndarray, numpy.ndarray]

Predict means and variances for given X.

Parameters
  • X (np.ndarray of shape = [n_samples,) – n_features (config + instance features)]

  • cov_return_type (typing.Optional[str]) – Specifies what to return along with the mean. Refer predict() for more information.

Returns

  • means (np.ndarray of shape = [n_samples, 1]) – Predictive mean

  • vars (np.ndarray of shape = [n_samples, 1]) – Predictive variance

_train(X: numpy.ndarray, y: numpy.ndarray) smac.epm.rf_with_instances.RandomForestWithInstances

Trains the random forest on X and y.

Parameters
  • X (np.ndarray [n_samples, n_features (config + instance features)]) – Input data points.

  • y (np.ndarray [n_samples, ]) – The corresponding target values.

Returns

Return type

self

predict_marginalized_over_instances(X: numpy.ndarray) Tuple[numpy.ndarray, numpy.ndarray]

Predict mean and variance marginalized over all instances.

Returns the predictive mean and variance marginalised over all instances for a set of configurations.

Note

This method overwrites the same method of ~smac.epm.base_epm.AbstractEPM; the following method is random forest specific and follows the SMAC2 implementation; it requires no distribution assumption to marginalize the uncertainty estimates

Parameters

X (np.ndarray) – [n_samples, n_features (config)]

Returns

  • means (np.ndarray of shape = [n_samples, 1]) – Predictive mean

  • vars (np.ndarray of shape = [n_samples, 1]) – Predictive variance