In [1]:
from neuralnilm import RealApplianceSource
import matplotlib.pyplot as plt
import numpy as np


/home/jack/workspace/python/nntools/lasagne/init.py:86: UserWarning: The uniform initializer no longer uses Glorot et al.'s approach to determine the bounds, but defaults to the range (-0.01, 0.01) instead. Please use the new GlorotUniform initializer to get the old behavior. GlorotUniform is now the default for all layers.
  warnings.warn("The uniform initializer no longer uses Glorot et al.'s "

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
)


Loading training activations...
INFO:neuralnilm.source:Loading training activations...
  Loading activations for fridge freezer from building 1...
INFO:neuralnilm.source:  Loading activations for fridge freezer from building 1...
Loaded 760 activations.
INFO:neuralnilm.source:Loaded 760 activations.
  Loading activations for washer dryer from building 1...
INFO:neuralnilm.source:  Loading activations for washer dryer from building 1...
Loaded 22 activations.
INFO:neuralnilm.source:Loaded 22 activations.
  Loading activations for hair straighteners from building 1...
INFO:neuralnilm.source:  Loading activations for hair straighteners from building 1...
Loaded 16 activations.
INFO:neuralnilm.source:Loaded 16 activations.
  Loading activations for television from building 1...
INFO:neuralnilm.source:  Loading activations for television from building 1...
Loaded 52 activations.
INFO:neuralnilm.source:Loaded 52 activations.
  Loading activations for dish washer from building 1...
INFO:neuralnilm.source:  Loading activations for dish washer from building 1...
Loaded 11 activations.
INFO:neuralnilm.source:Loaded 11 activations.
Done loading activations.
INFO:neuralnilm.source:Done loading activations.

In [3]:
X, y = source._gen_data()
X, y = source._process_data(X, y)

In [9]:
y[0]


Out[9]:
array([[ 0.47070312,  0.        ,  0.        ,  0.0078125 ,  0.        ],
       [ 0.66796875,  0.        ,  0.        ,  0.99804688,  0.        ],
       [ 0.28838283,  0.        ,  0.        ,  0.56630176,  0.        ]])

In [13]:
len(source.train_activations['fridge freezer'])


Out[13]:
823

In [ ]:


In [14]:
plt.plot(X[3,:,:]); plt.show()

In [12]:
source.target_stats


Out[12]:
{'mean': array([ 0.], dtype=float32), 'std': array([ 0.], dtype=float32)}

In [3]:
source.start()

In [5]:
X.shape


Out[5]:
(8, 64, 1)

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]:
0.20007956572024463

In [7]:
X[SEQ_I,:,:].std()


Out[7]:
1.2653309337904646

In [8]:
source.input_stats


Out[8]:
{'mean': array([ 0.04142749], dtype=float32),
 'std': array([ 0.10218309], dtype=float32)}

In [33]:
plt.plot(y[0,:,:])


Out[33]:
[<matplotlib.lines.Line2D at 0x7fbf612135d0>]

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]:
array([[ 0.        ,  0.        ,  2.14326191,  0.1450543 ,  0.48895144]])

In [28]:
source.target_stats


Out[28]:
{'mean': array([ 0.04066789,  0.01881946,  0.24639061,  0.17608672,  0.10273963], dtype=float32),
 'std': array([ 0.11449792,  0.07338708,  0.26608968,  0.33463112,  0.21250485], dtype=float32)}

In [9]:
y.min()


Out[9]:
0.0

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]:
array([ -2.48352684e-12,   1.46666716e-05,   5.46665751e-06,
         4.00013960e-07,   6.26781002e-07], dtype=float32)

In [7]:
plt.plot(y.reshape(10*1500, 5))
plt.show()


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-7-52a6256b067f> in <module>()
----> 1 plt.plot(y.reshape(10*1500, 5))
      2 plt.show()

ValueError: total size of new array must be unchanged

In [15]:
y.reshape(10*1500, 5).std(axis=0)


Out[15]:
array([ 0.0084313 ,  0.00956285,  0.00271722,  0.03271817,  0.07027333], dtype=float32)

In [7]:
X.reshape(10*1500, 1).std(axis=0)[0]


Out[7]:
0.13455896

In [49]:
import numpy as np
any(np.isnan(X.flatten()))


Out[49]:
False

In [50]:
any(np.isnan(y.flatten()))


Out[50]:
False

Test SubsampleLayer


In [1]:
from neuralnilm.net import SubsampleLayer


Couldn't import dot_parser, loading of dot files will not be possible.

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]:
(5, 200, 1)

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)


1
2
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-27-a5790709ee0a> in <module>()
      1 try:
----> 2     a = b
      3 except:
      4     print(1)
      5     raise

NameError: name 'b' is not defined

In [8]:
y.shape


Out[8]:
(10, 300, 5)

In [15]:
b = y > 0

In [17]:
inactive = b.sum(axis=1) == 0

In [18]:
inactive.shape


Out[18]:
(10, 5)

In [20]:
inactive


Out[20]:
array([[False,  True, False,  True,  True],
       [False,  True,  True, False, False],
       [False,  True,  True,  True,  True],
       [False,  True,  True,  True,  True],
       [False,  True, False,  True, False],
       [ True,  True,  True, False,  True],
       [ True,  True,  True,  True, False],
       [False,  True,  True,  True,  True],
       [False,  True, False,  True, False],
       [False,  True,  True,  True, False]], dtype=bool)

In [35]:



Out[35]:
(1, 3000, 5)

In [22]:
inactive[0]


Out[22]:
array([False,  True, False,  True,  True], dtype=bool)

In [46]:
np.swapaxes(y,2,1)[inactive].shape


Out[46]:
(32, 300)

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]:
array([[0, 1, 0, 1, 1],
       [0, 1, 1, 0, 0],
       [0, 1, 1, 1, 1],
       [0, 1, 1, 1, 1],
       [0, 1, 0, 1, 0],
       [1, 1, 1, 0, 1],
       [1, 1, 1, 1, 0],
       [0, 1, 1, 1, 1],
       [0, 1, 0, 1, 0],
       [0, 1, 1, 1, 0]], dtype=int8)

In [98]:
yt.dimshuffle(0,2,1)[inactivet.nonzero()].shape.eval()


Out[98]:
array([ 32, 300])

In [99]:
data = yt.dimshuffle(0,2,1)[inactivet.nonzero()].eval()

In [101]:
plt.plot(data[0])


Out[101]:
[<matplotlib.lines.Line2D at 0x7f2ca82b3dd0>]

In [ ]: