Example #1
0
def exp_a(name):
    # 151d but training for much longer and skip prob = 0.7
    source = RealApplianceSource(
        filename='/data/dk3810/ukdale.h5',
        appliances=
        [['fridge freezer', 'fridge', 'freezer'], 'hair straighteners',
         'television'
         #            'dish washer'
         #            ['washer dryer', 'washing machine']
         ],
        max_appliance_powers=None,  #[200, 100, 200, 2500, 2400],
        on_power_thresholds=[5, 5, 5, 5, 5],
        max_input_power=5900,
        min_on_durations=[60, 60, 60, 1800, 1800],
        min_off_durations=[12, 12, 12, 1800, 600],
        window=("2013-06-01", "2014-07-01"),
        seq_length=1500,
        output_one_appliance=False,
        boolean_targets=False,
        train_buildings=[1],
        validation_buildings=[1],
        skip_probability=0.0,
        n_seq_per_batch=25,
        include_diff=True)

    net = Net(experiment_name=name,
              source=source,
              save_plot_interval=250,
              loss_function=mse,
              updates=partial(nesterov_momentum,
                              learning_rate=.0001,
                              clip_range=(-1, 1)),
              layers_config=[{
                  'type': LSTMLayer,
                  'num_units': 50,
                  'W_in_to_cell': Uniform(25),
                  'gradient_steps': GRADIENT_STEPS,
                  'peepholes': False
              }, {
                  'type': LSTMLayer,
                  'num_units': 50,
                  'W_in_to_cell': Uniform(1),
                  'gradient_steps': GRADIENT_STEPS,
                  'peepholes': False
              }, {
                  'type': DenseLayer,
                  'num_units': 50,
                  'nonlinearity': rectify
              }, {
                  'type': DenseLayer,
                  'num_units': source.n_outputs,
                  'nonlinearity': None,
                  'W': Uniform(25)
              }])
    return net
Example #2
0
def exp_l(name):
    # 4 layers
    # avg valid cost =  0.5094475150
    source_dict_copy = deepcopy(source_dict)
    source = RealApplianceSource(**source_dict_copy)
    net_dict_copy = deepcopy(net_dict)
    net_dict_copy.update(dict(
        experiment_name=name,
        source=source
    ))
    N = 50
    net_dict_copy['layers_config'] = [
        {
            'type': BidirectionalRecurrentLayer,
            'num_units': N,
            'gradient_steps': GRADIENT_STEPS,
            'W_in_to_hid': Normal(std=1.),
            'nonlinearity': tanh
        },
        {
            'type': BidirectionalRecurrentLayer,
            'num_units': N,
            'gradient_steps': GRADIENT_STEPS,
            'W_in_to_hid': Normal(std=1/sqrt(N)),
            'nonlinearity': tanh
        },
        {
            'type': FeaturePoolLayer,
            'ds': 3, # number of feature maps to be pooled together
            'axis': 1, # pool over the time axis
            'pool_function': T.max
        },
        {
            'type': BidirectionalRecurrentLayer,
            'num_units': N,
            'gradient_steps': GRADIENT_STEPS,
            'W_in_to_hid': Normal(std=1/sqrt(N)),
            'nonlinearity': tanh
        },
        {
            'type': BidirectionalRecurrentLayer,
            'num_units': N,
            'gradient_steps': GRADIENT_STEPS,
            'W_in_to_hid': Normal(std=1/sqrt(N)),
            'nonlinearity': tanh
        },
        {
            'type': DenseLayer,
            'num_units': source.n_outputs,
            'nonlinearity': None,
            'W': Normal(std=(1/sqrt(N)))
        }
    ]
    net = Net(**net_dict_copy)
    return net
Example #3
0
def exp_a(name):
    # Bool target
    source = RealApplianceSource(
        filename='/data/dk3810/ukdale.h5',
        appliances=[['fridge freezer', 'fridge', 'freezer'],
                    'hair straighteners', 'television', 'dish washer',
                    ['washer dryer', 'washing machine']],
        max_appliance_powers=[300, 500, 200, 2500, 2400],
        on_power_thresholds=[5, 5, 5, 5, 5],
        max_input_power=None,
        min_on_durations=[60, 60, 60, 1800, 1800],
        min_off_durations=[12, 12, 12, 1800, 600],
        window=("2013-06-01", "2014-07-01"),
        seq_length=1500,
        output_one_appliance=False,
        boolean_targets=True,
        train_buildings=[1],
        validation_buildings=[1],
        skip_probability=0.7,
        n_seq_per_batch=50)

    net = Net(experiment_name=name,
              source=source,
              save_plot_interval=SAVE_PLOT_INTERVAL,
              loss_function=crossentropy,
              updates=partial(nesterov_momentum, learning_rate=1.0),
              layers_config=[{
                  'type': BLSTMLayer,
                  'num_units': 50,
                  'W_in_to_cell': Uniform(25),
                  'gradient_steps': GRADIENT_STEPS,
                  'peepholes': False
              }, {
                  'type': DenseLayer,
                  'num_units': source.n_outputs,
                  'nonlinearity': sigmoid
              }],
              layer_changes={
                  2001: {
                      'remove_from':
                      -3,
                      'new_layers': [{
                          'type': BLSTMLayer,
                          'num_units': 50,
                          'W_in_to_cell': Uniform(5),
                          'gradient_steps': GRADIENT_STEPS,
                          'peepholes': False
                      }, {
                          'type': DenseLayer,
                          'num_units': source.n_outputs,
                          'nonlinearity': sigmoid
                      }]
                  }
              })
    return net
Example #4
0
def exp_i(name):
    # e59 (but with softplus output, BiRNN, gradient_steps, learn_init=false,
    # conv1d stride=4 not 5), single target appliance
    source_dict_copy = deepcopy(source_dict)
    source = RealApplianceSource(**source_dict_copy)
    net_dict_copy = deepcopy(net_dict)
    net_dict_copy.update(
        dict(experiment_name=name, source=source, learning_rate=1e-2))
    net_dict_copy['layers_config'] = [{
        'type': DenseLayer,
        'num_units': 50,
        'nonlinearity': sigmoid,
        'W': Uniform(25),
        'b': Uniform(25)
    }, {
        'type': DenseLayer,
        'num_units': 50,
        'nonlinearity': sigmoid,
        'W': Uniform(10),
        'b': Uniform(10)
    }, {
        'type': BidirectionalRecurrentLayer,
        'num_units': 40,
        'W_in_to_hid': Uniform(5),
        'gradient_steps': GRADIENT_STEPS,
        'nonlinearity': sigmoid,
        'learn_init': False,
        'precompute_input': False
    }, {
        'type': DimshuffleLayer,
        'pattern': (0, 2, 1)
    }, {
        'type': Conv1DLayer,
        'num_filters': 20,
        'filter_length': 4,
        'stride': 4,
        'nonlinearity': sigmoid
    }, {
        'type': DimshuffleLayer,
        'pattern': (0, 2, 1)
    }, {
        'type': BidirectionalRecurrentLayer,
        'num_units': 80,
        'W_in_to_hid': Uniform(5),
        'gradient_steps': GRADIENT_STEPS,
        'nonlinearity': sigmoid,
        'learn_init': False,
        'precompute_input': False
    }, {
        'type': DenseLayer,
        'num_units': source.n_outputs,
        'nonlinearity': T.nnet.softplus
    }]
    net = Net(**net_dict_copy)
    return net
Example #5
0
def exp_e(name):
    """
    e380 again
    """

    source_dict_copy = deepcopy(source_dict)
    source = RealApplianceSource(**source_dict_copy)
    net_dict_copy = deepcopy(net_dict)
    net_dict_copy.update(dict(experiment_name=name, source=source))
    net_dict_copy['layers_config'] = [{
        'type': DimshuffleLayer,
        'pattern': (0, 2, 1)
    }, {
        'type': Conv1DLayer,
        'num_filters': 40,
        'filter_length': 2,
        'stride': 1,
        'nonlinearity': tanh,
        'border_mode': 'same'
    }, {
        'type': DimshuffleLayer,
        'pattern': (0, 2, 1)
    }, {
        'type': BidirectionalRecurrentLayer,
        'num_units': 40,
        'gradient_steps': GRADIENT_STEPS,
        'nonlinearity': tanh,
        'learn_init': False,
        'precompute_input': False
    }, {
        'type': DimshuffleLayer,
        'pattern': (0, 2, 1)
    }, {
        'type': Conv1DLayer,
        'num_filters': 40,
        'filter_length': 4,
        'stride': 4,
        'nonlinearity': tanh
    }, {
        'type': DimshuffleLayer,
        'pattern': (0, 2, 1)
    }, {
        'type': BidirectionalRecurrentLayer,
        'num_units': 40,
        'gradient_steps': GRADIENT_STEPS,
        'nonlinearity': tanh,
        'learn_init': False,
        'precompute_input': False
    }, {
        'type': DenseLayer,
        'num_units': source.n_outputs,
        'nonlinearity': T.nnet.softplus
    }]
    net = Net(**net_dict_copy)
    return net
Example #6
0
def exp_a(name):
    # 3 appliances
    global source
    source_dict_copy = deepcopy(source_dict)
    source_dict_copy['reshape_target_to_2D'] = False
    source = RealApplianceSource(**source_dict_copy)
    source.reshape_target_to_2D = False
    net_dict_copy = deepcopy(net_dict)
    net_dict_copy.update(dict(experiment_name=name, source=source))
    N = 50
    net_dict_copy['layers_config'] = [
        {
            'type': BidirectionalRecurrentLayer,
            'num_units': N,
            'gradient_steps': GRADIENT_STEPS,
            'W_in_to_hid': Normal(std=1.),
            'nonlinearity': tanh
        },
        {
            'type': FeaturePoolLayer,
            'ds': 4,  # number of feature maps to be pooled together
            'axis': 1,  # pool over the time axis
            'pool_function': T.max
        },
        {
            'type': BidirectionalRecurrentLayer,
            'num_units': N,
            'gradient_steps': GRADIENT_STEPS,
            'W_in_to_hid': Normal(std=1 / sqrt(N)),
            'nonlinearity': tanh
        },
        {
            'type': DenseLayer,
            'W': Normal(std=1 / sqrt(N)),
            'num_units': source.n_outputs,
            'nonlinearity': None
        }
    ]
    net_dict_copy['layer_changes'] = {
        5001: {
            'remove_from':
            -2,
            'callback':
            callback,
            'new_layers': [{
                'type': MixtureDensityLayer,
                'num_units': source.n_outputs,
                'num_components': 2
            }]
        }
    }

    net = Net(**net_dict_copy)
    return net
Example #7
0
def exp_r(name):
    # 4 layers
    # best valid cost =  0.2410877943 at iteration   480
    # probably needs longer to train!
    global source
    source_dict_copy = deepcopy(source_dict)
    source_dict_copy['subsample_target'] = 5
    source = RealApplianceSource(**source_dict_copy)
    net_dict_copy = deepcopy(net_dict)
    net_dict_copy.update(dict(experiment_name=name, source=source))
    net_dict_copy['layers_config'] = [
        {
            'type': BidirectionalRecurrentLayer,
            'num_units': 25,
            'gradient_steps': GRADIENT_STEPS,
            'W_in_to_hid': Normal(std=1.),
            'nonlinearity': tanh
        },
        {
            'type': BidirectionalRecurrentLayer,
            'num_units': 25,
            'gradient_steps': GRADIENT_STEPS,
            'W_in_to_hid': Normal(std=1 / sqrt(25)),
            'nonlinearity': tanh
        },
        {
            'type': FeaturePoolLayer,
            'ds': 5,  # number of feature maps to be pooled together
            'axis': 1,  # pool over the time axis
            'pool_function': T.mean
        },
        {
            'type': BidirectionalRecurrentLayer,
            'num_units': 25,
            'gradient_steps': GRADIENT_STEPS,
            'W_in_to_hid': Normal(std=1 / sqrt(25)),
            'nonlinearity': tanh
        },
        {
            'type': BidirectionalRecurrentLayer,
            'num_units': 25,
            'gradient_steps': GRADIENT_STEPS,
            'W_in_to_hid': Normal(std=1 / sqrt(25)),
            'nonlinearity': tanh
        },
        {
            'type': DenseLayer,
            'num_units': source.n_outputs,
            'nonlinearity': None,
            'W': Normal(std=(1 / sqrt(25)))
        }
    ]
    net = Net(**net_dict_copy)
    return net
Example #8
0
def exp_a(name):
    source = RealApplianceSource(**source_dict)
    net_dict_copy = deepcopy(net_dict)
    net_dict_copy.update(dict(experiment_name=name, source=source))
    net_dict_copy['layers_config'].append({
        'type': DenseLayer,
        'num_units': source.n_outputs,
        'nonlinearity': sigmoid
    })
    net = Net(**net_dict_copy)
    return net
Example #9
0
def exp_a(name):
    global source
    source_dict_copy = deepcopy(source_dict)
    source = RealApplianceSource(**source_dict_copy)
    net_dict_copy = deepcopy(net_dict)
    net_dict_copy.update(dict(
        experiment_name=name,
        source=source
    ))
    N = 50
    net_dict_copy['layers_config'] = [
        {
            'type': BLSTMLayer,
            'num_units': N,
            'gradient_steps': GRADIENT_STEPS,
            'peepholes': True,
            'W_in_to_cell': Normal(std=1.)
        },
        {
            'type': FeaturePoolLayer,
            'ds': 2, # number of feature maps to be pooled together
            'axis': 1, # pool over the time axis
            'pool_function': T.max
        },
        {
            'type': BLSTMLayer,
            'num_units': N,
            'gradient_steps': GRADIENT_STEPS,
            'peepholes': True,
            'W_in_to_cell': Normal(std=1/sqrt(N))
        },
        {
            'type': FeaturePoolLayer,
            'ds': 2, # number of feature maps to be pooled together
            'axis': 1, # pool over the time axis
            'pool_function': T.max
        },
        {
            'type': BLSTMLayer,
            'num_units': N,
            'gradient_steps': GRADIENT_STEPS,
            'peepholes': True,
            'W_in_to_cell': Normal(std=1/sqrt(N))
        },
        {
            'type': DenseLayer,
            'num_units': source.n_outputs,
            'W': Normal(std=1/sqrt(N)),
            'nonlinearity': T.nnet.softplus
        }
    ]
    net = Net(**net_dict_copy)
    return net
Example #10
0
def exp_a(name):
    global source
    source_dict_copy = deepcopy(source_dict)
    source = RealApplianceSource(**source_dict_copy)
    net_dict_copy = deepcopy(net_dict)
    net_dict_copy.update(dict(
        experiment_name=name,
        source=source
    ))
    net_dict_copy['layers_config'] = [
        {
            'type': DimshuffleLayer,
            'pattern': (0, 2, 1)  # (batch, features, time)
        },
        {
            'type': Conv1DLayer,  # convolve over the time axis
            'num_filters': 16,
            'filter_length': 4,
            'stride': 1,
            'nonlinearity': rectify,
        },
        {
            'type': DimshuffleLayer,
            'pattern': (0, 2, 1)  # back to (batch, time, features)
        },
        {
            'type': DenseLayer,
            'num_units': SEQ_LENGTH,
            'nonlinearity': rectify
        },
        {
            'type': DenseLayer,
            'num_units': SEQ_LENGTH // 4,
            'nonlinearity': rectify
        },
        {
            'type': DenseLayer,
            'num_units': 32,
            'nonlinearity': rectify
        },
        {
            'type': DenseLayer,
            'num_units': SEQ_LENGTH // 4,
            'nonlinearity': rectify
        },
        {
            'type': DenseLayer,
            'num_units': SEQ_LENGTH,
            'nonlinearity': None
        }
    ]
    net = Net(**net_dict_copy)
    return net
Example #11
0
def exp_j(name):
    """Trains to all 3000 epochs.  Not sure it's doing very well though."""
    print(
        "e82 but with seq length 2000 and 5 appliances and *learning rate 0.01* and train on houses 1-4, validate on house 5, only output fridge"
    )
    source = RealApplianceSource(
        filename='/data/dk3810/ukdale.h5',
        appliances=[['fridge freezer', 'fridge', 'freezer'],
                    'hair straighteners', 'television', 'dish washer',
                    ['washer dryer', 'washing machine']],
        max_appliance_powers=[300, 500, 200, 2500, 2400],
        on_power_thresholds=[80, 20, 20, 20, 600],
        min_on_durations=[60, 60, 60, 300, 300],
        window=("2013-05-01", "2015-01-01"),
        seq_length=2000,
        output_one_appliance=True,
        boolean_targets=False,
        min_off_duration=60,
        subsample_target=5,
        train_buildings=[1, 2, 3, 4],
        validation_buildings=[5])

    net = Net(experiment_name=name + 'j',
              source=source,
              save_plot_interval=SAVE_PLOT_INTERVAL,
              loss_function=crossentropy,
              updates=partial(nesterov_momentum, learning_rate=0.01),
              layers_config=[{
                  'type': BLSTMLayer,
                  'num_units': 60,
                  'W_in_to_cell': Uniform(5)
              }, {
                  'type': DimshuffleLayer,
                  'pattern': (0, 2, 1)
              }, {
                  'type': Conv1DLayer,
                  'num_filters': 80,
                  'filter_length': 5,
                  'stride': 5,
                  'nonlinearity': sigmoid
              }, {
                  'type': DimshuffleLayer,
                  'pattern': (0, 2, 1)
              }, {
                  'type': BLSTMLayer,
                  'num_units': 80,
                  'W_in_to_cell': Uniform(5)
              }, {
                  'type': DenseLayer,
                  'num_units': source.n_outputs,
                  'nonlinearity': sigmoid
              }])
    return net
Example #12
0
def exp_d(name):
    # Same as above but with learning rate = 0.001
    source = RealApplianceSource(
        filename='/data/dk3810/ukdale.h5',
        appliances=[['fridge freezer', 'fridge', 'freezer'],
                    'hair straighteners', 'television'
                    # 'dish washer',
                    # ['washer dryer', 'washing machine']
                    ],
        max_appliance_powers=[300, 500, 200],  #, 2500, 2400],
        on_power_thresholds=[20, 20, 20],  #, 20, 20],
        max_input_power=1000,
        min_on_durations=[60, 60, 60],  #, 1800, 1800],
        window=("2013-06-01", "2014-07-01"),
        seq_length=1000,
        output_one_appliance=False,
        boolean_targets=False,
        min_off_duration=60,
        train_buildings=[1],
        validation_buildings=[1],
        skip_probability=0,
        n_seq_per_batch=5)

    net = Net(experiment_name=name,
              source=source,
              save_plot_interval=SAVE_PLOT_INTERVAL,
              loss_function=crossentropy,
              updates=partial(nesterov_momentum, learning_rate=0.001),
              layers_config=[{
                  'type': DenseLayer,
                  'num_units': 50,
                  'nonlinearity': sigmoid,
                  'b': Uniform(25),
                  'W': Uniform(25)
              }, {
                  'type': DenseLayer,
                  'num_units': 50,
                  'nonlinearity': sigmoid,
                  'b': Uniform(10),
                  'W': Uniform(10)
              }, {
                  'type': LSTMLayer,
                  'num_units': 50,
                  'W_in_to_cell': Uniform(5),
                  'gradient_steps': GRADIENT_STEPS,
                  'peepholes': False
              }, {
                  'type': DenseLayer,
                  'num_units': source.n_outputs,
                  'nonlinearity': sigmoid
              }])
    return net
Example #13
0
def exp_d(name):
    """Dies immediately"""
    print("e82 but with seq length 2000 and 5 appliances")
    """RESULT: NaNs!!!"""
    source = RealApplianceSource(
        filename='/data/dk3810/ukdale.h5',
        appliances=[['fridge freezer', 'fridge', 'freezer'],
                    'hair straighteners', 'television', 'dish washer',
                    ['washer dryer', 'washing machine']],
        max_appliance_powers=[300, 500, 200, 2500, 2400],
        on_power_thresholds=[80, 20, 20, 20, 600],
        min_on_durations=[60, 60, 60, 300, 300],
        window=("2013-06-01", "2014-07-01"),
        seq_length=2000,
        output_one_appliance=False,
        boolean_targets=False,
        min_off_duration=60,
        subsample_target=5,
        train_buildings=[1],
        validation_buildings=[1])

    net = Net(experiment_name=name + 'd',
              source=source,
              save_plot_interval=SAVE_PLOT_INTERVAL,
              loss_function=crossentropy,
              updates=partial(nesterov_momentum, learning_rate=0.1),
              layers_config=[{
                  'type': BLSTMLayer,
                  'num_units': 60,
                  'W_in_to_cell': Uniform(5)
              }, {
                  'type': DimshuffleLayer,
                  'pattern': (0, 2, 1)
              }, {
                  'type': Conv1DLayer,
                  'num_filters': 80,
                  'filter_length': 5,
                  'stride': 5,
                  'nonlinearity': sigmoid
              }, {
                  'type': DimshuffleLayer,
                  'pattern': (0, 2, 1)
              }, {
                  'type': BLSTMLayer,
                  'num_units': 80,
                  'W_in_to_cell': Uniform(5)
              }, {
                  'type': DenseLayer,
                  'num_units': source.n_outputs,
                  'nonlinearity': sigmoid
              }])
    return net
