Skip to content

Commit

Permalink
style: add one space after commas for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
levaphenyl committed Dec 2, 2020
1 parent 1b1bda5 commit e7fc09e
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 54 deletions.
16 changes: 6 additions & 10 deletions nilmtk_contrib/disaggregate/WindowGRU.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,25 @@ def __init__(self, params):
self.max_val = 800
self.batch_size = params.get('batch_size',512)

def partial_fit(self,train_main,train_appliances,do_preprocessing=True,**load_kwargs):


def partial_fit(self, train_main, train_appliances, do_preprocessing=True, **load_kwargs):
if do_preprocessing:
train_main, train_appliances = self.call_preprocessing(train_main, train_appliances, 'train')

train_main = pd.concat(train_main,axis=0).values
train_main = train_main.reshape((-1,self.sequence_length,1))

train_main = train_main.reshape((-1, self.sequence_length, 1))
new_train_appliances = []
for app_name, app_df in train_appliances:
app_df = pd.concat(app_df,axis=0).values
app_df = app_df.reshape((-1,1))
app_df = pd.concat(app_df, axis=0).values
app_df = app_df.reshape((-1, 1))
new_train_appliances.append((app_name, app_df))

train_appliances = new_train_appliances
for app_name, app_df in train_appliances:
if app_name not in self.models:
print("First model training for ", app_name)
print("First model training for", app_name)
self.models[app_name] = self.return_network()
else:
print("Started re-training model for ", app_name)
print("Started re-training model for", app_name)

model = self.models[app_name]
mains = train_main.reshape((-1,self.sequence_length,1))
Expand All @@ -77,7 +74,6 @@ def partial_fit(self,train_main,train_appliances,do_preprocessing=True,**load_kw
)
model.load_weights(filepath)


def disaggregate_chunk(self,test_main_list,model=None,do_preprocessing=True):

if model is not None:
Expand Down
28 changes: 14 additions & 14 deletions nilmtk_contrib/disaggregate/dae.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
random.seed(10)
np.random.seed(10)
class DAE(Disaggregator):

