Source code for simulai.backup.Network.test_lstm_net_prediction

# (C) Copyright IBM Corp. 2019, 2020, 2021, 2022.

#    Licensed under the Apache License, Version 2.0 (the "License");
#    you may not use this file except in compliance with the License.
#    You may obtain a copy of the License at

#           http://www.apache.org/licenses/LICENSE-2.0

#     Unless required by applicable law or agreed to in writing, software
#     distributed under the License is distributed on an "AS IS" BASIS,
#     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#     See the License for the specific language governing permissions and
#     limitations under the License.

import os
import numpy as np
from unittest import TestCase

from simulai.utilities.lorenz_solver import lorenz_solver
from simulai.utilities.oscillator_solver import oscillator_solver
from simulai.io import MovingWindow

[docs]class TestDenseNetTFPrediction(TestCase):
[docs] def setUp(self) -> None: pass
[docs] def test_dense_net_tf_predictions_lorenz(self): data_path = os.path.join(os.getcwd(), 'data') save_path = os.path.join(os.getcwd(), 'data') case = 'Lorenz' dt = 0.025 T_max = 25 rho = 28 beta = 8/3 beta_str = '8/3' sigma = 10 history_size = 10 horizon_size = 1 skip_size = 1 architecture = [50, 50, 50] initial_state = np.array([1, 2, 3])[None, :] variables_matrix, _ = lorenz_solver(rho=rho, data_path=data_path, dt=dt, T=T_max, sigma=sigma, initial_state=initial_state, beta=beta, beta_str=beta_str) self.assertIsInstance(variables_matrix, np.ndarray) moving_window = MovingWindow(history_size=history_size, horizon_size=horizon_size, skip_size=skip_size) input_data, target_data = moving_window(input_data=variables_matrix, output_data=variables_matrix) self.assertIsInstance(input_data, np.ndarray) self.assertIsInstance(target_data, np.ndarray) model_name = case + "_tf_surrogate"
[docs] def test_dense_net_tf_predictions_oscillator(self): data_path = os.path.join(os.getcwd(), 'data') save_path = os.path.join(os.getcwd(), 'data') case = 'oscillator' dt = 0.025 T_max = 25 history_size = 10 horizon_size = 1 skip_size = 1 # initial_state = np.array([2, 0]) initial_state = np.array([2, 0])[None, :] variables_matrix, _ = oscillator_solver(dt=dt, T=T_max, initial_state=initial_state) self.assertIsInstance(variables_matrix, np.ndarray) moving_window = MovingWindow(history_size=history_size, horizon_size=horizon_size, skip_size=skip_size) input_data, target_data = moving_window(input_data=variables_matrix, output_data=variables_matrix) self.assertIsInstance(input_data, np.ndarray) self.assertIsInstance(target_data, np.ndarray) model_name = case + "_tf_surrogate"