Example #14
0
def exp_k(name):
    # Pool over 2 x 2
    # works pretty nicely. best valid = 0.1998
    global source
    source_dict_copy = deepcopy(source_dict)
    source_dict_copy['subsample_target'] = 4
    source = RealApplianceSource(**source_dict_copy)
    net_dict_copy = deepcopy(net_dict)
    net_dict_copy.update(dict(experiment_name=name, source=source))
    net_dict_copy['layers_config'] = [
        {
            'type': BidirectionalRecurrentLayer,
            'num_units': 25,
            'gradient_steps': GRADIENT_STEPS,
            'W_in_to_hid': Normal(std=1.),
            'nonlinearity': tanh
        },
        {
            'type': FeaturePoolLayer,
            'ds': 2,  # number of feature maps to be pooled together
            'axis': 1,  # pool over the time axis
            'pool_function': T.mean
        },
        {
            'type': BidirectionalRecurrentLayer,
            'num_units': 25,
            'gradient_steps': GRADIENT_STEPS,
            'W_in_to_hid': Normal(std=1 / sqrt(25)),
            'nonlinearity': tanh
        },
        {
            'type': FeaturePoolLayer,
            'ds': 2,  # number of feature maps to be pooled together
            'axis': 1,  # pool over the time axis
            'pool_function': T.mean
        },
        {
            'type': BidirectionalRecurrentLayer,
            'num_units': 25,
            'gradient_steps': GRADIENT_STEPS,
            'W_in_to_hid': Normal(std=1 / sqrt(25)),
            'nonlinearity': tanh
        },
        {
            'type': DenseLayer,
            'num_units': source.n_outputs,
            'nonlinearity': None,
            'W': Normal(std=(1 / sqrt(25)))
        }
    ]
    net = Net(**net_dict_copy)
    return net
Example #15
0
def exp_d(name):
    # tanh and softplus output
    # sane inits for other layers
    # output one appliance
    # 0% skip prob for first appliance
    # 90% skip prob for other appliances
    # 200 units
    # standardise input
    # sane inits for first layer
    # no dense layers at bottom
    source_dict_copy = deepcopy(source_dict)
    source_dict_copy['standardise_input'] = True
    source = RealApplianceSource(**source_dict_copy)
    net_dict_copy = deepcopy(net_dict)
    net_dict_copy.update(dict(experiment_name=name, source=source))
    net_dict_copy['layers_config'] = [{
        'type': BidirectionalRecurrentLayer,
        'num_units': 50,
        'W_in_to_hid': Normal(std=1),
        'gradient_steps': GRADIENT_STEPS,
        'nonlinearity': tanh,
        'learn_init': False,
        'precompute_input': False
    }, {
        'type': DimshuffleLayer,
        'pattern': (0, 2, 1)
    }, {
        'type': Conv1DLayer,
        'num_filters': 50,
        'filter_length': 4,
        'stride': 4,
        'nonlinearity': tanh,
        'W': Normal(std=1 / sqrt(50))
    }, {
        'type': DimshuffleLayer,
        'pattern': (0, 2, 1)
    }, {
        'type': BidirectionalRecurrentLayer,
        'num_units': 80,
        'W_in_to_hid': Normal(std=1 / sqrt(50)),
        'gradient_steps': GRADIENT_STEPS,
        'nonlinearity': tanh,
        'learn_init': False,
        'precompute_input': False
    }, {
        'type': DenseLayer,
        'num_units': source.n_outputs,
        'nonlinearity': T.nnet.softplus,
        'W': Normal(std=1 / sqrt(80))
    }]
    net = Net(**net_dict_copy)
    return net
Example #16
0
def exp_e(name):
    # As E but with Uniform(25) init
    source = RealApplianceSource(**source_dict)
    net_dict_copy = deepcopy(net_dict)
    net_dict_copy.update(dict(experiment_name=name, source=source))
    net_dict_copy['layers_config'][-1].update({'W_in_to_cell': Uniform(25)})
    net_dict_copy['layers_config'].append({
        'type': DenseLayer,
        'num_units': source.n_outputs,
        'nonlinearity': sigmoid
    })
    net = Net(**net_dict_copy)
    return net
Example #17
0
def exp_a(name):
    global source
    source_dict_copy = deepcopy(source_dict)
    source = RealApplianceSource(**source_dict_copy)
    net_dict_copy = deepcopy(net_dict)
    net_dict_copy.update(dict(experiment_name=name, source=source))
    net_dict_copy['layers_config'].extend([{
        'type': DenseLayer,
        'num_units': source.n_outputs,
        'nonlinearity': T.nnet.softplus
    }])
    net = Net(**net_dict_copy)
    return net
Example #18
0
def exp_a(name):
    # like 239 but LSTM not BLSTM and no lag and clip appliance power
    # RESULTS: aweful
    source = RealApplianceSource(**source_dict)
    net_dict_copy = deepcopy(net_dict)
    net_dict_copy.update(dict(experiment_name=name, source=source))
    net_dict_copy['layers_config'].append({
        'type': DenseLayer,
        'num_units': source.n_outputs,
        'nonlinearity': sigmoid
    })
    net = Net(**net_dict_copy)
    return net
Example #19
0
def exp_x(name):
    source = RealApplianceSource(**source_dict)
    try:
        source.lag = 1
    except NameError:
        global source
        source = RealApplianceSource(**source_dict)
    net_dict_copy = deepcopy(net_dict)
    net_dict_copy.update(dict(
        experiment_name=name, 
        source=source
    ))
    net_dict_copy['layers_config'].append(
        {
            'type': DenseLayer,
            'num_units': source.n_outputs,
            'nonlinearity': None,
            'W': Normal(std=(1/sqrt(50)))
        }
    )
    net = Net(**net_dict_copy)
    return net
