Skip to content

Commit

Permalink
add fedot remains reconstruction
Browse files Browse the repository at this point in the history
  • Loading branch information
valer1435 committed Sep 4, 2023
1 parent 18bd984 commit cb096bd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
8 changes: 4 additions & 4 deletions examples/ts_forecasting/with_decomposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def get_ts_data(dataset='australia', horizon: int = 30, m4_id=None):
with IndustrialModels():
pipeline = PipelineBuilder().add_node('data_driven_basis_for_forecasting',
params={'window_size': int(len(train_data.features) * 0.35),
'estimator': 'ets'}
'estimator': 'arima'}
).build()
pipeline_tuner = TunerBuilder(train_data.task) \
.with_tuner(SimultaneousTuner) \
Expand All @@ -89,9 +89,9 @@ def get_ts_data(dataset='australia', horizon: int = 30, m4_id=None):
no_ssa = np.ravel(pipeline2.predict(test_data).predict)
plt.plot(train_data.idx, test_data.features, label='features')
plt.plot(test_data.idx, test_data.target, label='target')
for comp in pipeline.nodes[0].fitted_operation.train_basis:
plt.plot(train_data.idx, comp,
label='reconmstructed features')
# for comp in pipeline.nodes[0].fitted_operation.train_basis:
# plt.plot(train_data.idx, comp,
# label='reconmstructed features')
plt.plot(test_data.idx, predict, label='predicted ssa')
plt.plot(test_data.idx, no_ssa, label='predicted no ssa')
print(f"SSA smape: {smape(test_data.target, predict)}")
Expand Down
33 changes: 25 additions & 8 deletions fedot_ind/core/operation/ts_forecasting/data_driven_ts.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from typing import TypeVar, Optional

from fedot.api.main import Fedot
from fedot.core.data.data import InputData, OutputData
from fedot.core.operations.evaluation.operation_implementations.implementation_interfaces import ModelImplementation
from fedot.core.operations.operation_parameters import OperationParameters
from fedot.core.pipelines.pipeline_builder import PipelineBuilder
from fedot.core.pipelines.tuning.tuner_builder import TunerBuilder
from fedot.core.repository.quality_metrics_repository import RegressionMetricsEnum
from fedot.core.repository.tasks import TsForecastingParams
from golem.core.tuning.simultaneous import SimultaneousTuner
from matplotlib import pyplot as plt
from pymonad.either import Either
Expand Down Expand Up @@ -99,14 +101,29 @@ def predict(self, input_data: InputData) -> OutputData:

# plt.grid()
# plt.show()
plt.plot(input_data.features)
for i in basis:
plt.plot(i)

plt.plot(np.arange(len(input_data.features), len(input_data.features) + forecast_length), np.array(basis).sum(axis=0)[-forecast_length:])
plt.show()

return np.array(basis).sum(axis=0)[-forecast_length:]
# plt.plot(input_data.features)
# for i in basis:
# plt.plot(i)
#
# plt.plot(np.arange(len(input_data.features), len(input_data.features) + forecast_length), np.array(basis).sum(axis=0)[-forecast_length:])
# plt.show()
reconstructed = np.array(basis).sum(axis=0)
remains = input_data.features - reconstructed[:-forecast_length]

train_data = InputData(idx=np.arange(remains.shape[0]), features=remains, target=remains,
data_type=input_data.data_type,
task=input_data.task)
test_data = InputData(idx=input_data.idx, features=remains, target=None,
data_type=input_data.data_type,
task=input_data.task)
fedot = Fedot(problem='ts_forecasting',
task_params=TsForecastingParams(forecast_length=forecast_length),
timeout=0.5)
fedot.fit(train_data)
fedot_predict = fedot.predict(test_data)

predict = reconstructed[-forecast_length:] + fedot_predict
return predict

def fit(self, input_data: InputData):
pass
Expand Down

0 comments on commit cb096bd

Please sign in to comment.