aimclub / FEDOT

Automated modeling and machine learning framework FEDOT
https://fedot.readthedocs.io
BSD 3-Clause "New" or "Revised" License
623 stars 84 forks source link

FEDOT does not reproduce results #1128

Closed kasyanovse closed 11 months ago

kasyanovse commented 11 months ago

Simple case with fedot timeseries forecast does not reproduce results with set seed in random, np.random modules and FEDOT.

Example code ``` import random import numpy as np import matplotlib.pyplot as plt 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 RANDOM_SEED = 0 random.seed(RANDOM_SEED) np.random.seed(RANDOM_SEED) 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 get_fitted_fedot(train, test, random_seed=RANDOM_SEED): fedot = Fedot(problem='ts_forecasting', task_params=TsForecastingParams(forecast_length=test.idx.shape[0]), seed=random_seed, timeout=1, pop_size=10, num_of_generations=10) fedot.fit(train) return fedot def plot(fedot, old_fedot, train, test, num=[0]): _, ax = plt.subplots() length = test.idx.shape[0] ax.plot(np.concatenate([train.idx[-2 * length:], test.idx]), np.concatenate([train.features[-2 * length:], test.target]), c='k') ax.plot(test.idx, fedot.forecast(test), c='r', ls=':', label='fedot') ax.plot(test.idx, old_fedot.forecast(test), c='m', ls='--', label='old_fedot') ax.legend() num[0] += 1 ax.set_title(num[0]) plt.show() train, test = get_data() old_fedot = None for _ in range(4): fedot = get_fitted_fedot(train, test) if old_fedot is not None: plot(fedot, old_fedot, train, test) assert fedot.current_pipeline.graph_description == old_fedot.current_pipeline.graph_description assert fedot.history.all_historical_fitness == old_fedot.history.all_historical_fitness assert np.sum(np.abs(fedot.forecast(test) - old_fedot.forecast(test))) < 1e-4 old_fedot = fedot ```
nicl-nno commented 11 months ago

А проверь с новой версией мастера на всякий случай. В последнем коммите был относящийся к рандомности фикс.