Example #20
0
def exp_b(name):
    # ReLU hidden layers
    # linear output
    # output one appliance
    # 0% skip prob for first appliance
    # 100% skip prob for other appliances
    # input is diff
    global source
    source_dict_copy = deepcopy(source_dict)
    source = RealApplianceSource(**source_dict_copy)
    net_dict_copy = deepcopy(net_dict)
    net_dict_copy.update(dict(experiment_name=name, source=source))
    net_dict_copy['layers_config'] = [{
        'type': RecurrentLayer,
        'num_units': 50,
        'W_in_to_hid': Normal(std=1),
        'W_hid_to_hid': Identity(scale=0.5),
        'gradient_steps': GRADIENT_STEPS,
        'nonlinearity': rectify,
        'learn_init': False,
        'precompute_input': False
    }, {
        'type': DimshuffleLayer,
        'pattern': (0, 2, 1)
    }, {
        'type': Conv1DLayer,
        'num_filters': 50,
        'filter_length': 4,
        'stride': 4,
        'nonlinearity': rectify,
        'W': Normal(std=1 / sqrt(50))
    }, {
        'type': DimshuffleLayer,
        'pattern': (0, 2, 1)
    }, {
        'type': RecurrentLayer,
        'num_units': 100,
        'W_in_to_hid': Normal(std=1 / sqrt(50)),
        'W_hid_to_hid': Identity(scale=0.5),
        'gradient_steps': GRADIENT_STEPS,
        'nonlinearity': rectify,
        'learn_init': False,
        'precompute_input': False
    }, {
        'type': DenseLayer,
        'num_units': source.n_outputs,
        'nonlinearity': None,
        'W': Normal(std=1 / sqrt(100))
    }]
    net = Net(**net_dict_copy)
    return net
Example #21
0
def exp_c(name):
    # 3 appliances and 3 layers with 2x2x pool
    # avg valid cost = -0.2468771785
    global source
    source_dict_copy = deepcopy(source_dict)
    source = RealApplianceSource(**source_dict_copy)
    net_dict_copy = deepcopy(net_dict)
    net_dict_copy.update(dict(experiment_name=name, source=source))
    net_dict_copy['layers_config'] = [
        {
            'type': BidirectionalRecurrentLayer,
            'num_units': N,
            'gradient_steps': GRADIENT_STEPS,
            'W_in_to_hid': Normal(std=1.),
            'nonlinearity': tanh
        },
        {
            'type': FeaturePoolLayer,
            'ds': 2,  # number of feature maps to be pooled together
            'axis': 1,  # pool over the time axis
            'pool_function': T.max
        },
        {
            'type': BidirectionalRecurrentLayer,
            'num_units': N,
            'gradient_steps': GRADIENT_STEPS,
            'W_in_to_hid': Normal(std=1 / sqrt(N)),
            'nonlinearity': tanh
        },
        {
            'type': FeaturePoolLayer,
            'ds': 2,  # number of feature maps to be pooled together
            'axis': 1,  # pool over the time axis
            'pool_function': T.max
        },
        {
            'type': BidirectionalRecurrentLayer,
            'num_units': N,
            'gradient_steps': GRADIENT_STEPS,
            'W_in_to_hid': Normal(std=1 / sqrt(N)),
            'nonlinearity': tanh
        },
        {
            'type': MixtureDensityLayer,
            'num_units': source.n_outputs,
            'num_components': 2
        }
    ]
    net = Net(**net_dict_copy)
    return net
Example #22
0
def exp_a(name):
    """Results: works fairly well.  Appears to die after 1250 epochs."""
    print("Try totally recreating e82.")
    source = RealApplianceSource(
        filename='/data/dk3810/ukdale.h5',
        appliances=[['fridge freezer', 'fridge', 'freezer'],
                    'hair straighteners', 'television'],
        max_appliance_powers=[300, 500, 200],
        on_power_thresholds=[80, 20, 20],
        min_on_durations=[60, 60, 60],
        window=("2013-06-01", "2014-07-01"),
        seq_length=1000,
        output_one_appliance=False,
        boolean_targets=False,
        min_off_duration=60,
        subsample_target=5,
        train_buildings=[1],
        validation_buildings=[1])

    net = Net(experiment_name=name + 'a',
              source=source,
              save_plot_interval=SAVE_PLOT_INTERVAL,
              loss_function=crossentropy,
              updates=partial(nesterov_momentum, learning_rate=0.1),
              layers_config=[{
                  'type': BLSTMLayer,
                  'num_units': 60,
                  'W_in_to_cell': Uniform(5)
              }, {
                  'type': DimshuffleLayer,
                  'pattern': (0, 2, 1)
              }, {
                  'type': Conv1DLayer,
                  'num_filters': 80,
                  'filter_length': 5,
                  'stride': 5,
                  'nonlinearity': sigmoid
              }, {
                  'type': DimshuffleLayer,
                  'pattern': (0, 2, 1)
              }, {
                  'type': BLSTMLayer,
                  'num_units': 80,
                  'W_in_to_cell': Uniform(5)
              }, {
                  'type': DenseLayer,
                  'num_units': source.n_outputs,
                  'nonlinearity': sigmoid
              }])
    return net
