Skip to content

Commit

Permalink
Just added or updated docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
technocreep committed Dec 3, 2024
1 parent 68bee24 commit 5e9a98e
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 20 deletions.
29 changes: 25 additions & 4 deletions fedot_ind/api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,32 @@


class FedotIndustrial(Fedot):
"""This class is used to run Fedot in industrial mode as FedotIndustrial.
"""Main class for Industrial API. It provides a high-level interface for working with the
Fedot framework. The class allows you to train, predict, and evaluate models for time series.
All arguments are passed as keyword arguments and handled by the ApiManager class.
Args:
input_config: dictionary with the parameters of the experiment.
output_folder: path to the folder where the results will be saved.
problem: str. The type of task to solve. Available options: 'ts_forecasting', 'ts_classification', 'ts_regression'.
timeout: int. Time for model design (in minutes): ``None`` or ``-1`` means infinite time.
logging_level: logging levels are the same as in
`built-in logging library <https://docs.python.org/3/library/logging.html>`_.
.. details:: Possible options:
- ``50`` -> critical
- ``40`` -> error
- ``30`` -> warning
- ``20`` -> info
- ``10`` -> debug
- ``0`` -> nonset
backend_method: str. Default `cpu`. The method for backend. Available options: 'cpu', 'dask'.
initial_assumption: Pipeline = None. The initial pipeline for the model.
optimizer_params: dict = None.
task_params: dict = None.
strategy: str = None.
strategy_params: dict = None.
available_operations: list = None.
output_folder: str = './output'.
Example:
First, configure experiment and instantiate FedotIndustrial class::
Expand All @@ -50,7 +71,6 @@ class FedotIndustrial(Fedot):
industrial = FedotIndustrial(problem='ts_classification',
use_cache=False,
timeout=15,
n_jobs=2,
logging_level=20)
Expand Down Expand Up @@ -476,5 +496,6 @@ def plot_func(mode):
return history_visualizer.history if return_history else None

def shutdown(self):
"""Shutdown Dask client"""
self.dask_client.close()
del self.dask_client
4 changes: 2 additions & 2 deletions fedot_ind/api/utils/api_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ def null_state_object(self):
def user_config_object(self, kwargs):
self.output_folder = kwargs.get('output_folder', None)
self.strategy_params = kwargs.get(
'industrial_strategy_params', None)
self.strategy_class = kwargs.get('industrial_strategy', None)
'strategy_params', None)
self.strategy_class = kwargs.get('strategy', None)
self.path_to_composition_results = kwargs.get('history_dir', None)
self.backend_method = kwargs.get('backend', 'cpu')
self.task_params = kwargs.get('task_params', {})
Expand Down
11 changes: 11 additions & 0 deletions fedot_ind/api/utils/industrial_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@


