Commit 2e5e8d3d authored by Avisek Naug's avatar Avisek Naug 🎨
Browse files

Update modelretrain.py: initialize model architecture

parent f4360684
......@@ -3,7 +3,15 @@ Preprocessing/transformation/training functions for the energy model used in
the reinforcement learning agent's environment.
"""
from math import sqrt
from sklearn.metrics import mean_squared_error, mean_absolute_error
import numpy as np
from keras.models import Model
from keras.layers import Input, Dense, LSTM, RepeatVector, Reshape, Dropout, BatchNormalization, Activation
from keras.callbacks import TensorBoard
from keras.regularizers import L1L2
from keras.models import load_model
from keras.callbacks import ModelCheckpoint
from sklearn.model_selection import train_test_split
......@@ -12,7 +20,50 @@ from sklearn.preprocessing import MinMaxScaler
import scipy.signal as signal
from pandas import DataFrame
def createmodel(l1=0.01, l2=0.001, batch_size=1, time_steps=1,
inputfeatures=4, outputsequence=1, period=1,stateful=False):
"""
possible regularization strategies
"""
regularizers = L1L2(l1, l2)
"""
parameters
"""
timegap = period*5
batch_size = batch_size
time_steps = time_steps
inputfeatures = inputfeatures
outputsequence = outputsequence
outputfeatures = 1
"""
Design the network
"""
input_layer = Input(batch_shape=(None,time_steps,inputfeatures), name='input_layer')
reshape_layer = Reshape((time_steps*inputfeatures,),name='reshape_layer')(input_layer)
num_op = outputsequence
repeater = RepeatVector(num_op, name='repeater')(reshape_layer)
LSTM_layer = LSTM(16, return_sequences=True,
recurrent_regularizer=regularizers)(repeater)
#LSTM_layer = Dropout(0.2)(LSTM_layer)
LSTM_layer = LSTM(16, return_sequences=True,
recurrent_regularizer=regularizers)(LSTM_layer)
#LSTM_layer = Dropout(0.2)(LSTM_layer)
LSTM_layer = LSTM(8, return_sequences=True,
recurrent_regularizer=regularizers)(LSTM_layer)
#LSTM_layer = Dropout(0.2)(LSTM_layer)
LSTM_layer = LSTM(8, return_sequences=True,
recurrent_regularizer=regularizers)(LSTM_layer)
#LSTM_layer = Dropout(0.2)(LSTM_layer)
dense_layer = Dense(1)(LSTM_layer)
#dense_layer = BatchNormalization()(dense_layer)
dense_layer = Activation('linear')(dense_layer)
model = Model(inputs=input_layer, outputs=dense_layer)
model.compile(loss='mse', optimizer='adam')
return model
def retrain(model, data, epochs=25):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment