Skip to content

Commit

Permalink
revised the evaluators documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
KrissiHub committed Jan 19, 2024
1 parent 1396581 commit 3e45b16
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 62 deletions.
7 changes: 2 additions & 5 deletions deepcave/evaluators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@
## Modules
----------
fanova
This module provides a tool for assessing the importance of an algorithms hyperparameters (HPs).
This module provides a tool for assessing the importance of an algorithms Hyperparameters.
footprint
This module provides utilities for creating a footprint of a model.
This module provides utilities for creating a footprint of a run.
lpi
This module provides utilties to calculate the local parameter importance (LPM).
## Packages
epm
"""
9 changes: 5 additions & 4 deletions deepcave/evaluators/epm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
## Modules
----------
fanova_forest
This module provides utilities for conducting feature analysis.
The module provides utilities for creating a fANOVA forest.
random_forest
This module is used for training and using a Random Forest Regression model.
This module can be used for training and using a Random Forest Regression model.
random_forest_surrogate
This module provides an implementation for a RandomForest Surrogate model.
This module provides a RandomForest Surrogate model.
utils
Return types and bounds of hyperparameter (HP).
This module provides a utility to get the types
as well as the bounds of the Hyperparameters.
"""
25 changes: 12 additions & 13 deletions deepcave/evaluators/epm/fanova_forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
"""
# FanovaForest
The module provides utilities for conducting feature analysis.
The module provides utilities for creating a fANOVA forest.
It includes a FanovaForest wrapper for pyrfr, which facilitates this analysis.
The functionality of a FanovaForest Regression model is wrapped.
FanovaForest can be used for analyzing and quantifying the features of a dataset.
It includes a FanovaForest wrapper for pyrfr.
fANOVA can be used for analyzing the importances of Hyperparameters.
## Classes
- FanovaForest: A fanova forest wrapper for pyrfr.
- FanovaForest: A fANOVA forest wrapper for pyrfr.
"""

from typing import Any, Dict, List, Optional, Tuple, Union
Expand All @@ -27,21 +26,20 @@

class FanovaForest(RandomForest):
"""
A fanova forest wrapper for pyrfr.
A fANOVA forest wrapper for pyrfr.
Properties
----------
cutoffs : Tuple[float, float]
The cutoff of the model.
The cutoffs of the model.
percentiles : NDArray[floating]
The percentiles of the data points Y.
all_midpoints : List
All midpoints tree wise for the whole forest.
all_sizes : List
All interval sized tree wise for the whole forest.
All interval sizes tree wise for the whole forest.
bounds : List[Tuple[float, float]
Stores feature bounds.
Can be used as categorical or continuous parameter.
trees_total_variances : List
The total variances of the trees.
trees_total_variance : Any
Expand All @@ -53,7 +51,7 @@ class FanovaForest(RandomForest):
V_U_individual : Dict[Tuple[int, ...], List[Any]]
Store variance-related information for individual subsets.
n_params : int
The number of parameters to sample.
The number of Hyperparameters to sample.
"""