class IndustrialStrategy:
"""
Class for industrial strategy implementation
Args:
industrial_strategy_params: dict
Parameters for industrial strategy
industrial_strategy: str
Industrial strategy name
api_config: dict
Configuration for API
"""
def __init__(self,
industrial_strategy_params,
industrial_strategy,
Expand Down
16 changes: 16 additions & 0 deletions fedot_ind/core/ensemble/kernel_ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@


class KernelEnsembler(BaseExtractor):
"""
Class for kernel ensembling. This class implements a kernel-based ensemble method for feature
extraction and classification. It supports both one-stage and two-stage kernel learning
strategies and can handle multiclass classification problems.
Args:
params (Optional[OperationParameters]): Parameters of the operation
Attributes:
distance_metric (str): The distance metric used to calculate the Gram matrix
kernel_strategy (str): The kernel learning strategy used by the model
learning_strategy (str): The learning strategy used by the model
head_model (str): The head model used by the model
feature_extractor (List[str]): The feature extractors used by the model
"""
def __init__(self, params: Optional[OperationParameters] = None):
super().__init__(params)
self.distance_metric = params.get('distance_metric', KERNEL_DISTANCE_METRIC['default_metric'])
Expand Down
20 changes: 16 additions & 4 deletions fedot_ind/core/metrics/evaluation.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
import logging
from enum import Enum
from typing import Dict, List


from fedot_ind.core.metrics.metrics_implementation import *
from typing import Dict, List, Union

import numpy as np

from fedot_ind.core.metrics.metrics_implementation import (
F1,
MAE,
MAPE,
MSE,
R2,
RMSE,
ROCAUC,
Accuracy,
Logloss,
Precision,
)


class Metrics(Enum):
Expand Down
34 changes: 24 additions & 10 deletions fedot_ind/core/metrics/metrics_implementation.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,37 @@
from typing import Optional
from typing import Union
from typing import Optional, Union

import numpy as np
import pandas as pd
from fedot.core.data.data import InputData
from fedot.core.operations.operation_parameters import OperationParameters
from golem.core.dag.graph import Graph
from sklearn.metrics import (accuracy_score, f1_score,
log_loss, mean_absolute_error,
mean_absolute_percentage_error,
mean_squared_error, mean_squared_log_error,
precision_score, r2_score, roc_auc_score)
from sklearn.metrics import d2_absolute_error_score, explained_variance_score, max_error, median_absolute_error
from sklearn.metrics import (
accuracy_score,
d2_absolute_error_score,
explained_variance_score,
f1_score,
log_loss,
max_error,
mean_absolute_error,
mean_absolute_percentage_error,
mean_squared_error,
mean_squared_log_error,
median_absolute_error,
precision_score,
r2_score,
roc_auc_score,
)
from sktime.performance_metrics.forecasting import mean_absolute_scaled_error

from fedot_ind.core.architecture.settings.computational import backend_methods as np

# from fedot_ind.core.architecture.preprocessing.data_convertor import DataConverter
from fedot_ind.core.metrics.anomaly_detection.function import single_average_delay, \
single_evaluate_nab, single_detecting_boundaries, check_errors
from fedot_ind.core.metrics.anomaly_detection.function import (
check_errors,
single_average_delay,
single_detecting_boundaries,
single_evaluate_nab,
)


class ParetoMetrics:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,24 @@


class CURDecomposition:
"""
CUR decomposition is a low-rank matrix decomposition method that is based on selecting
a subset of columns and rows of the original matrix. The method is based on the
Johnson-Lindenstrauss lemma and is used to approximate the original matrix with a
low-rank matrix. The CUR decomposition is defined as follows:
A = C @ U @ R
where A is the original matrix, C is a subset of columns of A, U is a subset of rows of A,
and R is a subset of rows of A. The selection of columns and rows is based on the
probabilities p and q, which are computed based on the norms of the columns and rows of A.
The selection of columns and rows is done in such a way that the approximation error is minimized.
Args:
params: the parameters of the operation
rank: the rank of the decomposition
tolerance: the tolerance of the decomposition
return_samples: whether to return the samples or the decomposition matrices
"""
def __init__(self, params: Optional[OperationParameters] = None):
self.selection_rank = params.get('rank', None)
self.tolerance = params.get('tolerance', [0.5, 0.1, 0.05])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,26 @@


class RSVDDecomposition:
"""Randomized SVD decomposition with power iteration method.
Implements the block Krylov subspace method for computing the SVD of a matrix with a low computational cost.
The method is based on the power iteration procedure, which allows us to obtain a low-rank approximation of the
matrix. The method is based on the following steps:
1. Random projection of the matrix.
2. Transformation of the initial matrix to the Gram matrix.
3. Power iteration procedure.
4. Orthogonalization of the resulting "sampled" matrix.
5. Projection of the initial Gram matrix on the new basis obtained from the "sampled matrix".
6. Classical svd decomposition with the chosen type of spectrum thresholding.
7. Compute matrix approximation and choose a new low_rank.
8. Return matrix approximation.
Args:
params: dictionary with parameters for the operation:
rank: rank of the matrix approximation
power_iter: polynom degree for power iteration procedure
sampling_share: percent of sampling columns. By default - 70%
"""
def __init__(self, params: Optional[OperationParameters] = {}):
self.rank = params.get('rank', 1)
# Polynom degree for power iteration procedure.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@


class MultiDimPreprocessingStrategy(EvaluationStrategy):
"""
Class for preprocessing operations that can be used for multi-dimensional data.
Args:
operation_impl: operation implementation
operation_type: operation type
params: operation parameters
mode: mode of operation. Can be 'one_dimensional', 'channel_independent' or 'multi_dimensional'
"""
def __init__(self, operation_impl,
operation_type: str,
params: Optional[OperationParameters] = None,
Expand Down

0 comments on commit 5e9a98e

Please sign in to comment.