In [3]:
from __future__ import print_function, division
from neuralnilm import RealApplianceSource
import matplotlib.pyplot as plt
import numpy as np


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

In [91]:
source = RealApplianceSource(
    filename='/data/mine/vadeec/merged/ukdale.h5',
    appliances=[
        ['fridge freezer', 'fridge', 'freezer'], 
        'hair straighteners', 
        'television',
        'dish washer',
        ['washer dryer', 'washing machine']
    ],
    max_appliance_powers=[300, 500, 200, 2500, 2400],
    n_seq_per_batch=2,
    max_input_power=5900,
    on_power_thresholds=[20, 20, 20, 20, 10],
    min_on_durations=[60, 60, 60, 1800, 1800],
    window=("2013-06-01", "2013-07-01"),
    seq_length=1500,
    output_one_appliance=False,
    boolean_targets=False,
    min_off_durations=[60] * 5,
    subsample_target=5,
    train_buildings=[1],
    validation_buildings=[1],
    skip_probability=0.7
)


Loading training activations...
  Loading activations for fridge freezer from building 1... Loaded 803 activations.
  Loading activations for hair straighteners from building 1... Loaded 7 activations.
  Loading activations for television from building 1... Loaded 41 activations.
  Loading activations for dish washer from building 1... Loaded 7 activations.
  Loading activations for washer dryer from building 1... Loaded 22 activations.

Done loading activations.

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

In [93]:
def cost(x, t):
    return (x - t) ** 2

In [94]:
t = y
noise = np.random.randn(*y.shape) * 0.1
x = t + noise
raw_cost = (x - t) ** 2

In [102]:
sum_over_sequences = t.sum(axis=1)
sum_over_sequences


Out[102]:
array([[   6.18933296,    4.22200012,   27.93600082,    0.        ,
          45.60556793],
       [   0.        ,    0.        ,  135.63398743,   22.02120399,
          42.0132103 ]], dtype=float32)

In [103]:
sum_over_batches = sum_over_sequences.sum(axis=1)

In [104]:
sum_over_batches = sum_over_batches.reshape(-1,1)
sum_over_batches


Out[104]:
array([[  83.95290375],
       [ 199.66841125]], dtype=float32)

In [105]:
normed = sum_over_sequences / sum_over_batches
normed


Out[105]:
array([[ 0.07372387,  0.0502901 ,  0.33275801,  0.        ,  0.54322797],
       [ 0.        ,  0.        ,  0.6792962 ,  0.11028887,  0.2104149 ]], dtype=float32)

In [108]:
normed[1,:].sum()


Out[108]:
0.99999994

In [111]:
raw_cost.mean(axis=1)


Out[111]:
array([[ 0.00975108,  0.01062885,  0.01111484,  0.00839669,  0.0100884 ],
       [ 0.01061563,  0.01073628,  0.01170655,  0.01119199,  0.01029221]])

In [122]:
cost = raw_cost.mean(axis=1) * (1 - normed)
cost


Out[122]:
array([[ 0.00903219,  0.01009432,  0.00741628,  0.00839669,  0.0046081 ],
       [ 0.01061563,  0.01073628,  0.00375433,  0.00995764,  0.00812658]])

In [123]:
cost.mean()


Out[123]:
0.0082738055891949103

In [119]:
1 - normed


Out[119]:
array([[ 0.92627615,  0.94970989,  0.66724199,  1.        ,  0.45677203],
       [ 1.        ,  1.        ,  0.3207038 ,  0.88971114,  0.78958511]], dtype=float32)

In [116]:
normed / normed.sum(axis=1)


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-116-2eaea8a3dc75> in <module>()
----> 1 normed / normed.sum(axis=1)

ValueError: operands could not be broadcast together with shapes (2,5) (2,) 

In [117]:
normed.sum(axis=1)


Out[117]:
array([ 0.99999994,  0.99999994], dtype=float32)

In [ ]: