Skip to content

Commit

Permalink
change config file
Browse files Browse the repository at this point in the history
  • Loading branch information
TianyuDu committed Sep 11, 2018
1 parent 36c6e77 commit ee259d4
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 46 deletions.
61 changes: 46 additions & 15 deletions k models/exchange/config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import pandas as pd
import numpy as np

"""
Configuration file for univariate time series model.
"""
Expand All @@ -12,23 +15,51 @@
# Configuration dictionary to create DataContainer Object
data_proc_config = {
# Method to remove non-stationarity of time series
# By default, create stationary time series using first
# differencing.
# By default, create stationary time series using first
# differencing.
"method": "diff", # {str}
# Avaiable method:
# "diff": remove non-stationarity by differncing.
# Avaiable method:
# "diff": remove non-stationarity by differncing.
"diff.lag": 1, # {int > 0}
# Lag of differencing,
# Notice: If set to zero, the 0 series will be returned (x[i] - x[i - 0] == 0)
# Lag of differencing,
# Notice: If set to zero, the 0 series will be returned (x[i] - x[i - 0] == 0)
"diff.order": 1, # {int >= 0}
# Order of differencing,
# Notice: 0 order differencing will return the original series.
# For k order differncing, the generated series will have length N - k
# Order of differencing,
# Notice: 0 order differencing will return the original series.
# For k order differncing, the generated series will have length N - k
"test_ratio": 0.2, # {0 <= float < 1}
# Ratio of test set to evaluate neural network.
"lag_for_sup": 3, # {int > 0}
# Total number of lag values used to generate
# supervised learning problem (SLP).
# Using m then the i-1 to i-m total m lagged variables
# will be used to predict the i-index variable in the SLP.
# Ratio of test set to evaluate neural network.
"lag_for_sup": 3, # {int > 0}
# Total number of lag values used to generate
# supervised learning problem (SLP).
# Using m then the i-1 to i-m total m lagged variables
# will be used to predict the i-index variable in the SLP.
}


# ================ Configuration for multivariate model.
def load_multi_ex(file_dir: str) -> pd.DataFrame:
dataset = pd.read_csv(file_dir, delimiter="\t", index_col=0)
# Cleaning Data
dataset.dropna(how="any", axis=0, inplace=True)
dataset.replace(to_replace=".", value=np.NaN, inplace=True)
dataset.fillna(method="ffill", inplace=True)
dataset = dataset.astype(np.float32)
# DEXVZUS behaved abnomally
dataset.drop(columns=["DEXVZUS"], inplace=True)
return dataset


CON_config = {
"max_lag": 3,
"train_ratio": 0.9,
"time_steps": 14
}

NN_config = {
"batch_size": 32,
"validation_split": 0.1,
"nn.lstm1": 256,
"nn.lstm2": 128,
"nn.dense1": 64
}
16 changes: 15 additions & 1 deletion k models/exchange/local_visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,24 @@
from containers import *
from methods import *
from models import *
from config import *

file_dir = "./data/exchange_rates/exchange_rates_Daily.csv"

container = MultivariateContainer(
file_dir,
"DEXCAUS",
load_multi_ex,
CON_config)

# Create empty model
model = MultivariateLSTM(container, NN_config, create_empty=True)

load_target = "./saved_models/2018Sep11_14_01_1536688913/"

model.load_model(
folder_dir="./saved_models/2018Sep11_14_01_1536688913/")
folder_dir=load_target
)

# Testing Data

Expand Down
12 changes: 9 additions & 3 deletions k models/exchange/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ def fit_model(self):


class MultivariateLSTM(BaseModel):
def __init__(self, container, config=None) -> None:
def __init__(
self,
container,
config: bool=None,
create_empty: bool=False) -> None:
"""
Initialization method.
"""
Expand All @@ -99,9 +103,11 @@ def __init__(self, container, config=None) -> None:
\n\tFeature: {self.num_fea}")

self.config = config

self.container = container
self.core = self._construct_lstm(self.config)
if create_empty:
self.core = None
else:
self.core = self._construct_lstm(self.config)
self._gen_file_name()
print(
f"\tMultivariateLSTM: Current model will be save to ./saved_models/f{MultivariateLSTM}/")
Expand Down
29 changes: 2 additions & 27 deletions k models/exchange/multi_ex.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,11 @@
from containers import *
from methods import *
from models import *
from config import *

file_dir = "./data/exchange_rates/exchange_rates_Daily.csv"

def load_multi_ex(file_dir: str) -> pd.DataFrame:
dataset = pd.read_csv(file_dir, delimiter="\t", index_col=0)
# Cleaning Data
dataset.dropna(how="any", axis=0, inplace=True)
dataset.replace(to_replace=".", value=np.NaN, inplace=True)
dataset.fillna(method="ffill", inplace=True)
dataset = dataset.astype(np.float32)
# DEXVZUS behaved abnomally
dataset.drop(columns=["DEXVZUS"], inplace=True)
return dataset


# Setting up parameters.
CON_config = {
"max_lag": 3,
"train_ratio": 0.9,
"time_steps": 14
}

NN_config = {
"batch_size": 32,
"validation_split": 0.1,
"nn.lstm1": 256,
"nn.lstm2": 128,
"nn.dense1": 64
}

container = MultivariateContainer(
file_dir,
"DEXCAUS",
Expand All @@ -66,4 +41,4 @@ def load_multi_ex(file_dir: str) -> pd.DataFrame:

model = MultivariateLSTM(container, NN_config)
model.fit_model(epochs=int(input("Training epochs >>> ")))
model.save_model()
model.save_model()

0 comments on commit ee259d4

Please sign in to comment.