Example #23
0
def exp_b(name):
    global source
    source_dict_copy = deepcopy(source_dict)
    source = RealApplianceSource(**source_dict_copy)
    net_dict_copy = deepcopy(net_dict)
    net_dict_copy.update(dict(experiment_name=name, source=source))
    net_dict_copy['layers_config'] = [{
        'type': DimshuffleLayer,
        'pattern': (0, 2, 1)
    }, {
        'type': Conv1DLayer,
        'num_filters': 10,
        'filter_length': 2,
        'stride': 1,
        'nonlinearity': rectify,
        'border_mode': 'same'
    }, {
        'type': DimshuffleLayer,
        'pattern': (0, 2, 1)
    }, {
        'type': BidirectionalRecurrentLayer,
        'num_units': 40,
        'gradient_steps': GRADIENT_STEPS,
        'nonlinearity': rectify,
        'W_hid_to_hid': Identity(scale=0.5)
    }, {
        'type': DimshuffleLayer,
        'pattern': (0, 2, 1)
    }, {
        'type': Conv1DLayer,
        'num_filters': 40,
        'filter_length': 4,
        'stride': 4,
        'nonlinearity': rectify
    }, {
        'type': DimshuffleLayer,
        'pattern': (0, 2, 1)
    }, {
        'type': BidirectionalRecurrentLayer,
        'num_units': 40,
        'gradient_steps': GRADIENT_STEPS,
        'nonlinearity': rectify,
        'W_hid_to_hid': Identity(scale=0.5)
    }, {
        'type': DenseLayer,
        'num_units': source.n_outputs,
        'nonlinearity': T.nnet.softplus
    }]
    net = Net(**net_dict_copy)
    return net
Example #24
0
def exp_a(name):
    # 5 appliances
    global source
    source_dict_copy = deepcopy(source_dict)
    source = RealApplianceSource(**source_dict_copy)
    net_dict_copy = deepcopy(net_dict)
    net_dict_copy.update(dict(experiment_name=name, source=source))
    net_dict_copy['layers_config'].extend([{
        'type': MixtureDensityLayer,
        'num_units': source.n_outputs,
        'num_components': 2
    }])
    net = Net(**net_dict_copy)
    return net
Example #25
0
def exp_r(name):
    # mse cost
    # avg valid cost =  0.3652453125 BUT THIS ISn'T same cost function!
    # eye-balling data suggests it isn't great
    source_dict_copy = deepcopy(source_dict)
    source = RealApplianceSource(**source_dict_copy)
    net_dict_copy = deepcopy(net_dict)
    net_dict_copy.update(dict(
        experiment_name=name,
        source=source,
        loss_function=mse
    ))
    N = 50
    net_dict_copy['layers_config'] = [
        {
            'type': BidirectionalRecurrentLayer,
            'num_units': N,
            'gradient_steps': GRADIENT_STEPS,
            'W_in_to_hid': Normal(std=1.),
            'nonlinearity': tanh
        },
        {
            'type': BidirectionalRecurrentLayer,
            'num_units': N,
            'gradient_steps': GRADIENT_STEPS,
            'W_in_to_hid': Normal(std=1/sqrt(N)),
            'nonlinearity': tanh
        },
        {
            'type': FeaturePoolLayer,
            'ds': 3, # number of feature maps to be pooled together
            'axis': 1, # pool over the time axis
            'pool_function': T.max
        },
        {
            'type': BidirectionalRecurrentLayer,
            'num_units': N,
            'gradient_steps': GRADIENT_STEPS,
            'W_in_to_hid': Normal(std=1/sqrt(N)),
            'nonlinearity': tanh
        },
        {
            'type': DenseLayer,
            'num_units': source.n_outputs,
            'nonlinearity': None,
            'W': Normal(std=(1/sqrt(N)))
        }
    ]
    net = Net(**net_dict_copy)
    return net
Example #26
0
def exp_i(name):
    # two dense layers at start, no batch norm
    # no gradient step, do precompute input, small net
    
    source_dict_copy = deepcopy(source_dict)
    source = RealApplianceSource(**source_dict_copy)
    net_dict_copy = deepcopy(net_dict)
    net_dict_copy.update(dict(
        experiment_name=name,
        source=source
    ))
    net_dict_copy['layers_config']= [
        {
            'type': BidirectionalRecurrentLayer,
            'num_units': 40,
            'nonlinearity': tanh,
            'learn_init': True, 
            'precompute_input': True
        },
        {
            'type': DimshuffleLayer,
            'pattern': (0, 2, 1)
        },
        {
            'type': Conv1DLayer,
            'num_filters': 40,
            'filter_length': 4,
            'stride': 4,
            'nonlinearity': tanh
        },
        {
            'type': DimshuffleLayer,
            'pattern': (0, 2, 1)
        },
        {
            'type': BidirectionalRecurrentLayer,
            'num_units': 40,
            'nonlinearity': tanh,
            'learn_init': True,
            'precompute_input': True
        },
        {
            'type': DenseLayer,
            'num_units': source.n_outputs,
            'nonlinearity': T.nnet.softplus
        }
    ]
    net = Net(**net_dict_copy)
    return net
Example #27
0
def exp_h(name):
    # replace tanh with sigmoid

    source_dict_copy = deepcopy(source_dict)
    source = RealApplianceSource(**source_dict_copy)
    net_dict_copy = deepcopy(net_dict)
    net_dict_copy.update(dict(experiment_name=name, source=source))
    net_dict_copy['layers_config'] = [{
        'type': DenseLayer,
        'num_units': 40,
        'nonlinearity': sigmoid,
        'W': Normal(std=1)
    }, {
        'type': DenseLayer,
        'num_units': 40,
        'nonlinearity': sigmoid
    }, {
        'type': BidirectionalRecurrentLayer,
        'num_units': 40,
        'gradient_steps': GRADIENT_STEPS,
        'nonlinearity': sigmoid,
        'learn_init': False,
        'precompute_input': False
    }, {
        'type': DimshuffleLayer,
        'pattern': (0, 2, 1)
    }, {
        'type': Conv1DLayer,
        'num_filters': 40,
        'filter_length': 4,
        'stride': 4,
        'nonlinearity': sigmoid
    }, {
        'type': DimshuffleLayer,
        'pattern': (0, 2, 1)
    }, {
        'type': BidirectionalRecurrentLayer,
        'num_units': 40,
        'gradient_steps': GRADIENT_STEPS,
        'nonlinearity': sigmoid,
        'learn_init': False,
        'precompute_input': False
    }, {
        'type': DenseLayer,
        'num_units': source.n_outputs,
        'nonlinearity': T.nnet.softplus
    }]
    net = Net(**net_dict_copy)
    return net
Example #28
0
def exp_j(name):
    # 3 BLSTM layers
    # avg valid cost =  0.7796924710
    source_dict_copy = deepcopy(source_dict)
    source_dict_copy['subsample_target'] = 3
    source = RealApplianceSource(**source_dict_copy)
    net_dict_copy = deepcopy(net_dict)
    net_dict_copy.update(dict(
        experiment_name=name,
        source=source
    ))
    N = 50
    net_dict_copy['layers_config'] = [
        {
            'type': BLSTMLayer,
            'num_units': N,
            'gradient_steps': GRADIENT_STEPS,
            'W_in_to_cell': Normal(std=1.),
            'peepholes': False
        },
        {
            'type': BLSTMLayer,
            'num_units': N,
            'gradient_steps': GRADIENT_STEPS,
            'W_in_to_cell': Normal(std=(1/sqrt(N))),
            'peepholes': False
        },
        {
            'type': FeaturePoolLayer,
            'ds': 3, # number of feature maps to be pooled together
            'axis': 1, # pool over the time axis
            'pool_function': T.max
        },
        {
            'type': BLSTMLayer,
            'num_units': N,
            'gradient_steps': GRADIENT_STEPS,
            'W_in_to_cell': Normal(std=(1/sqrt(N))),
            'peepholes': False
        },
        {
            'type': DenseLayer,
            'num_units': source.n_outputs,
            'nonlinearity': None,
            'W': Normal(std=(1/sqrt(N)))
        }
    ]
    net = Net(**net_dict_copy)
    return net
Example #29
0
def exp_a(name):
    global source
    source_dict_copy = deepcopy(source_dict)
    source_dict_copy['appliances'] = [['fridge freezer', 'fridge',
                                       'freezer'], 'hair straighteners',
                                      'television', 'dish washer',
                                      ['washer dryer', 'washing machine']]
    source_dict_copy['skip_probability'] = 0.7
    source = RealApplianceSource(**source_dict_copy)
    net_dict_copy = deepcopy(net_dict)
    net_dict_copy.update(dict(experiment_name=name, source=source))
    net_dict_copy['layers_config'] = [
        {
            'type': BidirectionalRecurrentLayer,
            'num_units': 25,
            'gradient_steps': GRADIENT_STEPS,
            'W_in_to_hid': Normal(std=1.),
            'nonlinearity': tanh
        },
        {
            'type': FeaturePoolLayer,
            'ds': 5,  # number of feature maps to be pooled together
            'axis': 1,  # pool over the time axis
            'pool_function': T.mean
        },
        {
            'type': BidirectionalRecurrentLayer,
            'num_units': 25,
            'gradient_steps': GRADIENT_STEPS,
            'W_in_to_hid': Normal(std=1 / sqrt(25)),
            'nonlinearity': tanh
        },
        {
            'type': BidirectionalRecurrentLayer,
            'num_units': 25,
            'gradient_steps': GRADIENT_STEPS,
            'W_in_to_hid': Normal(std=1 / sqrt(25)),
            'nonlinearity': tanh
        },
        {
            'type': DenseLayer,
            'num_units': source.n_outputs,
            'nonlinearity': None,
            'W': Normal(std=(1 / sqrt(25)))
        }
    ]
    net = Net(**net_dict_copy)
    return net
Example #30
0
def exp_a(name):
    global source
    source_dict_copy = deepcopy(source_dict)
    source = RealApplianceSource(**source_dict_copy)
    net_dict_copy = deepcopy(net_dict)
    net_dict_copy.update(dict(experiment_name=name, source=source))
    N = 512
    output_shape = source.output_shape_after_processing()
    net_dict_copy['layers_config'] = [
        {
            'type': DimshuffleLayer,
            'pattern': (0, 2, 1)  # (batch, features, time)
        },
        {
            'type': Conv1DLayer,  # convolve over the time axis
            'num_filters': 32,
            'filter_length': 4,
            'stride': 1,
            'nonlinearity': rectify,
            'border_mode': 'same'
        },
        {
            'type': DimshuffleLayer,
            'pattern': (0, 2, 1)  # back to (batch, time, features)
        },
        {
            'type': DenseLayer,
            'num_units': N * 2,
            'nonlinearity': rectify
        },
        {
            'type': DenseLayer,
            'num_units': N,
            'nonlinearity': rectify
        },
        {
            'type': DenseLayer,
            'num_units': N // 2,
            'nonlinearity': rectify
        },
        {
            'type': DenseLayer,
            'num_units': output_shape[1] * output_shape[2],
            'nonlinearity': sigmoid
        }
    ]
    net = Net(**net_dict_copy)
    return net