In [1]:
from neuralnilm import RealApplianceSource
import matplotlib.pyplot as plt
import numpy as np
In [2]:
source = RealApplianceSource(
filename='/data/mine/vadeec/merged/ukdale.h5',
appliances=[
['fridge freezer', 'fridge', 'freezer'],
['washer dryer', 'washing machine'],
'hair straighteners',
'television',
'dish washer'
],
max_appliance_powers=[300, 2400, 500, 200, 2500],
on_power_thresholds=[5] * 5,
min_on_durations=[60, 1800, 60, 60, 1800],
min_off_durations=[12, 600, 12, 12, 1800],
window=("2013-03-18", "2013-04-18"),
seq_length=512,
output_one_appliance=False,
train_buildings=[1],
validation_buildings=[1],
n_seq_per_batch=8,
standardise_input=True,
independently_center_inputs=False,
skip_probability=0.75,
skip_probability_for_first_appliance=0.5,
target_is_start_and_end_and_mean=True
)
In [3]:
X, y = source._gen_data()
X, y = source._process_data(X, y)
In [9]:
y[0]
Out[9]:
In [13]:
len(source.train_activations['fridge freezer'])
Out[13]:
In [ ]:
In [14]:
plt.plot(X[3,:,:]); plt.show()
In [12]:
source.target_stats
Out[12]:
In [3]:
source.start()
In [5]:
X.shape
Out[5]:
In [7]:
#source.standardise_input = True
X, y = source.queue.get()
In [16]:
#source.input_stats = {'std': np.array([0.01], dtype=np.float32)}
X, y = source._gen_data()
X, y = source._process_data(X, y)
In [17]:
SEQ_I = 7
plt.plot(X[SEQ_I,:,:])
plt.show()
In [6]:
X[SEQ_I,:,:].mean()
Out[6]:
In [7]:
X[SEQ_I,:,:].std()
Out[7]:
In [8]:
source.input_stats
Out[8]:
In [33]:
plt.plot(y[0,:,:])
Out[33]:
In [9]:
lines = plt.plot(y[4,:,:])
plt.legend([label for label in source.get_labels()], framealpha=.5)
plt.show()
In [8]:
y[0]
Out[8]:
In [28]:
source.target_stats
Out[28]:
In [9]:
y.min()
Out[9]:
In [8]:
import numpy as np
fig, ax = plt.subplots()
ax.plot(np.sum(y[2,:,:], axis=1), label='appliances')
ax.plot(X[2,:,:], label='mains')
plt.legend()
plt.show()
In [14]:
y.mean(axis=0).mean(axis=0)
Out[14]:
In [7]:
plt.plot(y.reshape(10*1500, 5))
plt.show()
In [15]:
y.reshape(10*1500, 5).std(axis=0)
Out[15]:
In [7]:
X.reshape(10*1500, 1).std(axis=0)[0]
Out[7]:
In [49]:
import numpy as np
any(np.isnan(X.flatten()))
Out[49]:
In [50]:
any(np.isnan(y.flatten()))
Out[50]:
In [1]:
from neuralnilm.net import SubsampleLayer
In [3]:
sub = SubsampleLayer(None, 5)
In [7]:
sub.input_shape = X.shape
In [9]:
out = sub.get_output_for(X)
In [10]:
out.shape
Out[10]:
In [15]:
plt.plot(out[0,:,:])
plt.show()
In [11]:
from nilmtk import DataSet
ds = DataSet('/data/mine/vadeec/merged/ukdale.h5')
In [12]:
elec = ds.buildings[1].elec
meter = elec['washer dryer']
In [13]:
activations = meter.activation_series()
In [18]:
activations[3].plot()
plt.show()
In [27]:
try:
a = b
except:
print(1)
raise
finally:
print(2)
In [8]:
y.shape
Out[8]:
In [15]:
b = y > 0
In [17]:
inactive = b.sum(axis=1) == 0
In [18]:
inactive.shape
Out[18]:
In [20]:
inactive
Out[20]:
In [35]:
Out[35]:
In [22]:
inactive[0]
Out[22]:
In [46]:
np.swapaxes(y,2,1)[inactive].shape
Out[46]:
In [48]:
import theano
import theano.tensor as T
In [50]:
yt = theano.shared(y, name='y')
In [51]:
bt = yt > 0
In [96]:
inactivet = bt.sum(axis=1) <= 0
In [97]:
inactivet.eval()
Out[97]:
In [98]:
yt.dimshuffle(0,2,1)[inactivet.nonzero()].shape.eval()
Out[98]:
In [99]:
data = yt.dimshuffle(0,2,1)[inactivet.nonzero()].eval()
In [101]:
plt.plot(data[0])
Out[101]:
In [ ]: