Skip to content

Commit

Permalink
update tests for consistency and clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
technocreep committed Dec 17, 2024
1 parent 45c7064 commit b1e003c
Show file tree
Hide file tree
Showing 15 changed files with 52 additions and 280 deletions.
2 changes: 1 addition & 1 deletion fedot_ind/core/operation/IndustrialCachableOperation.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def transform(
operation_info=class_params.__repr__())
try:
transformed_features = self.try_load_from_cache(hashed_info)
except FileNotFoundError:
except (FileNotFoundError, ValueError):
transformed_features = self._transform(input_data)
self.cacher.cache_data(hashed_info, transformed_features)

Expand Down
2 changes: 1 addition & 1 deletion fedot_ind/core/operation/caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def load_data_from_cache(self, hashed_info: str):
raise FileNotFoundError(f'File {file_path} was not found')
elapsed_time = round(timeit.default_timer() - start, 5)
print(
f'{self.data_type} of {type(data)} type is loaded from cache in {elapsed_time} sec')
f'{self.data_type} of {type(data)} type are loaded from cache in {elapsed_time} sec')
return data

def cache_data(self, hashed_info: str, data: pd.DataFrame):
Expand Down
1 change: 1 addition & 0 deletions fedot_ind/core/operation/transformation/basis/fourier.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def _build_spectrum(self, input_data):
return estimator

def _decompose_signal(self, input_data):

estimator = self._build_spectrum(input_data)
# self._visualise_spectrum(estimator)
psd = estimator.psd
Expand Down
7 changes: 5 additions & 2 deletions fedot_ind/core/operation/transformation/data/point_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,11 @@ def point_cloud_to_persistent_cohomology_ripser(
# normalize epsilon distance in diagrams so max is 1
diagrams = [np.array([dg for dg in diag if np.isfinite(dg).all()])
for diag in diagrams]
diagrams = diagrams / max([np.array([dg for dg in diag if np.isfinite(
dg).all()]).max() for diag in diagrams if diag.shape[0] > 0])
# diagrams = diagrams / max([np.array([dg for dg in diag if np.isfinite(
# dg).all()]).max() for diag in diagrams if diag.shape[0] > 0])

diagrams = [d / max([np.array([dg for dg in diag if np.isfinite(
dg).all()]).max() for diag in diagrams if diag.shape[0] > 0]) for d in diagrams]

ep_ran_len = len(epsilon_range)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def _concatenate_global_and_local_feature(
window_stat_features = np.nan_to_num(window_stat_features)
return window_stat_features

def extract_stats_features(self, ts: np.array, axis=None) -> InputData:
def extract_stats_features(self, ts: np.array, axis: int) -> InputData:
global_features = self.get_statistical_features(ts, add_global_features=self.add_global_features, axis=axis)
window_stat_features = self.get_statistical_features(ts, axis=axis) if self.window_size == 0 else \
self.apply_window_for_stat_feature(ts_data=ts, feature_generator=self.get_statistical_features,
Expand All @@ -71,7 +71,7 @@ def generate_features_from_ts(self,
ts: np.array,
window_length: int = None) -> InputData:
ts = ts[None, :] if len(ts.shape) == 1 else ts # sanity check for map method
statistical_representation = np.array(list(map(lambda channel: self.extract_stats_features(channel), ts)))
statistical_representation = np.array(list(map(lambda channel: self.extract_stats_features(channel, axis=0), ts)))
return statistical_representation

def generate_features_from_array(self, array: np.array) -> InputData:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@ def _generate_features_from_ts(self, ts_data: np.array, persistence_params: dict

point_cloud = self.data_transformer.time_series_to_point_cloud(input_data=ts_data, use_gtda=True)
topological_features = self.feature_extractor.transform(point_cloud)
topological_features = InputData(idx=np.arange(len(topological_features.values)),
features=topological_features.values,
target='no_target',
task='no_task',
data_type=DataTypesEnum.table,
supplementary_data={'feature_name': topological_features.columns})
return topological_features
# topological_features = InputData(idx=np.arange(len(topological_features.values)),
# features=topological_features.values,
# target='no_target',
# task='no_task',
# data_type=DataTypesEnum.table,
# supplementary_data={'feature_name': topological_features.columns})
return topological_features.values

def generate_topological_features(self, ts: np.array, persistence_params: dict = None) -> InputData:
if persistence_params is not None:
Expand Down
56 changes: 0 additions & 56 deletions tests/unit/core/models/test_quantile_extractor.py

This file was deleted.

61 changes: 0 additions & 61 deletions tests/unit/core/models/test_recurrence_extractor.py

This file was deleted.

96 changes: 0 additions & 96 deletions tests/unit/core/models/test_riemann_embeding.py

This file was deleted.

41 changes: 0 additions & 41 deletions tests/unit/core/models/test_topological_extractor.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ def sample_ts():

def test_fit_transform(sample_matrix):
rank = 1
cur = CURDecomposition(rank)
cur = CURDecomposition({'rank': rank})
result = cur.fit_transform(sample_matrix)
approximated = result[0]
assert isinstance(result, tuple)
assert approximated.shape[0] == rank


def test_ts_to_matrix(sample_ts):
cur = CURDecomposition(rank=2)
cur = CURDecomposition({'rank': 2})
matrix = cur.ts_to_matrix(time_series=sample_ts, window=10)
assert isinstance(matrix, np.ndarray)


def test_matrix_to_ts(sample_matrix):
cur = CURDecomposition(rank=2)
cur = CURDecomposition({'rank': 2})
ts = cur.matrix_to_ts(sample_matrix)
assert isinstance(ts, np.ndarray)
assert len(ts.shape) == 1
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def test_transform_one_sample():
basis.SV_threshold = 3
sample = input_train_data.features[0]
transformed_sample = basis._transform_one_sample(sample)
transformed_sample = transformed_sample.compute()
assert isinstance(transformed_sample, np.ndarray)
assert transformed_sample.shape[0] == basis.SV_threshold
assert transformed_sample.shape[1] == len(sample)
Loading

0 comments on commit b1e003c

Please sign in to comment.