Quickstart: Discrete Dynamic with the Python API#

This tutorial uses Temperature forecasting provided with NeurEco installation.

To work with the Discrete Dynamic NeurEco models in Python, import NeurEcoDynamic library:

from NeurEco import NeurEcoDynamic as Dynamic

Import numpy to handle the data sets:

import numpy as np

Load the data sets (see Data preparation for NeurEco Discrete Dynamic with the Python API and Temperature forecasting):

x_first_year = np.load("x_first_year.npy")
t_first_year = x_first_year[:, 0:1]
x_first_year = x_first_year[:, 1:]
y_first_year = np.load("y_first_year.npy")
y_first_year = y_first_year[:, 1:]
x_year_2 = np.load("x_second_year.npy")
t_year_2 = x_year_2[:, 0:1]
x_year_2 = x_year_2[:, 1:]
y_year_2 = np.load("y_second_year.npy")
y_year_2 = y_year_2[:, 1:]

To initialize a NeurEco object to handle the Discrete Dynamic problem:

dynamic_model = Dynamic.DiscreteDynamic()

To build the model, call method build with the parameters set for the problem under consideration (see Build NeurEco Discrete Dynamic model with the Python API). For this example, we will choose a validation percentage of 30%. Meaning that NeurEco will use the last 30% of the training trajectory as validation data. For example, if the training trajectory contains 1000 time steps, the first 700 steps will be used for training and the last 300 steps will be used for validation.

dynamic_model.build(train_time_list=[t_first_year], train_exc_list=[x_first_year], train_out_list=[y_first_year],
                   valid_percentage=30,
                   # the rest of these parameters are optional
                   write_model_to="./TemperatureForecasting/TemperatureForecasting.ernn",
                   checkpoint_address="./TemperatureForecasting/TemperatureForecasting.checkpoint")

Note

For detailed documentation on build, see Build NeurEco Discrete Dynamic model with the Python API.

To evaluate the NeurEco Model on the testing data (the second year of data), call evaluate method:

neureco_outputs_second_year = dynamic_model.evaluate([t_second_year], [x_second_year])

Note

For detailed documentation on evaluate, see Evaluate NeurEco Discrete Dynamic model with the Python API.

To export the model as an FMU file:

dynamic_model.export_fmu("./TemperatureForecasting/TemperatureForecasting.fmu")

This export requires embed license.

Note

For detailed documentation on export, see Export NeurEco Discrete Dynamic model python

When the model is not needed any more, delete it from the memory:

dynamic_model.delete()

Note

For detailed documentation on Tabular Regression with the python API, see Discrete Dynamic with the Python API.