From 0ec915daa5d99bb53820f4fb297ced3103d6ccb4 Mon Sep 17 00:00:00 2001 From: Sergey Kasyanov Date: Fri, 28 Jul 2023 17:03:44 +0300 Subject: [PATCH 1/2] Add test of Fedot forecast reproducing --- .../test_model_result_reproducing.py | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 test/integration/real_applications/test_model_result_reproducing.py diff --git a/test/integration/real_applications/test_model_result_reproducing.py b/test/integration/real_applications/test_model_result_reproducing.py new file mode 100644 index 0000000000..a686b4d133 --- /dev/null +++ b/test/integration/real_applications/test_model_result_reproducing.py @@ -0,0 +1,45 @@ +import numpy as np +from fedot.core.repository.tasks import Task, TaskTypesEnum, TsForecastingParams +from fedot.api.main import Fedot +from fedot.core.data.data import InputData +from fedot.core.repository.dataset_types import DataTypesEnum +from fedot.core.data.data_split import train_test_data_setup + + +def get_data(data_length=500, test_length=100): + garmonics = [(0.1, 0.9), (0.1, 1), (0.1, 1.1), (0.05, 2), (0.05, 5), (1, 0.02)] + time = np.linspace(0, 100, data_length) + data = time * 0 + for g in garmonics: + data += g[0] * np.sin(g[1] * 2 * np.pi / time[-1] * 25 * time) + + data = InputData(idx=np.arange(0, data.shape[0]), + features=data, + target=data, + task=Task(TaskTypesEnum.ts_forecasting, + TsForecastingParams(forecast_length=test_length)), + data_type=DataTypesEnum.ts) + return train_test_data_setup(data, split_ratio=(data_length - test_length) / + ((data_length - test_length) + test_length)) + + +def test_result_reproducing(): + train, test = get_data() + old_fedot = None + # try in cycle because some problems are random + for _ in range(4): + fedot = Fedot(problem='ts_forecasting', + task_params=TsForecastingParams(forecast_length=test.idx.shape[0]), + seed=0, + timeout=2, + pop_size=2, + num_of_generations=2, + ) + fedot.fit(train) + + if old_fedot is not None: + assert np.all([np.isclose(x, y) for x, y in zip(fedot.history.all_historical_fitness, + old_fedot.history.all_historical_fitness)]) + assert np.isclose(np.sum(np.abs(fedot.forecast(test) - old_fedot.forecast(test))), 0) + + old_fedot = fedot From 1cbc378e1ca37f876f0b1a9331df188ef5198b0f Mon Sep 17 00:00:00 2001 From: Sergey Kasyanov Date: Fri, 28 Jul 2023 17:05:40 +0300 Subject: [PATCH 2/2] Fixes --- .../real_applications/test_model_result_reproducing.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/integration/real_applications/test_model_result_reproducing.py b/test/integration/real_applications/test_model_result_reproducing.py index a686b4d133..ea1b04adad 100644 --- a/test/integration/real_applications/test_model_result_reproducing.py +++ b/test/integration/real_applications/test_model_result_reproducing.py @@ -32,8 +32,8 @@ def test_result_reproducing(): task_params=TsForecastingParams(forecast_length=test.idx.shape[0]), seed=0, timeout=2, - pop_size=2, - num_of_generations=2, + pop_size=50, + num_of_generations=5, ) fedot.fit(train)