The BaseAlgorithm class
- class pyoma2.algorithms.base.BaseAlgorithm(run_params: T_RunParams | None = None, name: str | None = None, *args: Any, **kwargs: Any)[source]
Bases:
Generic[T_RunParams,T_Result,T_Data],ABCAbstract base class for OMA algorithms.
This class serves as a foundational structure for implementing various OMA algorithms, setting a standard interface and workflow.
- result
Stores the results produced by the algorithm. The type of result depends on T_Result.
- Type:
Optional[T_Result]
- run_params
Holds the parameters necessary to run the algorithm. The type of run parameters depends on T_RunParams.
- Type:
Optional[T_RunParams]
- RunParamCls
The class used for instantiating run parameters. Must be a subclass of BaseModel.
- Type:
Type[T_RunParams]
- ResultCls
The class used for encapsulating the algorithm’s results. Must be a subclass of BaseResult.
- Type:
Type[T_Result]
- data
The input data for the algorithm. The type of data depends on T_Data.
- Type:
Optional[T_Data]
- __init__(self, run_params=None, name=None, \*args, \*\*kwargs)[source]
Initializes the algorithm with optional run parameters and a name.
- __init_subclass__(cls, \*\*kwargs)[source]
Ensures that subclasses define RunParamCls and ResultCls.
Warning
The BaseAlgorithm class is not intended for direct instantiation by users. Specific functionalities are provided through its subclasses.
- __init__(run_params: T_RunParams | None = None, name: str | None = None, *args: Any, **kwargs: Any)[source]
Initialize the algorithm with optional run parameters and a name.
- Parameters:
run_params (Optional[T_RunParams], optional) – The parameters required to run the algorithm. If not provided, can be set later.
name (Optional[str], optional) – The name of the algorithm. If not provided, defaults to the class name.
*args (tuple) – Additional positional arguments.
**kwargs (dict) – Additional keyword arguments used to instantiate run parameters if run_params is not provided.
- abstract mpe(*args, **kwargs) Any[source]
Abstract method to return the modal parameters extracted by the algorithm.
- Parameters:
- Returns:
The modal parameters extracted by the algorithm.
- Return type:
- Raises:
NotImplementedError – If the method is not implemented in the subclass.
ValueError – If the algorithm has not been run or the result is not set.
Note
Implementing classes should override this method to provide functionality for extracting and returning modal parameters based on the algorithm’s results.
- abstract mpe_from_plot(*args, **kwargs) Any[source]
Abstract method to select peaks or modal parameters from plots.
- Parameters:
- Returns:
The selected peaks or modal parameters.
- Return type:
- Raises:
NotImplementedError – If the method is not implemented in the subclass.
ValueError – If the algorithm has not been run or the result is not set.
Note
Implementing classes should provide mechanisms for selecting and returning peaks or modal parameters from graphical plots or visual representations of the data.
- abstract run() T_Result[source]
Abstract method to execute the algorithm.
This method must be implemented by all subclasses. It should use the set run_params and input data to perform the modal analysis and save the result in the result attribute.
- Returns:
The result of the algorithm execution.
- Return type:
T_Result
- Raises:
NotImplementedError – If the method is not implemented in the subclass.
Note
Implementing classes should handle the algorithm logic within this method and ensure that the output is an instance of the ResultCls.
- set_run_params(run_params: T_RunParams) BaseAlgorithm[source]
Set the run parameters for the algorithm.
- Parameters:
run_params (T_RunParams) – The run parameters for the algorithm.
- Returns:
Returns the instance with updated run parameters.
- Return type:
Note
This method allows dynamically setting or updating the run parameters for the algorithm after its initialization.