def __init__(self, params):
"""
Iniititalize the moel with the given parameters
Expand All @@ -37,10 +37,8 @@ def __init__(self, params):
self.models = OrderedDict()
if self.load_model_path:
self.load_model()



def partial_fit(self, train_main, train_appliances, do_preprocessing=True,**load_kwargs):
def partial_fit(self, train_main, train_appliances, do_preprocessing=True, **load_kwargs):
"""
The partial fit function
"""
Expand All @@ -49,24 +47,26 @@ def partial_fit(self, train_main, train_appliances, do_preprocessing=True,**load
if len(self.appliance_params) == 0:
self.set_appliance_params(train_appliances)

# TO preprocess the data and bring it to a valid shape
# To preprocess the data and bring it to a valid shape
if do_preprocessing:
print ("Doing Preprocessing")
train_main,train_appliances = self.call_preprocessing(train_main,train_appliances,'train')
train_main = pd.concat(train_main,axis=0).values
train_main = train_main.reshape((-1,self.sequence_length,1))
print ("Preprocessing")
train_main, train_appliances = self.call_preprocessing(train_main, train_appliances, 'train')
train_main = pd.concat(train_main, axis=0).values
train_main = train_main.reshape((-1, self.sequence_length, 1))
new_train_appliances = []
for app_name, app_df in train_appliances:
app_df = pd.concat(app_df,axis=0).values
app_df = app_df.reshape((-1,self.sequence_length,1))
app_df = pd.concat(app_df, axis=0).values
app_df = app_df.reshape((-1, self.sequence_length, 1))
new_train_appliances.append((app_name, app_df))

train_appliances = new_train_appliances
for appliance_name, power in train_appliances:
if appliance_name not in self.models:
print ("First model training for ",appliance_name)
print("First model training for", appliance_name)
self.models[appliance_name] = self.return_network()
print (self.models[appliance_name].summary())
print ("Started Retraining model for ",appliance_name)
print(self.models[appliance_name].summary())

print("Started Retraining model for", appliance_name)
model = self.models[appliance_name]
filepath = 'dae-temp-weights-'+str(random.randint(0,100000))+'.h5'
checkpoint = ModelCheckpoint(filepath, monitor='val_loss', verbose=1, save_best_only=True, mode='min')
Expand Down
15 changes: 5 additions & 10 deletions nilmtk_contrib/disaggregate/rnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,23 @@ def __init__(self, params):
print ("Sequence length should be odd!")
raise (SequenceLengthError)

def partial_fit(self,train_main,train_appliances,do_preprocessing=True,
**load_kwargs):

def partial_fit(self, train_main, train_appliances, do_preprocessing=True, **load_kwargs):
# If no appliance wise parameters are provided, then copmute them using the first chunk
if len(self.appliance_params) == 0:
self.set_appliance_params(train_appliances)


print("...............RNN partial_fit running...............")
# Do the pre-processing, such as windowing and normalizing

if do_preprocessing:
train_main, train_appliances = self.call_preprocessing(
train_main, train_appliances, 'train')

train_main = pd.concat(train_main,axis=0)
train_main = train_main.values.reshape((-1,self.sequence_length,1))

train_main = pd.concat(train_main, axis=0)
train_main = train_main.values.reshape((-1, self.sequence_length, 1))
new_train_appliances = []
for app_name, app_df in train_appliances:
app_df = pd.concat(app_df,axis=0)
app_df_values = app_df.values.reshape((-1,1))
app_df = pd.concat(app_df, axis=0)
app_df_values = app_df.values.reshape(( -1, 1 ))
new_train_appliances.append((app_name, app_df_values))
train_appliances = new_train_appliances

Expand Down
18 changes: 7 additions & 11 deletions nilmtk_contrib/disaggregate/seq2point.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,38 +43,34 @@ def __init__(self, params):
print ("Sequence length should be odd!")
raise (SequenceLengthError)

def partial_fit(self,train_main,train_appliances,do_preprocessing=True,
**load_kwargs):

def partial_fit(self, train_main, train_appliances, do_preprocessing=True, **load_kwargs):
# If no appliance wise parameters are provided, then copmute them using the first chunk
if len(self.appliance_params) == 0:
self.set_appliance_params(train_appliances)

print("...............Seq2Point partial_fit running...............")
# Do the pre-processing, such as windowing and normalizing

if do_preprocessing:
train_main, train_appliances = self.call_preprocessing(
train_main, train_appliances, 'train')

train_main = pd.concat(train_main,axis=0)
train_main = train_main.values.reshape((-1,self.sequence_length,1))

train_main = pd.concat(train_main, axis=0)
train_main = train_main.values.reshape((-1, self.sequence_length, 1))
new_train_appliances = []
for app_name, app_df in train_appliances:
app_df = pd.concat(app_df,axis=0)
app_df_values = app_df.values.reshape((-1,1))
app_df = pd.concat(app_df, axis=0)
app_df_values = app_df.values.reshape((-1, 1))
new_train_appliances.append((app_name, app_df_values))
train_appliances = new_train_appliances

for appliance_name, power in train_appliances:
# Check if the appliance was already trained. If not then create a new model for it
if appliance_name not in self.models:
print("First model training for ", appliance_name)
print("First model training for", appliance_name)
self.models[appliance_name] = self.return_network()
# Retrain the particular appliance
else:
print("Started Retraining model for ", appliance_name)
print("Started Retraining model for", appliance_name)

model = self.models[appliance_name]
if train_main.size > 0:
Expand Down
16 changes: 7 additions & 9 deletions nilmtk_contrib/disaggregate/seq2seq.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,24 @@ def __init__(self, params):
print ("Sequence length should be odd!")
raise (SequenceLengthError)

def partial_fit(self,train_main,train_appliances,do_preprocessing=True,**load_kwargs):

def partial_fit(self, train_main, train_appliances, do_preprocessing=True, **load_kwargs):
print("...............Seq2Seq partial_fit running...............")
if len(self.appliance_params) == 0:
self.set_appliance_params(train_appliances)

print (len(train_main))
if do_preprocessing:
train_main, train_appliances = self.call_preprocessing(
train_main, train_appliances, 'train')
train_main = pd.concat(train_main,axis=0)
train_main = train_main.values.reshape((-1,self.sequence_length,1))


train_main = pd.concat(train_main, axis=0)
train_main = train_main.values.reshape((-1, self.sequence_length, 1))
new_train_appliances = []
for app_name, app_dfs in train_appliances:
app_df = pd.concat(app_dfs,axis=0)
app_df_values = app_df.values.reshape((-1,self.sequence_length))
app_df = pd.concat(app_dfs, axis=0)
app_df_values = app_df.values.reshape((-1, self.sequence_length))
new_train_appliances.append((app_name, app_df_values))
train_appliances = new_train_appliances

train_appliances = new_train_appliances
for appliance_name, power in train_appliances:
if appliance_name not in self.models:
print("First model training for ", appliance_name)
Expand Down

0 comments on commit e7fc09e

Please sign in to comment.