BTSTN
is a Python package designed to model the metabolic dynamics from Partially-Observed Time Series based on the Bidrectional Time-series State Transfer Network.
The source code developed in Python 3.8 using PyTorch. The required python dependencies are given below.
torch==2.0.0
numpy>=1.23.5
pandas>=1.5.2
pypots==0.5
Batch | Time | Parameter 1 | Parameter 2 | ... |
---|---|---|---|---|
A1 | T1 | 2.1 | 5.0 | ... |
A1 | T2 | 1.4 | 4.3 | ... |
A1 | T3 | 3.8 | 0 | ... |
B1 | T1 | 2.1 | 5.0 | ... |
B1 | T3 | 1.4 | 4.3 | ... |
B1 | T4 | 3.8 | 0 | ... |
... | ... | ... | ... | ... |
DataReader
are used to read your file as input for model training and forecasting.
import pandas as pd
from btstn import DataReader
# Load data
file_path = "xxx.csv"
data = DataReader(
data=pd.read_csv(file_path),
scaler="MinMax",
unit = 1,
dropna=False,
sort=True,
header=0
)
BTSTN
provides a simple tool to define the structure of model and training parameters.
from btstn import BTSTN
# Initialize the model
tcnits = BTSTN(
n_features=2,
n_dims=16,
g_inner=32,
g_layers=2,
d_inner=None,
d_layers=None,
dropout=0.1,
d_dropout=0,
activation={"fc_name":"tanh"},
max_gap=10,
batch_size=128,
epoch=1000,
patience=100,
learning_rate=0.001,
threshold=0,
gpu_id=-1,
num_workers=0,
pin_memory=False,
saving_path=None,
saving_prefix=None
)
# fit the model
train_loss = tcnits.fit(data=data)
BTSTN supported the following tasks with the trained model: imputation and forecasting.
BTSTN
supported the Imputation Task (Interpolation and Extrapolation).
# Imputation
impdata = tcnits.impute(
data=data,
max_gap_f=None,
batch_size_f=None,
epoch_f=None,
patience_f=None,
learning_rate_f=None,
inverse=True
)
BTSTN
supported the Forecasting Task.
# Load data
mfile_path = "yyy.csv"
mdata = DataReader(
data=pd.read_csv(mfile_path),
scaler="MinMax",
unit = 1,
dropna=False,
sort=True,
header=0
)
# Monitor
tcnits.monitor(
data=mdata,
max_gap_f=10,
batch_size_f=128,
epoch_f=3000,
patience_f=-1,
learning_rate_f=0.001
)
# Forecast
foredata = tcnits.forecast(
data=mdata,
stime=[0],
pred_step=99,
multi_step=1,
inverse=True
)