data_models.domain.features.Inputs

data_models.domain.features.Inputs()

Container of input features, only input features are allowed.

Attributes

Name Type Description
features List(Inputs list of the features.

Methods

Name Description
get_bounds Returns the boundaries of the optimization problem based on the transformations
get_categorical_combinations Get a list of tuples pairing the feature keys with a list of valid categories
get_feature_indices Returns a list of indices of the given feature key list.
get_fixed Gets all features in self that are fixed and returns them as new
get_free Gets all features in self that are not fixed and returns them as
get_number_of_categorical_combinations Get the total number of unique categorical combinations.
inverse_transform Transform a dataframe back to the original representations.
is_fulfilled Check if the provided experiments fulfill all constraints defined on the
sample Draw sobol samples
transform Transform a dataframe to the representation specified in specs.
validate_candidates Validate a pandas dataframe with input feature values.

get_bounds

data_models.domain.features.Inputs.get_bounds(
    specs,
    experiments=None,
    reference_experiment=None,
)

Returns the boundaries of the optimization problem based on the transformations defined in the specs dictionary.

Parameters

Name Type Description Default
specs InputTransformSpecs Dictionary specifying which input feature is transformed by which encoder. required
experiments Optional[pd.DataFrame] Dataframe with input features. If provided the real feature bounds are returned based on both the opt. feature bounds and the extreme points in the dataframe. Defaults to None, None
reference_experiment Optional[pd.Series] If a reference experiment provided, None

Raises

Name Type Description
ValueError If a feature type is not known.
ValueError If no transformation is provided for a categorical feature.

Returns

Name Type Description
Tuple[List[float], List[float]] Tuple[List[float], List[float]]: list with lower bounds, list with upper bounds.

get_categorical_combinations

data_models.domain.features.Inputs.get_categorical_combinations(
    include=Input,
    exclude=None,
)

Get a list of tuples pairing the feature keys with a list of valid categories

Parameters

Name Type Description Default
include Feature Features to be included. Defaults to Input. Input
exclude Feature Features to be excluded, e.g. subclasses of the included features. Defaults to None. None

Returns

Name Type Description
list[tuple[tuple[str, float] | tuple[str, str], …]] List[(str, List[str])]: Returns a list of tuples pairing the feature keys with a list of valid categories (str)

get_feature_indices

data_models.domain.features.Inputs.get_feature_indices(specs, feature_keys)

Returns a list of indices of the given feature key list.

Parameters

Name Type Description Default
specs InputTransformSpecs Dictionary specifying which input feature is transformed by which encoder. required
feature_keys List[str] List of feature keys. required

Returns

Name Type Description
List[int] List[int]: The list of indices.

get_fixed

data_models.domain.features.Inputs.get_fixed()

Gets all features in self that are fixed and returns them as new Inputs object.

Returns

Name Type Description
Inputs Inputs Input features object containing only fixed features.

get_free

data_models.domain.features.Inputs.get_free()

Gets all features in self that are not fixed and returns them as new Inputs object.

Returns

Name Type Description
Inputs Inputs Input features object containing only non-fixed features.

get_number_of_categorical_combinations

data_models.domain.features.Inputs.get_number_of_categorical_combinations(
    include=Input,
    exclude=None,
)

Get the total number of unique categorical combinations.

This is used before generating all of the categorical combinations, which may cause memory issues if there are too many.

Parameters

Name Type Description Default
include Feature Features to be included. Defaults to Input. Input
exclude Feature Features to be excluded, e.g. subclasses of the included features. Defaults to None. None

Returns: int: Returns the number of unique combinations of discrete and categorical features.

inverse_transform

data_models.domain.features.Inputs.inverse_transform(experiments, specs)

Transform a dataframe back to the original representations.

The original applied transformation has to be provided via the specs dictionary. Currently only input categoricals are supported.

Parameters

Name Type Description Default
experiments pd.DataFrame Transformed data dataframe. required
specs InputTransformSpecs Dictionary specifying which input feature is transformed by which encoder. required

Returns

Name Type Description
pd.DataFrame pd.DataFrame: Back transformed dataframe. Only input features are included.

is_fulfilled

data_models.domain.features.Inputs.is_fulfilled(experiments)

Check if the provided experiments fulfill all constraints defined on the input features itself like the bounds or the allowed categories.

Parameters

Name Type Description Default
experiments pd.DataFrame Dataframe with input features. required

Returns

Name Type Description
pd.Series Series with boolean values indicating if the experiments fulfill the constraints on the input features.

sample

data_models.domain.features.Inputs.sample(
    n=1,
    method=SamplingMethodEnum.UNIFORM,
    seed=None,
)

Draw sobol samples

Parameters

Name Type Description Default
n int Number of samples, has to be larger than 0. Defaults to 1. 1
method SamplingMethodEnum Method to use, implemented methods are UNIFORM, SOBOL and LHS. Defaults to UNIFORM. SamplingMethodEnum.UNIFORM
seed int random seed. Defaults to None. None

Returns

Name Type Description
pd.DataFrame pd.DataFrame: Dataframe containing the samples.

transform

data_models.domain.features.Inputs.transform(experiments, specs)

Transform a dataframe to the representation specified in specs.

Currently only input categoricals are supported.

Parameters

Name Type Description Default
experiments pd.DataFrame Data dataframe to be transformed. required
specs InputTransformSpecs Dictionary specifying which input feature is transformed by which encoder. required

Returns

Name Type Description
pd.DataFrame pd.DataFrame: Transformed dataframe. Only input features are included.

validate_candidates

data_models.domain.features.Inputs.validate_candidates(candidates)

Validate a pandas dataframe with input feature values.

Parameters

Name Type Description Default
candidates pd.Dataframe Inputs to validate. required

Raises

Name Type Description
ValueError Raises a Valueerror if a feature based validation raises an exception.

Returns

Name Type Description
pd.DataFrame pd.Dataframe: Validated dataframe