def __init__(
Expand Down Expand Up @@ -167,12 +165,13 @@ def compute_marginals(
self, hp_ids: Union[List[int], Tuple[int, ...]], depth: int = 1
) -> Tuple[Dict[Tuple[int, ...], List[Any]], Dict[Tuple[int, ...], List[Any]],]:
"""
Return the marginal of selected parameters.
Return the marginal of selected Hyperparameters.
Parameters
----------
hp_ids: Union[List[int], Tuple[int, ...]]
Contains the indices of the configspace for the selected parameters (starts with 0).
Contains the indices of the configspace for the selected Hyperparameters
(starts with 0).
depth: int
The depth of the marginalization.
Default value is 1.
Expand All @@ -181,7 +180,7 @@ def compute_marginals(
-------
Tuple[Dict[Tuple[int, ...], List[Any]],
Dict[Tuple[int, ...], List[Any]],
The marginal of selected parameters.
The marginal of selected Hyperparameters.
"""
if not isinstance(hp_ids, tuple):
hp_ids = tuple(hp_ids)
Expand Down
20 changes: 10 additions & 10 deletions deepcave/evaluators/epm/random_forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"""
# RandomForest
This module is used for training and using a Random Forest Regression model.
This module can be used for training and using a Random Forest Regression model.
A pyrfr wrapper is used for simplification.
Expand All @@ -12,7 +12,6 @@
## Constants
VERY_SMALL_NUMBER : float
PYRFR_MAPPING : Dict[str, str]
}
"""

from typing import Any, Dict, List, Optional, Tuple, Union
Expand Down Expand Up @@ -68,11 +67,11 @@ class RandomForest:
seed : int
The seed. If not provided, it is random.
types : List[int]
The types of the hyperparameters (HPS).
The types of the Hyperparameters.
bounds : List[Tuple[float, float]]
The bounds of the hyperparameters (HPS).
The bounds of the Hyperparameters.
n_params : int
The number of hyperparameters (HPS) in the configuration space.
The number of Hyperparameters in the configuration space.
n_features : int
The number of features.
pca_components : int
Expand Down Expand Up @@ -202,7 +201,7 @@ def _impute_inactive(self, X: np.ndarray) -> np.ndarray:
Raises
------
ValueError
If hyperparameter (HP) is not supported.
If Hyperparameter is not supported.
"""
conditional: Dict[int, bool] = {}
impute_values: Dict[int, float] = {}
Expand Down Expand Up @@ -296,7 +295,7 @@ def train(self, X: np.ndarray, Y: np.ndarray) -> None:
"""
Train the random forest on X and Y.
Transforms X if principal component analysis (PCA) is applied.
Transform X if principal component analysis (PCA) is applied.
Afterwards, `_train` is called.
Parameters
Expand Down Expand Up @@ -403,7 +402,8 @@ def _predict(self, X: np.ndarray) -> Tuple[np.ndarray, np.ndarray]:
Parameters
----------
X : np.ndarray [n_samples, n_features (config + instance features)]
X : np.ndarray
[n_samples, n_features (config + instance features)]
Returns
-------
Expand Down Expand Up @@ -457,7 +457,7 @@ def predict_marginalized(self, X: np.ndarray) -> Tuple[np.ndarray, np.ndarray]:
"""
Predict mean and variance marginalized over all instances.
Returns the predictive mean and variance marginalized over all
Return the predictive mean and variance marginalized over all
instances for a set of configurations.
Parameters
Expand Down Expand Up @@ -525,7 +525,7 @@ def get_leaf_values(self, x: np.ndarray) -> regression.binary_rss_forest:
Parameters
----------
x : np.ndarray
Input data points.
Input data array.
Returns
-------
Expand Down
2 changes: 1 addition & 1 deletion deepcave/evaluators/epm/random_forest_surrogate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"""
# RandomForest Surrogate
This module provides an implementation for a RandomForest Surrogate model.
This module provides a RandomForest Surrogate model.
Mean and standard deviation values can be predicted for a given input with this module.
Expand Down
13 changes: 7 additions & 6 deletions deepcave/evaluators/epm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"""
# Utils
This module provides a utility to get the types of the hyperparameters (HPs).
This module provides a utility to get the types
as well as the bounds of the Hyperparameters.
"""

import typing
Expand All @@ -27,9 +28,9 @@ def get_types(
instance_features: typing.Optional[np.ndarray] = None,
) -> typing.Tuple[typing.List[int], typing.List[typing.Tuple[float, float]]]:
"""
Return the types of the hyperparameters (HPs).
Return the types of the Hyperparameters.
Also return the bounds of the hyperparameters (HPs) and instance features.
Also return the bounds of the Hyperparameters and instance features.
Parameters
----------
Expand All @@ -42,14 +43,14 @@ def get_types(
Returns
-------
Tuple[typing.List[int], List[Tuple[float, float]]]
The types of the hyperparameters (HPs), as well as the bounds and instance features.
The types of the Hyperparameters, as well as the bounds and instance features.
Raises
------
ValueError
Inactive parameters not supported for Beta and Normal Hyperparameters (HPs).
Inactive parameters not supported for Beta and Normal Hyperparameters.
TypeError
If the hyperparameter (HP) Type is unknown.
If the Hyperparameter Type is unknown.
"""
# Extract types vector for rf from config space and the bounds
types = [0] * len(config_space.get_hyperparameters())
Expand Down
16 changes: 8 additions & 8 deletions deepcave/evaluators/fanova.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"""
# fANOVA
This module provides a tool for assessing the importance of an algorithms hyperparameters (HPs).
This module provides a tool for assessing the importance of an algorithms Hyperparameters.
Utilities provide calculation of the data wrt the budget and train the forest on the encoded data.
Expand Down Expand Up @@ -35,9 +35,9 @@ class fANOVA:
cs : ConfigurationSpace
The configuration space of the run.
hps : List[Hyperparameters]
The hyperparameters (HPs) of the configuration space.
The Hyperparameters of the configuration space.
hp_names : List[str]
The corresponding names of the hyperparameters (HPs).
The corresponding names of the Hyperparameters.
n_trees : int
The number of trees.
"""
Expand Down Expand Up @@ -100,7 +100,7 @@ def get_importances(
self, hp_names: Optional[List[str]] = None, depth: int = 1, sort: bool = True
) -> Dict[Union[str, Tuple[str, ...]], Tuple[float, float, float, float]]:
"""
Return the importance scores from the passed hyperparameter (HP) names.
Return the importance scores from the passed Hyperparameter names.
Warning
-------
Expand All @@ -109,17 +109,17 @@ def get_importances(
Parameters
----------
hp_names : Optional[List[str]]
Selected hyperparameter (HP) names to get the importance scores from. If None, all
hyperparameters (HPs) of the configuration space are used.
Selected Hyperparameter names to get the importance scores from. If None, all
Hyperparameters of the configuration space are used.
depth : int, optional
How often dimensions should be combined. By default 1.
sort : bool, optional
Whether the hyperparameters (HPs) should be sorted by importance. By default True.
Whether the Hyperparameters should be sorted by importance. By default True.
Returns
-------
Dict[Union[str, Tuple[str, ...]], Tuple[float, float, float, float]]
Dictionary with hyperparameter (HP) names and the corresponding importance scores.
Dictionary with Hyperparameter names and the corresponding importance scores.
The values are tuples of the form (mean individual, var individual, mean total,
var total). Note that individual and total are the same if depth is 1.
Expand Down
16 changes: 8 additions & 8 deletions deepcave/evaluators/footprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
"""
# Footprint
This module provides utilities for creating a footprint of a model.
This module provides utilities for creating a footprint of a run.
It uses multidimensional scaling (MDS).
It also provides utilities to get the surface and the points of the plot.
## Classes
- Footprint: Can train and create a footprint of a model.
- Footprint: Can train and create a footprint of a run.
"""

from typing import List, Optional, Tuple, Union
Expand All @@ -34,7 +34,7 @@

class Footprint:
"""
Can train and create a footprint of a model.
Can train and create a footprint of a run.
It uses multidimensional scaling (MDS).
Provides utilities to get the surface and the points of the plot.
Expand Down Expand Up @@ -336,7 +336,7 @@ def _get_max_distance(self) -> float:
"""
Calculate the maximum distance between all configs.
Basically, the number of hyperparameters (HPS) are just counted.
Basically, the number of Hyperparameters are just counted.
Returns
-------
Expand Down Expand Up @@ -514,12 +514,12 @@ def _get_depth(self, hp: Hyperparameter) -> int:
Parameters
----------
hp: Hyperparameter
name of parameter to inspect
name of Hyperparameter to inspect
Returns
-------
int
Depth of the hyperparameter (HP).
Depth of the Hyperparameter.
"""
parents = self.cs.get_parents_of(hp)
if not parents:
Expand Down Expand Up @@ -562,7 +562,7 @@ def _get_mds(self) -> np.ndarray:

def _train_on_objective(self, X: np.ndarray, Y: np.ndarray) -> None:
"""
Trains the random forest on the performance.
Train the random forest on the performance.
Parameters
----------
Expand All @@ -577,7 +577,7 @@ def _train_on_objective(self, X: np.ndarray, Y: np.ndarray) -> None:

def _train_on_areas(self) -> None:
"""
Trains the random forest on the "valid" areas.
Train the random forest on the "valid" areas.
Raises
------
Expand Down
14 changes: 7 additions & 7 deletions deepcave/evaluators/lpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,21 @@ class LPI:
Properties
----------
run : AbstractRun
The AbstractRun ro calculate the importance from.
The AbstractRun to get the importance from.
cs : ConfigurationSpace
The configuration space of the run.
hp_names : List[str]
The names of the hyperparameters (HPs).
The names of the Hyperparameters.
variances : Dict[Any, list]
The overall variances per tree.
importances : dict
The importances of the hyperparameters (HPs).
The importances of the Hyperparameters.
continuous_neighbors : int
The number of neighbors chosen for continuous hyperparameters (HPs).
The number of neighbors chosen for continuous Hyperparameters.
incumbent : Configuration
The incumbent of the run.
default : Configuration
A configuration containing hyperparameters (HPs) with default values.
A configuration containing Hyperparameters with default values.
incumbent_array : numpy.ndarray
The internal vector representation of the incumbent.
seed : int
Expand Down Expand Up @@ -231,12 +231,12 @@ def get_importances(self, hp_names: List[str]) -> Dict[str, Tuple[float, float]]
Parameters
----------
hp_names : List[str]
Selected hyperparameter (HP) names to get the importance scores from.
Selected Hyperparameter names to get the importance scores from.
Returns
-------
importances : Dict[str, Tuple[float, float]]
Hyperparameter (HP) name and mean+var importance.
Hyperparameter name and mean+var importance.
Raises
------
Expand Down

0 comments on commit 3e45b16

Please sign in to comment.