-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add fast topo * fix fast topo * Automated autopep8 fixes * pep8 * add to initial assumption * make code more clear in `fit` method * add `fast_topoligical_features` to docs * fix aligment for pipeline builders in `TSForecastingAssumptions` * add topo to `FedotBuilder` docs * fix table in docs * add params to fast_topo * change params and add it to tuner search space * fix integration tests * add new param stride * fix param * dirty speedup * delete ica from initial assumption due to instability * fix documentation * fix test * delete fast_topo from assumption and delete fast_train tag --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
5e726e9
commit 5efd0fb
Showing
9 changed files
with
118 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...ation/operation_implementations/data_operations/topological/fast_topological_extractor.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from itertools import chain | ||
from typing import Optional | ||
|
||
import numpy as np | ||
from gph import ripser_parallel as ripser | ||
from joblib import Parallel, delayed | ||
|
||
from fedot.core.data.data import InputData, OutputData | ||
from fedot.core.operations.evaluation.operation_implementations.implementation_interfaces import \ | ||
DataOperationImplementation | ||
from fedot.core.operations.operation_parameters import OperationParameters | ||
|
||
|
||
class FastTopologicalFeaturesImplementation(DataOperationImplementation): | ||
def __init__(self, params: Optional[OperationParameters] = None): | ||
super().__init__(params) | ||
self.window_size_as_share = params.get('window_size_as_share') | ||
self.max_homology_dimension = params.get('max_homology_dimension') | ||
self.metric = params.get('metric') | ||
self.stride = params.get('stride') | ||
self.n_jobs = params.get('n_jobs') | ||
self.quantiles = (0.1, 0.25, 0.5, 0.75, 0.9) | ||
self._shape = len(self.quantiles) | ||
self._window_size = None | ||
|
||
def fit(self, input_data: InputData): | ||
self._window_size = int(input_data.features.shape[1] * self.window_size_as_share) | ||
self._window_size = max(self._window_size, 2) | ||
self._window_size = min(self._window_size, input_data.features.shape[1] - 2) | ||
return self | ||
|
||
def transform(self, input_data: InputData) -> OutputData: | ||
features = input_data.features | ||
with Parallel(n_jobs=self.n_jobs, prefer='processes') as parallel: | ||
topological_features = parallel(delayed(self._extract_features) | ||
(np.mean(features[i:i+2, ::self.stride], axis=0)) | ||
for i in range(0, features.shape[0], 2)) | ||
if len(topological_features) * 2 < features.shape[0]: | ||
topological_features.append(topological_features[-1]) | ||
result = np.array(list(chain(*zip(topological_features, topological_features)))) | ||
if result.shape[0] > features.shape[0]: | ||
result = result[:-1, :] | ||
np.nan_to_num(result, copy=False, nan=0, posinf=0, neginf=0) | ||
return result | ||
|
||
def _extract_features(self, x): | ||
x_sliced = np.array([x[i:self._window_size + i] for i in range(x.shape[0] - self._window_size + 1)]) | ||
x_processed = ripser(x_sliced, | ||
maxdim=self.max_homology_dimension, | ||
coeff=2, | ||
metric=self.metric, | ||
n_threads=1, | ||
collapse_edges=False)["dgms"] | ||
result = np.zeros(self._shape * (self.max_homology_dimension + 1)) | ||
for i, xp in enumerate(x_processed): | ||
if xp.shape[0] > 0: | ||
result[i * self._shape:(i + 1) * self._shape] = np.quantile(xp[:, 1] - xp[:, 0], self.quantiles, | ||
overwrite_input=True, method='hazen') | ||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters