plaid.problem_definition¶
Implementation of the ProblemDefinition class.
Attributes¶
Classes¶
Gathers all necessary informations to define a learning problem. |
Module Contents¶
- class ProblemDefinition(path: str | pathlib.Path | None = None, directory_path: str | pathlib.Path | None = None)[source]¶
Bases:
objectGathers all necessary informations to define a learning problem.
Initialize an empty
ProblemDefinition.Use
add_inputsoradd_output_scalars_namesto feed theProblemDefinition- Parameters:
Example
from plaid import ProblemDefinition # 1. Create empty instance of ProblemDefinition problem_definition = ProblemDefinition() print(problem_definition) >>> ProblemDefinition() # 2. Load problem definition and create ProblemDefinition instance problem_definition = ProblemDefinition("path_to_plaid_prob_def") print(problem_definition) >>> ProblemDefinition(input_scalars_names=['s_1'], output_scalars_names=['s_2'], input_meshes_names=['mesh'], task='regression')
- in_features_identifiers: list[plaid.types.feature_types.FeatureIdentifier] = [][source]¶
- out_features_identifiers: list[plaid.types.feature_types.FeatureIdentifier] = [][source]¶
- get_task() str[source]¶
Get the authorized task. None if not defined.
- Returns:
The authorized task, such as “regression” or “classification”.
- Return type:
- set_task(task: str) None[source]¶
Set the authorized task.
- Parameters:
task (str) – The authorized task to be set, such as “regression” or “classification”.
- get_split(indices_name: str | None = None) plaid.types.IndexType | dict[str, plaid.types.IndexType][source]¶
Get the split indices. This function returns the split indices, either for a specific split with the provided indices_name or all split indices if indices_name is not specified.
- Parameters:
indices_name (str, optional) – The name of the split for which indices are requested. Defaults to None.
- Raises:
KeyError – If indices_name is specified but not found among split names.
- Returns:
If indices_name is provided, it returns the indices for that split (IndexType). If indices_name is not provided, it returns a dictionary mapping split names (str) to their respective indices (IndexType).
- Return type:
Example
from plaid import ProblemDefinition problem = ProblemDefinition() # [...] split_indices = problem.get_split() print(split_indices) >>> {'train': [0, 1, 2, ...], 'test': [100, 101, ...]} test_indices = problem.get_split('test') print(test_indices) >>> [100, 101, ...]
- set_split(split: dict[str, plaid.types.IndexType]) None[source]¶
Set the split indices. This function allows you to set the split indices by providing a dictionary mapping split names (str) to their respective indices (IndexType).
Example
from plaid import ProblemDefinition problem = ProblemDefinition() new_split = {'train': [0, 1, 2], 'test': [3, 4]} problem.set_split(new_split)
- get_in_features_identifiers() list[plaid.types.feature_types.FeatureIdentifier][source]¶
Get the input features identifiers of the problem.
- Returns:
A list of input feature identifiers.
- Return type:
Example
from plaid.problem_definition import ProblemDefinition problem = ProblemDefinition() # [...] in_features_identifiers = problem.get_in_features_identifiers() print(in_features_identifiers) >>> ['omega', 'pressure']
- add_in_features_identifiers(inputs: list[plaid.types.feature_types.FeatureIdentifier]) None[source]¶
Add input features identifiers to the problem.
- Parameters:
inputs (list[FeatureIdentifier]) – A list of input feature identifiers to add.
- Raises:
ValueError – If some
inputsare redondant.
Example
from plaid.problem_definition import ProblemDefinition problem = ProblemDefinition() in_features_identifiers = ['omega', 'pressure'] problem.add_in_features_identifiers(in_features_identifiers)
- add_in_feature_identifier(input: plaid.types.feature_types.FeatureIdentifier) None[source]¶
Add an input feature identifier or identifier to the problem.
- Parameters:
input (FeatureIdentifier) – The identifier or identifier of the input feature to add.
- Raises:
ValueError – If the specified input feature is already in the list of inputs.
Example
from plaid.problem_definition import ProblemDefinition problem = ProblemDefinition() input_identifier = 'pressure' problem.add_in_feature_identifier(input_identifier)
- filter_in_features_identifiers(identifiers: list[plaid.types.feature_types.FeatureIdentifier]) list[plaid.types.feature_types.FeatureIdentifier][source]¶
Filter and get input features features corresponding to a sorted list of identifiers.
- Parameters:
identifiers (list[FeatureIdentifier]) – A list of identifiers for which to retrieve corresponding input features.
- Returns:
A sorted list of input feature identifiers or categories corresponding to the provided identifiers.
- Return type:
Example
from plaid.problem_definition import ProblemDefinition problem = ProblemDefinition() # [...] features_identifiers = ['omega', 'pressure', 'temperature'] input_features = problem.filter_in_features_identifiers(features_identifiers) print(input_features) >>> ['omega', 'pressure']
- get_out_features_identifiers() list[plaid.types.feature_types.FeatureIdentifier][source]¶
Get the output features identifiers of the problem.
- Returns:
A list of output feature identifiers.
- Return type:
Example
from plaid.problem_definition import ProblemDefinition problem = ProblemDefinition() # [...] outputs_identifiers = problem.get_out_features_identifiers() print(outputs_identifiers) >>> ['compression_rate', 'in_massflow', 'isentropic_efficiency']
- add_out_features_identifiers(outputs: list[plaid.types.feature_types.FeatureIdentifier]) None[source]¶
Add output features identifiers to the problem.
- Parameters:
outputs (list[FeatureIdentifier]) – A list of output feature identifiers to add.
- Raises:
ValueError – if some
outputsare redondant.
Example
from plaid.problem_definition import ProblemDefinition problem = ProblemDefinition() out_features_identifiers = ['compression_rate', 'in_massflow', 'isentropic_efficiency'] problem.add_out_features_identifiers(out_features_identifiers)
- add_out_feature_identifier(output: plaid.types.feature_types.FeatureIdentifier) None[source]¶
Add an output feature identifier or identifier to the problem.
- Parameters:
output (FeatureIdentifier) – The identifier or identifier of the output feature to add.
- Raises:
ValueError – If the specified output feature is already in the list of outputs.
Example
from plaid.problem_definition import ProblemDefinition problem = ProblemDefinition() out_features_identifiers = 'pressure' problem.add_out_feature_identifier(out_features_identifiers)
- filter_out_features_identifiers(identifiers: list[plaid.types.feature_types.FeatureIdentifier]) list[plaid.types.feature_types.FeatureIdentifier][source]¶
Filter and get output features corresponding to a sorted list of identifiers.
- Parameters:
identifiers (list[FeatureIdentifier]) – A list of identifiers for which to retrieve corresponding output features.
- Returns:
A sorted list of output feature identifiers or categories corresponding to the provided identifiers.
- Return type:
Example
from plaid.problem_definition import ProblemDefinition problem = ProblemDefinition() # [...] features_identifiers = ['compression_rate', 'in_massflow', 'isentropic_efficiency'] output_features = problem.filter_out_features_identifiers(features_identifiers) print(output_features) >>> ['in_massflow']
- get_input_scalars_names() list[str][source]¶
Get the input scalars names of the problem.
Example
from plaid import ProblemDefinition problem = ProblemDefinition() # [...] input_scalars_names = problem.get_input_scalars_names() print(input_scalars_names) >>> ['omega', 'pressure']
- add_input_scalars_names(inputs: list[str]) None[source]¶
Add input scalars names to the problem.
- Parameters:
- Raises:
ValueError – If some
inputsare redondant.
Example
from plaid import ProblemDefinition problem = ProblemDefinition() input_scalars_names = ['omega', 'pressure'] problem.add_input_scalars_names(input_scalars_names)
- add_input_scalar_name(input: str) None[source]¶
Add an input scalar name to the problem.
- Parameters:
input (str) – The name of the input feature to add.
- Raises:
ValueError – If the specified input feature is already in the list of inputs.
Example
from plaid import ProblemDefinition problem = ProblemDefinition() input_name = 'pressure' problem.add_input_scalar_name(input_name)
- filter_input_scalars_names(names: list[str]) list[str][source]¶
Filter and get input scalars features corresponding to a list of names.
- Parameters:
names (list[str]) – A list of names for which to retrieve corresponding input features.
- Returns:
A sorted list of input feature names or categories corresponding to the provided names.
- Return type:
Example
from plaid import ProblemDefinition problem = ProblemDefinition() # [...] scalars_names = ['omega', 'pressure', 'temperature'] input_features = problem.filter_input_scalars_names(scalars_names) print(input_features) >>> ['omega', 'pressure']
- get_output_scalars_names() list[str][source]¶
Get the output scalars names of the problem.
Example
from plaid import ProblemDefinition problem = ProblemDefinition() # [...] outputs_names = problem.get_output_scalars_names() print(outputs_names) >>> ['compression_rate', 'in_massflow', 'isentropic_efficiency']
- add_output_scalars_names(outputs: list[str]) None[source]¶
Add output scalars names to the problem.
- Parameters:
outputs (list[str]) – A list of output feature names to add.
- Raises:
ValueError – if some
outputsare redondant.
Example
from plaid import ProblemDefinition problem = ProblemDefinition() output_scalars_names = ['compression_rate', 'in_massflow', 'isentropic_efficiency'] problem.add_output_scalars_names(output_scalars_names)
- add_output_scalar_name(output: str) None[source]¶
Add an output scalar name to the problem.
- Parameters:
output (str) – The name of the output feature to add.
- Raises:
ValueError – If the specified output feature is already in the list of outputs.
Example
from plaid import ProblemDefinition problem = ProblemDefinition() output_scalars_names = 'pressure' problem.add_output_scalar_name(output_scalars_names)
- filter_output_scalars_names(names: list[str]) list[str][source]¶
Filter and get output features corresponding to a list of names.
- Parameters:
names (list[str]) – A list of names for which to retrieve corresponding output features.
- Returns:
A sorted list of output feature names or categories corresponding to the provided names.
- Return type:
Example
from plaid import ProblemDefinition problem = ProblemDefinition() # [...] scalars_names = ['compression_rate', 'in_massflow', 'isentropic_efficiency'] output_features = problem.filter_output_scalars_names(scalars_names) print(output_features) >>> ['in_massflow']
- get_input_fields_names() list[str][source]¶
Get the input fields names of the problem.
Example
from plaid import ProblemDefinition problem = ProblemDefinition() # [...] input_fields_names = problem.get_input_fields_names() print(input_fields_names) >>> ['omega', 'pressure']
- add_input_fields_names(inputs: list[str]) None[source]¶
Add input fields names to the problem.
- Parameters:
- Raises:
ValueError – If some
inputsare redondant.
Example
from plaid import ProblemDefinition problem = ProblemDefinition() input_fields_names = ['omega', 'pressure'] problem.add_input_fields_names(input_fields_names)
- add_input_field_name(input: str) None[source]¶
Add an input field name to the problem.
- Parameters:
input (str) – The name of the input feature to add.
- Raises:
ValueError – If the specified input feature is already in the list of inputs.
Example
from plaid import ProblemDefinition problem = ProblemDefinition() input_name = 'pressure' problem.add_input_field_name(input_name)
- filter_input_fields_names(names: list[str]) list[str][source]¶
Filter and get input fields features corresponding to a list of names.
- Parameters:
names (list[str]) – A list of names for which to retrieve corresponding input features.
- Returns:
A sorted list of input feature names or categories corresponding to the provided names.
- Return type:
Example
from plaid import ProblemDefinition problem = ProblemDefinition() # [...] input_fields_names = ['omega', 'pressure', 'temperature'] input_features = problem.filter_input_fields_names(input_fields_names) print(input_features) >>> ['omega', 'pressure']
- get_output_fields_names() list[str][source]¶
Get the output fields names of the problem.
Example
from plaid import ProblemDefinition problem = ProblemDefinition() # [...] outputs_names = problem.get_output_fields_names() print(outputs_names) >>> ['compression_rate', 'in_massflow', 'isentropic_efficiency']
- add_output_fields_names(outputs: list[str]) None[source]¶
Add output fields names to the problem.
- Parameters:
outputs (list[str]) – A list of output feature names to add.
- Raises:
ValueError – if some
outputsare redondant.
Example
from plaid import ProblemDefinition problem = ProblemDefinition() output_fields_names = ['compression_rate', 'in_massflow', 'isentropic_efficiency'] problem.add_output_fields_names(output_fields_names)
- add_output_field_name(output: str) None[source]¶
Add an output field name to the problem.
- Parameters:
output (str) – The name of the output feature to add.
- Raises:
ValueError – If the specified output feature is already in the list of outputs.
Example
from plaid import ProblemDefinition problem = ProblemDefinition() output_fields_names = 'pressure' problem.add_output_field_name(output_fields_names)
- filter_output_fields_names(names: list[str]) list[str][source]¶
Filter and get output features corresponding to a list of names.
- Parameters:
names (list[str]) – A list of names for which to retrieve corresponding output features.
- Returns:
A sorted list of output feature names or categories corresponding to the provided names.
- Return type:
Example
from plaid import ProblemDefinition problem = ProblemDefinition() # [...] output_fields_names = ['compression_rate', 'in_massflow', 'isentropic_efficiency'] output_features = problem.filter_output_fields_names(output_fields_names) print(output_features) >>> ['in_massflow']
- get_input_timeseries_names() list[str][source]¶
Get the input timeseries names of the problem.
Example
from plaid import ProblemDefinition problem = ProblemDefinition() # [...] input_timeseries_names = problem.get_input_timeseries_names() print(input_timeseries_names) >>> ['omega', 'pressure']
- add_input_timeseries_names(inputs: list[str]) None[source]¶
Add input timeseries names to the problem.
- Parameters:
- Raises:
ValueError – If some
inputsare redondant.
Example
from plaid import ProblemDefinition problem = ProblemDefinition() input_timeseries_names = ['omega', 'pressure'] problem.add_input_timeseries_names(input_timeseries_names)
- add_input_timeseries_name(input: str) None[source]¶
Add an input timeseries name to the problem.
- Parameters:
input (str) – The name of the input feature to add.
- Raises:
ValueError – If the specified input feature is already in the list of inputs.
Example
from plaid import ProblemDefinition problem = ProblemDefinition() input_name = 'pressure' problem.add_input_timeseries_name(input_name)
- filter_input_timeseries_names(names: list[str]) list[str][source]¶
Filter and get input timeseries features corresponding to a list of names.
- Parameters:
names (list[str]) – A list of names for which to retrieve corresponding input features.
- Returns:
A sorted list of input feature names or categories corresponding to the provided names.
- Return type:
Example
from plaid import ProblemDefinition problem = ProblemDefinition() # [...] input_timeseries_names = ['omega', 'pressure', 'temperature'] input_features = problem.filter_input_timeseries_names(input_timeseries_names) print(input_features) >>> ['omega', 'pressure']
- get_output_timeseries_names() list[str][source]¶
Get the output timeseries names of the problem.
Example
from plaid import ProblemDefinition problem = ProblemDefinition() # [...] outputs_names = problem.get_output_timeseries_names() print(outputs_names) >>> ['compression_rate', 'in_massflow', 'isentropic_efficiency']
- add_output_timeseries_names(outputs: list[str]) None[source]¶
Add output timeseries names to the problem.
- Parameters:
outputs (list[str]) – A list of output feature names to add.
- Raises:
ValueError – if some
outputsare redondant.
Example
from plaid import ProblemDefinition problem = ProblemDefinition() output_timeseries_names = ['compression_rate', 'in_massflow', 'isentropic_efficiency'] problem.add_output_timeseries_names(output_timeseries_names)
- add_output_timeseries_name(output: str) None[source]¶
Add an output timeseries name to the problem.
- Parameters:
output (str) – The name of the output feature to add.
- Raises:
ValueError – If the specified output feature is already in the list of outputs.
Example
from plaid import ProblemDefinition problem = ProblemDefinition() output_timeseries_names = 'pressure' problem.add_output_timeseries_name(output_timeseries_names)
- filter_output_timeseries_names(names: list[str]) list[str][source]¶
Filter and get output features corresponding to a list of names.
- Parameters:
names (list[str]) – A list of names for which to retrieve corresponding output features.
- Returns:
A sorted list of output feature names or categories corresponding to the provided names.
- Return type:
Example
from plaid import ProblemDefinition problem = ProblemDefinition() # [...] output_timeseries_names = ['compression_rate', 'in_massflow', 'isentropic_efficiency'] output_features = problem.filter_output_timeseries_names(output_timeseries_names) print(output_features) >>> ['in_massflow']
- get_input_meshes_names() list[str][source]¶
Get the input meshes names of the problem.
Example
from plaid import ProblemDefinition problem = ProblemDefinition() # [...] input_meshes_names = problem.get_input_meshes_names() print(input_meshes_names) >>> ['omega', 'pressure']
- add_input_meshes_names(inputs: list[str]) None[source]¶
Add input meshes names to the problem.
- Parameters:
- Raises:
ValueError – If some
inputsare redondant.
Example
from plaid import ProblemDefinition problem = ProblemDefinition() input_meshes_names = ['omega', 'pressure'] problem.add_input_meshes_names(input_meshes_names)
- add_input_mesh_name(input: str) None[source]¶
Add an input mesh name to the problem.
- Parameters:
input (str) – The name of the input feature to add.
- Raises:
ValueError – If the specified input feature is already in the list of inputs.
Example
from plaid import ProblemDefinition problem = ProblemDefinition() input_name = 'pressure' problem.add_input_mesh_name(input_name)
- filter_input_meshes_names(names: list[str]) list[str][source]¶
Filter and get input meshes features corresponding to a list of names.
- Parameters:
names (list[str]) – A list of names for which to retrieve corresponding input features.
- Returns:
A sorted list of input feature names or categories corresponding to the provided names.
- Return type:
Example
from plaid import ProblemDefinition problem = ProblemDefinition() # [...] input_meshes_names = ['omega', 'pressure', 'temperature'] input_features = problem.filter_input_meshes_names(input_meshes_names) print(input_features) >>> ['omega', 'pressure']
- get_output_meshes_names() list[str][source]¶
Get the output meshes names of the problem.
Example
from plaid import ProblemDefinition problem = ProblemDefinition() # [...] outputs_names = problem.get_output_meshes_names() print(outputs_names) >>> ['compression_rate', 'in_massflow', 'isentropic_efficiency']
- add_output_meshes_names(outputs: list[str]) None[source]¶
Add output meshes names to the problem.
- Parameters:
outputs (list[str]) – A list of output feature names to add.
- Raises:
ValueError – if some
outputsare redondant.
Example
from plaid import ProblemDefinition problem = ProblemDefinition() output_meshes_names = ['compression_rate', 'in_massflow', 'isentropic_efficiency'] problem.add_output_meshes_names(output_meshes_names)
- add_output_mesh_name(output: str) None[source]¶
Add an output mesh name to the problem.
- Parameters:
output (str) – The name of the output feature to add.
- Raises:
ValueError – If the specified output feature is already in the list of outputs.
Example
from plaid import ProblemDefinition problem = ProblemDefinition() output_meshes_names = 'pressure' problem.add_output_mesh_name(output_meshes_names)
- filter_output_meshes_names(names: list[str]) list[str][source]¶
Filter and get output features corresponding to a list of names.
- Parameters:
names (list[str]) – A list of names for which to retrieve corresponding output features.
- Returns:
A sorted list of output feature names or categories corresponding to the provided names.
- Return type:
Example
from plaid import ProblemDefinition problem = ProblemDefinition() # [...] output_meshes_names = ['compression_rate', 'in_massflow', 'isentropic_efficiency'] output_features = problem.filter_output_meshes_names(output_meshes_names) print(output_features) >>> ['in_massflow']
- _save_to_dir_(path: str | pathlib.Path) None[source]¶
Save problem information, inputs, outputs, and split to the specified directory in YAML and CSV formats.
- Parameters:
path (Union[str,Path]) – The directory where the problem information will be saved.
Example
from plaid import ProblemDefinition problem = ProblemDefinition() problem._save_to_dir_("/path/to/save_directory")
- classmethod load(path: str | pathlib.Path) Self[source]¶
Load data from a specified directory.
- Parameters:
path (Union[str,Path]) – The path from which to load files.
- Returns:
The loaded dataset (Dataset).
- Return type:
Self
- _load_from_dir_(path: str | pathlib.Path) None[source]¶
Load problem information, inputs, outputs, and split from the specified directory in YAML and CSV formats.
- Parameters:
path (Union[str,Path]) – The directory from which to load the problem information.
- Raises:
FileNotFoundError – Triggered if the provided directory or file problem_infos.yaml does not exist
FileExistsError – Triggered if the provided path is a file instead of a directory.
Example
from plaid import ProblemDefinition problem = ProblemDefinition() problem._load_from_dir_("/path/to/load_directory")