示例#1
0
def exp_a(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': BidirectionalRecurrentLayer,
            'num_units': 50,
            'W_in_to_hid': Normal(std=1),
            'W_hid_to_hid': Identity(scale=0.9),
            'nonlinearity': rectify,
            'learn_init': False, 
            'precompute_input': True
        },
        {
            'type': DenseLayer,
            'num_units': source.n_outputs,
            'nonlinearity': None,
            'W': Normal(std=1/sqrt(50))
        }
    ]
    net = Net(**net_dict_copy)
    net.load_params(5000)
    return net
示例#2
0
def exp_a(name):
    # 5 appliances
    global source
    source_dict_copy = deepcopy(source_dict)
    source_dict_copy.update(dict(
        appliances=[
            ['fridge freezer', 'fridge', 'freezer'], 
            'hair straighteners', 
            'television',
            'dish washer',
            ['washer dryer', 'washing machine']
        ],
        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'].extend([
        {
            'type': MixtureDensityLayer,
            'num_units': source.n_outputs,
            'num_components': 2
        }
    ])
    net = Net(**net_dict_copy)
    net.load_params(iteration=4000)
    return net
示例#3
0
def exp_c(name):
    global source
    MAX_TARGET_POWER = 200
    source_dict_copy = deepcopy(source_dict)
    source_dict_copy.update(dict(
        logger=logging.getLogger(name),
        appliances=[
            'HTPC',
            'dish washer',
            ['fridge freezer', 'fridge', 'freezer'],
            ['washer dryer', 'washing machine'],
            'kettle'
        ],
        max_appliance_powers=[MAX_TARGET_POWER, 2500, 300, 2400, 2600],
        on_power_thresholds=[5] * 5,
        min_on_durations=[60, 1800, 60, 1800, 30],
        min_off_durations=[12, 1800, 12, 600, 1],
        seq_length=2048
    ))
    source = RealApplianceSource(**source_dict_copy)
    net_dict_copy = deepcopy(net_dict)
    net_dict_copy.update(dict(
        experiment_name=name,
        source=source,
        plotter=StartEndMeanPlotter(
            n_seq_to_plot=32, max_target_power=MAX_TARGET_POWER),
        learning_rate_changes_by_iteration={
            150000: 1e-4,
            275000: 1e-5
        }
    ))
    net = Net(**net_dict_copy)
    net.load_params(146758)
    return net
示例#4
0
def exp_a(name):
    net_dict_copy = deepcopy(net_dict)
    net_dict_copy.update(dict(
        experiment_name=name,
        source=multi_source,
        plotter=StartEndMeanPlotter(
            n_seq_to_plot=32, max_target_power=MAX_TARGET_POWER)
    ))
    net = Net(**net_dict_copy)
    net.load_params(350000)
    return net
示例#5
0
def exp_c(name):
    global source
    source_dict_copy = deepcopy(source_dict)
    source_dict_copy['random_window'] = 256
    source = RealApplianceSource(**source_dict_copy)
    net_dict_copy = deepcopy(net_dict)
    net_dict_copy.update(dict(
        experiment_name=name,
        source=source,
        learning_rate=1e-5
    ))
    N = 512 * 8
    output_shape = source.output_shape_after_processing()
    net_dict_copy['layers_config'] = [
        {
            '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': N // 4,
            'nonlinearity': rectify
        },
        {
            'type': DenseLayer,
            'num_units': output_shape[1] * output_shape[2],
            'nonlinearity': sigmoid
        }
    ]
    net = Net(**net_dict_copy)
    net.load_params(30000)
    return net
示例#6
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)
    net.load_params(1000)
    return net
示例#7
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)
    net.load_params(397)
    return net
示例#8
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': DenseLayer,
            'num_units': N,
            'W': Normal(std=1/sqrt(N)),
            'nonlinearity': rectify
        },
        {
            'type': DenseLayer,
            'num_units': N // 2,
            'W': Normal(std=1/sqrt(N)),
            'nonlinearity': rectify
        },
        {
            'type': DenseLayer,
            'num_units': N // 4,
            'W': Normal(std=1/sqrt(N // 2)),
            'nonlinearity': rectify
        },
        {
            'type': DenseLayer,
            'num_units': output_shape[1] * output_shape[2],
            'W': Normal(std=1/sqrt(N // 4)),
            'nonlinearity': T.nnet.softplus
        }
    ]
    net = Net(**net_dict_copy)
    net.load_params(25000)
    return net
示例#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': 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': MixtureDensityLayer,
            'num_units': source.n_outputs,
            'num_components': 2
        }
    ]
    net = Net(**net_dict_copy)
    net.load_params(iteration=5000)
    return net
def exp_a(name):
    global source
    source_dict_copy = deepcopy(source_dict)
    source_dict_copy.update(dict(logger=logging.getLogger(name)))
    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": PadLayer, "width": 4},
        {
            "type": Conv1DLayer,  # convolve over the time axis
            "num_filters": 16,
            "filter_size": 4,
            "stride": 1,
            "nonlinearity": None,
            "border_mode": "valid",
        },
        {
            "type": Conv1DLayer,  # convolve over the time axis
            "num_filters": 16,
            "filter_size": 4,
            "stride": 1,
            "nonlinearity": None,
            "border_mode": "valid",
        },
        {"type": DimshuffleLayer, "pattern": (0, 2, 1), "label": "dimshuffle3"},  # back to (batch, time, features)
        {"type": DenseLayer, "num_units": 512 * 16, "nonlinearity": rectify, "label": "dense0"},
        {"type": DenseLayer, "num_units": 512 * 8, "nonlinearity": rectify, "label": "dense1"},
        {"type": DenseLayer, "num_units": 512 * 4, "nonlinearity": rectify, "label": "dense2"},
        {"type": DenseLayer, "num_units": 512, "nonlinearity": rectify},
        {"type": DenseLayer, "num_units": 3, "nonlinearity": None},
    ]
    net = Net(**net_dict_copy)
    net.load_params(300000)
    return net
def get_net(appliance, architecture):
    """
    Parameters
    ----------
    appliance : string
    architecture : {'rnn', 'ae', 'rectangles'}
    """
    NET_DICTS = {
        'rnn': net_dict_rnn,
        'ae': net_dict_ae,
        'rectangles': net_dict_rectangles
    }
    net_dict_func = NET_DICTS[architecture]
    source = get_source(
        appliance,
        logger,
        target_is_start_and_end_and_mean=(architecture == 'rectangles'),
        is_rnn=(architecture == 'rnn'),
        window_per_building={  # just load a tiny bit of data. Won't be used.
            1: ("2013-04-12", "2013-05-12"),
            2: ("2013-05-22", "2013-06-22"),
            3: ("2013-02-27", "2013-03-27"),
            4: ("2013-03-09", "2013-04-09"),
            5: ("2014-06-29", "2014-07-29")
        },
        source_type='real_appliance_source',
        filename=UKDALE_FILENAME
    )
    seq_length = source.seq_length
    net_dict = net_dict_func(seq_length)
    if appliance == 'dish washer' and architecture == 'rectangles':
        epochs = 200000
        net_dict.pop('epochs')
    else:
        epochs = net_dict.pop('epochs')
    net_dict_copy = deepcopy(net_dict)
    experiment_name = EXPERIMENT + "_" + appliance + "_" + architecture
    net_dict_copy.update(dict(
        source=source,
        logger=logger,
        experiment_name=experiment_name
    ))
    net = Net(**net_dict_copy)
    net.plotter.max_target_power = source.max_appliance_powers.values()[0]
    net.load_params(iteration=epochs,
                    path=join(NET_BASE_PATH, experiment_name))
    net.print_net()
    net.compile()
    return net
示例#12
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))
    output_shape = source.output_shape_after_processing()
    net_dict_copy['layers_config'] = [{
        'type': BLSTMLayer,
        'num_units': 40,
        'gradient_steps': GRADIENT_STEPS,
        'peepholes': 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': BLSTMLayer,
        'num_units': 80,
        'gradient_steps': GRADIENT_STEPS,
        'peepholes': False
    }, {
        'type': DenseLayer,
        'num_units': source.n_outputs,
        'nonlinearity': T.nnet.softplus
    }]
    net = Net(**net_dict_copy)
    return net
示例#13
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': 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': MixtureDensityLayer,
            'num_units': source.n_outputs,
            'num_components': 2
        }
    ]
    net = Net(**net_dict_copy)
    return net
示例#14
0
net = Net(
    experiment_name="e87",
    source=source,
    save_plot_interval=50,
    loss_function=crossentropy,
    updates=partial(adagrad, learning_rate=0.001),
    layers_config=[
        {
            'type': LSTMLayer, # TODO change to BLSTM
            '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': LSTMLayer,
            'num_units': 80,
            'W_in_to_cell': Uniform(5)
        },
        {
            'type': DenseLayer,
            'num_units': source.n_outputs,
            'nonlinearity': sigmoid
        }
    ]
)
示例#15
0
def exp_a(name):
    logger = logging.getLogger(name)
    real_appliance_source1 = RealApplianceSource(
        logger=logger,
        filename=UKDALE_FILENAME,
        appliances=[
            TARGET_APPLIANCE,
            ['fridge freezer', 'fridge', 'freezer'],
            'dish washer',
            'kettle',
            ['washer dryer', 'washing machine']
        ],
        max_appliance_powers=[MAX_TARGET_POWER, 300, 2500, 2600, 2400],
        on_power_thresholds=[ON_POWER_THRESHOLD] + [10] * 4,
        min_on_durations=[MIN_ON_DURATION, 60, 1800, 12, 1800],
        min_off_durations=[MIN_OFF_DURATION, 12, 1800, 12, 600],
        divide_input_by_max_input_power=False,
        window_per_building=WINDOW_PER_BUILDING,
        seq_length=SEQ_LENGTH,
        output_one_appliance=True,
        train_buildings=TRAIN_BUILDINGS,
        validation_buildings=VALIDATION_BUILDINGS,
        n_seq_per_batch=N_SEQ_PER_BATCH,
        skip_probability=0.75,
        skip_probability_for_first_appliance=SKIP_PROBABILITY_FOR_TARGET,
        target_is_start_and_end_and_mean=True,
        standardise_input=True,
        input_stats=INPUT_STATS,
        independently_center_inputs=INDEPENDENTLY_CENTER_INPUTS
    )

    same_location_source1 = SameLocation(
        logger=logger,
        filename=UKDALE_FILENAME,
        target_appliance=TARGET_APPLIANCE,
        window_per_building=WINDOW_PER_BUILDING,
        seq_length=SEQ_LENGTH,
        train_buildings=TRAIN_BUILDINGS,
        validation_buildings=VALIDATION_BUILDINGS,
        n_seq_per_batch=N_SEQ_PER_BATCH,
        skip_probability=SKIP_PROBABILITY_FOR_TARGET,
        target_is_start_and_end_and_mean=True,
        standardise_input=True,
        offset_probability=1,
        divide_target_by=MAX_TARGET_POWER,
        input_stats=INPUT_STATS,
        independently_center_inputs=INDEPENDENTLY_CENTER_INPUTS,
        on_power_threshold=ON_POWER_THRESHOLD,
        min_on_duration=MIN_ON_DURATION,
        min_off_duration=MIN_OFF_DURATION
    )

    multi_source = MultiSource(
        sources=[
            {
                'source': real_appliance_source1,
                'train_probability': 0.5,
                'validation_probability': 0
            },
            {
                'source': same_location_source1,
                'train_probability': 0.5,
                'validation_probability': 1
            }
        ],
        standardisation_source=same_location_source1
    )

    net_dict_copy = deepcopy(net_dict)
    net_dict_copy.update(dict(
        experiment_name=name,
        source=multi_source,
        plotter=StartEndMeanPlotter(
            n_seq_to_plot=32,
            n_training_examples_to_plot=16,
            max_target_power=MAX_TARGET_POWER)
    ))
    net = Net(**net_dict_copy)
    net.load_params(11589)
    return net
示例#16
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=[300, 500, 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=1504,
        output_one_appliance=False,
        boolean_targets=False,
        train_buildings=[1],
        validation_buildings=[1], 
        skip_probability=0.7,
        n_seq_per_batch=25,
        include_diff=True
    )

    net = Net(
        experiment_name=name,
        source=source,
        save_plot_interval=1000,
        loss_function=crossentropy,
        updates=partial(nesterov_momentum, learning_rate=.1, clip_range=(-1, 1)),
        layers_config=[
            {
                'type': LSTMLayer,
                'num_units': 60,
                'W_in_to_cell': Uniform(25),
                'gradient_steps': GRADIENT_STEPS,
                'peepholes': False
            },
            {
                'type': DenseLayer,
                'num_units': source.n_outputs,
                'nonlinearity': sigmoid
            }            
        ],
        layer_changes={
            5001: {
                'remove_from': -3,
                'callback': set_subsample_target,
                'new_layers': 
                [
                    {
                        'type': DimshuffleLayer,
                        'pattern': (0, 2, 1)
                    },
                    {
                        'type': Conv1DLayer,
                        'num_filters': 80,
                        'filter_length': 5,
                        'stride': 1,
                        'nonlinearity': sigmoid,
                        'W': Uniform(1)
                    },
                    {
                        'type': DimshuffleLayer,
                        'pattern': (0, 2, 1)
                    },
                    {
                        'type': FeaturePoolLayer,
                        'ds': 5, # number of feature maps to be pooled together
                        'axis': 1 # pool over the time axis
                    },
                    {
                        'type': DenseLayer,
                        'num_units': source.n_outputs,
                        'nonlinearity': sigmoid
                    }
                ]
            },
            10001: { 
                'remove_from': -3,
                'new_layers': 
                [
                    {
                        'type': LSTMLayer,
                        'num_units': 80,
                        'W_in_to_cell': Uniform(1),
                        'gradient_steps': GRADIENT_STEPS,
                        'peepholes': False
                    },
                    {
                        'type': DenseLayer,
                        'num_units': source.n_outputs,
                        'nonlinearity': sigmoid
                    }            
                ]
            }
        }
    )
    return net
def exp_a(name):
    global source
    source_dict_copy = deepcopy(source_dict)
    source_dict_copy.update(dict(
        logger=logging.getLogger(name)
    ))
    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': PadLayer,
            'width': 4
        },
        {
            'type': Conv1DLayer,  # convolve over the time axis
            'num_filters': 16,
            'filter_size': 4,
            'stride': 1,
            'nonlinearity': None,
            'border_mode': 'valid'
        },
        {
            'type': Conv1DLayer,  # convolve over the time axis
            'num_filters': 16,
            'filter_size': 4,
            'stride': 1,
            'nonlinearity': None,
            'border_mode': 'valid'
        },
        {
            'type': DimshuffleLayer,
            'pattern': (0, 2, 1),  # back to (batch, time, features)
            'label': 'dimshuffle3'
        },
        {
            'type': DenseLayer,
            'num_units': 512 * 16,
            'nonlinearity': rectify,
            'label': 'dense0'
        },
        {
            'type': DenseLayer,
            'num_units': 512 * 8,
            'nonlinearity': rectify,
            'label': 'dense1'
        },
        {
            'type': DenseLayer,
            'num_units': 512 * 4,
            'nonlinearity': rectify,
            'label': 'dense2'
        },
        {
            'type': DenseLayer,
            'num_units': 512,
            'nonlinearity': rectify
        },
        {
            'type': DenseLayer,
            'num_units': 3,
            'nonlinearity': None
        }
    ]
    net = Net(**net_dict_copy)
    net.load_params(300000)
    return net
示例#18
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': True, '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': True, 'precompute_input': False
        },
        {
            'type': DenseLayer,
            'num_units': source.n_outputs,
            'nonlinearity': T.nnet.softplus
        }
    ]
    net = Net(**net_dict_copy)
    return net
示例#19
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 = 1024
    NUM_FILTERS = 50
    net_dict_copy['layers_config'] = [
        {
            'type': DimshuffleLayer,
            'pattern': (0, 2, 1)  # (batch, features, time)
        },
        {
            'type': Conv1DLayer,  # convolve over the time axis
            'num_filters': NUM_FILTERS,
            'filter_length': 10,
            'stride': 2,
            'nonlinearity': rectify,
            'W': Normal(std=1 / sqrt(source.seq_length))
        },
        {
            'type': DimshuffleLayer,
            'pattern': (0, 2, 1)  # back to (batch, time, features)
        },
        {
            'type': DenseLayer,
            'num_units': N,
            'W': Normal(std=1 / sqrt(N * NUM_FILTERS)),
            'nonlinearity': rectify
        },
        {
            'type': DenseLayer,
            'num_units': N,
            'W': Normal(std=1 / sqrt(N)),
            'nonlinearity': rectify
        },
        {
            'type': DenseLayer,
            'num_units': source.output_shape()[1] * source.output_shape()[2],
            'W': Normal(std=1 / sqrt(N)),
            'nonlinearity': rectify
        },
        {
            'type': ReshapeLayer,
            'shape': (16 * 256, 5)
        },
        # {
        #     'type': DenseLayer,
        #     'num_units': source.output_shape()[1] * source.output_shape()[2],
        #     'W': Normal(std=1/sqrt(N)),
        #     'nonlinearity': T.nnet.softplus
        # }
        {
            'type': MixtureDensityLayer,
            'num_units': source.n_outputs,
            'num_components': 1,
            'nonlinearity_mu': T.nnet.softplus
        }
    ]
    net = Net(**net_dict_copy)
    return net
示例#20
0
def exp_a(name):
    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=1520,
        output_one_appliance=False,
        boolean_targets=False,
        train_buildings=[1],
        validation_buildings=[1],
        skip_probability=0.7,
        n_seq_per_batch=25,
        subsample_target=2,
        input_padding=2,
        include_diff=False)

    net = Net(
        experiment_name=name,
        source=source,
        save_plot_interval=5000,
        loss_function=scaled_cost,
        updates=partial(nesterov_momentum,
                        learning_rate=.00001,
                        clip_range=(-1, 1)),
        layers_config=[
            {
                'type': DimshuffleLayer,
                'pattern': (0, 2, 1)  # (batch, features, time)
            },
            {
                'type': Conv1DLayer,  # convolve over the time axis
                'num_filters': 1,
                'filter_length': 3,
                'stride': 1,
                'nonlinearity': sigmoid
            },
            {
                'type': DimshuffleLayer,
                'pattern': (0, 2, 1)  # back to (batch, time, features)
            },
            {
                'type': FeaturePoolLayer,
                'ds': 2,  # number of feature maps to be pooled together
                'axis': 1  # pool over the time axis
            },
            {
                'type': DenseLayer,
                'num_units': 50,
                'nonlinearity': rectify
            },
            {
                'type': DenseLayer,
                'num_units': source.n_outputs,
                'nonlinearity': None,
                'W': Uniform(25)
            }
        ])
    return net
示例#21
0
net = Net(
    experiment_name="e49b",
    source=source,
    learning_rate=1e-1,
    save_plot_interval=50,
    loss_function=crossentropy,
    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': LSTMLayer,
            'num_units': 20,
            'W_in_to_cell': Uniform(5)
        },
        {
            'type': ReshapeLayer,
            'shape': (5, 20, 1000)
        },
        {
            'type': Conv1DLayer,
            'num_filters': 20,
            'filter_length': 5,
            'stride': 5
        },
        {
            'type': ReshapeLayer,
            'shape': (5, 200, 20)
        },
        {
            'type': LSTMLayer,
            'num_units': 40,
            'W_in_to_cell': Uniform(5)
        },
        {
            'type': ReshapeLayer,
            'shape': (5, 40, 200)
        },
        {
            'type': Conv1DLayer,
            'num_filters': 40,
            'filter_length': 5,
            'stride': 5
        },
        {
            'type': ReshapeLayer,
            'shape': (5, 40, 40)
        },
        {
            'type': LSTMLayer,
            'num_units': 80,
            'W_in_to_cell': Uniform(5)
        },
        {
            'type': DenseLayer,
            'num_units': source.n_outputs,
            'nonlinearity': sigmoid
        }
    ]
)
示例#22
0
def exp_i(name):
    # like a but with max power = 1000W and 5 appliances
    # tanh and softplus output
    # sane inits for other layers
    source_dict_copy = deepcopy(source_dict)
    source_dict_copy.update(dict(
        standardise_targets=True,
        unit_variance_targets=True,
        max_input_power=1000,
        skip_probability=0.9
    ))
    source_dict_copy['appliances'] = [
            ['fridge freezer', 'fridge', 'freezer'], 
            'hair straighteners', 
            'television',
            'dish washer',
            ['washer dryer', 'washing machine']
        ]
    source = RealApplianceSource(**source_dict_copy)
    net_dict_copy = deepcopy(net_dict)
    net_dict_copy.update(dict(
        experiment_name=name,
        source=source,
        loss_function=lambda x, t: mse(x, t).mean(),
        learning_rate=1e-4,
        learning_rate_changes_by_iteration={}
    ))
    net_dict_copy['layers_config']= [
        {
            'type': DenseLayer,
            'num_units': 200,
            'nonlinearity': tanh,
            'W': Uniform(25),
            'b': Uniform(25)
        },
        {
            'type': DenseLayer,
            'num_units': 50,
            'nonlinearity': tanh,
            'W': Normal(std=1/sqrt(50)),
            'b': Normal(std=1/sqrt(50))
        },
        {
            'type': BidirectionalRecurrentLayer,
            'num_units': 40,
            'W_in_to_hid': Normal(std=1/sqrt(50)),
            'gradient_steps': GRADIENT_STEPS,
            'nonlinearity': tanh,
            'learn_init': False, 
            'precompute_input': False
        },
        {
            'type': DimshuffleLayer,
            'pattern': (0, 2, 1)
        },
        {
            'type': Conv1DLayer,
            'num_filters': 20,
            '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
        }
    ]
    net = Net(**net_dict_copy)
    net.load_params(18500)
    return net
示例#23
0
def exp_a(name):
    # tanh and softplus output
    # sane inits for other layers
    source_dict_copy = deepcopy(source_dict)
    source_dict_copy.update(dict(
        standardise_targets=True,
        unit_variance_targets=True
    ))
    source = RealApplianceSource(**source_dict_copy)
    net_dict_copy = deepcopy(net_dict)
    net_dict_copy.update(dict(
        experiment_name=name,
        source=source,
        loss_function=lambda x, t: mse(x, t).mean(),
        learning_rate=1e-3,
        learning_rate_changes_by_iteration={
            1000: 1e-4,
            2000: 1e-5
        }
    ))
    net_dict_copy['layers_config']= [
        {
            'type': DenseLayer,
            'num_units': 50,
            'nonlinearity': tanh,
            'W': Uniform(25),
            'b': Uniform(25)
        },
        {
            'type': DenseLayer,
            'num_units': 50,
            'nonlinearity': tanh,
            'W': Normal(std=1/sqrt(50)),
            'b': Normal(std=1/sqrt(50))
        },
        {
            'type': BidirectionalRecurrentLayer,
            'num_units': 40,
            'W_in_to_hid': Normal(std=1/sqrt(50)),
            'gradient_steps': GRADIENT_STEPS,
            'nonlinearity': tanh,
            'learn_init': False, 
            'precompute_input': False
        },
        {
            'type': DimshuffleLayer,
            'pattern': (0, 2, 1)
        },
        {
            'type': Conv1DLayer,
            'num_filters': 20,
            '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
        }
    ]
    net = Net(**net_dict_copy)
    net.load_params(2000)
    return net
示例#24
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,
            'border_mode': 'same'
        },
        {
            'type': Conv1DLayer,  # convolve over the time axis
            'num_filters': 16,
            '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': SEQ_LENGTH,
            'nonlinearity': rectify
        },
        {
            'type': DenseLayer,
            'num_units': SEQ_LENGTH // 4,
            'nonlinearity': rectify
        },
        {
            'type': DenseLayer,
            'num_units': SEQ_LENGTH // 8,
            'nonlinearity': rectify
        },
        {
            'type': DenseLayer,
            'num_units': SEQ_LENGTH // 16,
            'nonlinearity': rectify
        },
        {
            'type': DenseLayer,
            'num_units': SEQ_LENGTH // 8,
            '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
示例#25
0
net = Net(experiment_name="e44a",
          source=source,
          learning_rate=1e-1,
          save_plot_interval=50,
          loss_function=crossentropy,
          layers_config=[{
              'type': DenseLayer,
              'num_units': 50,
              'nonlinearity': sigmoid,
              'b': Uniform(25),
              'W': Uniform(25)
          }, {
              'type': BLSTMLayer,
              'num_units': 50,
              'W_in_to_cell': Normal(1.0)
          }, {
              'type': DenseLayer,
              'num_units': 50,
              'nonlinearity': sigmoid,
              'b': Uniform(1),
              'W': Uniform(1)
          }, {
              'type': BLSTMLayer,
              'num_units': 50,
              'W_in_to_cell': Normal(1.0)
          }, {
              'type': DenseLayer,
              'num_units': 50,
              'nonlinearity': sigmoid,
              'b': Uniform(1),
              'W': Uniform(1)
          }, {
              'type': BLSTMLayer,
              'num_units': 50,
              'W_in_to_cell': Normal(1.0)
          }, {
              'type': DenseLayer,
              'num_units': source.n_outputs,
              'nonlinearity': sigmoid,
              'b': Uniform(1),
              'W': Uniform(1)
          }])
示例#26
0
net = Net(
    experiment_name="e83c",
    source=source,
    learning_rate=1e-1,
    save_plot_interval=250,
    loss_function=crossentropy,
    layers_config=[
        {
            'type': DimshuffleLayer,
            'pattern': (0, 2, 1)
        },
        {
            'type': Conv1DLayer,
            'num_filters': 50,
            'filter_length': 3,
            'stride': 1,
            'nonlinearity': sigmoid
            # 'W': Uniform(25),
            # 'b': Uniform(25)
        },
        {
            'type': Conv1DLayer,
            'num_filters': 50,
            'filter_length': 3,
            'stride': 1,
            'nonlinearity': sigmoid
            # 'W': Uniform(10),
            # 'b': Uniform(10)
        },
        {
            'type': DimshuffleLayer,
            'pattern': (0, 2, 1)
        },
        {
            'type': BLSTMLayer,
            'num_units': 50
            #            '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
        }
    ])
示例#27
0
def exp_c(name):
    """
    tanh all the way through.  Identity init of RNNs
    """
    
    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': identity,
            'b': None,
            'border_mode': 'same'
        },
        {
            'type': BatchNormLayer,
            'nonlinearity': tanh
        },
        {
            'type': DimshuffleLayer,
            'pattern': (0, 2, 1)
        },
        {
            'type': BidirectionalRecurrentLayer,
            'num_units': 40,
            'gradient_steps': GRADIENT_STEPS,
            'nonlinearity': identity,
            'b': None,
            'W_hid_to_hid': Identity(scale=0.5),
            'learn_init': True, 'precompute_input': False
        },
        {
            'type': BatchNormLayer,
            'axes': (0, 1),
            'nonlinearity': tanh
        },
        {
            'type': DimshuffleLayer,
            'pattern': (0, 2, 1)
        },
        {
            'type': Conv1DLayer,
            'num_filters': 40,
            'filter_length': 4,
            'stride': 4,
            'nonlinearity': identity,
            'b': None
        },
        {
            'type': BatchNormLayer,
            'nonlinearity': tanh
        },
        {
            'type': DimshuffleLayer,
            'pattern': (0, 2, 1)
        },
        {
            'type': BidirectionalRecurrentLayer,
            'num_units': 40,
            'gradient_steps': GRADIENT_STEPS,
            'nonlinearity': identity,
            'b': None,
            'W_hid_to_hid': Identity(scale=0.5),
            'learn_init': True, 'precompute_input': False
        },
        {
            'type': BatchNormLayer,
            'axes': (0, 1),
            'nonlinearity': tanh
        },
        {
            'type': DenseLayer,
            'num_units': source.n_outputs,
            'nonlinearity': T.nnet.softplus
        }
    ]
    net = Net(**net_dict_copy)
    return net
示例#28
0
def exp_b(name):
    """Results isn't learning anything very sensible.  I stopped it after 500 epochs."""
    print("e91d but with MSE cost (with sigmoid outputs)")
    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],
        min_on_durations=[60, 60, 60, 1800, 1800],
        window=("2013-06-01", "2014-07-01"),
        seq_length=1500,
        output_one_appliance=False,
        boolean_targets=False,
        min_off_duration=60,
        subsample_target=5,
        train_buildings=[1],
        validation_buildings=[1],
        skip_probability=0.7)

    net = Net(experiment_name=name + 'b',
              source=source,
              save_plot_interval=SAVE_PLOT_INTERVAL,
              loss_function=mse,
              updates=partial(nesterov_momentum, learning_rate=0.01),
              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': BLSTMLayer,
                  'num_units': 40,
                  'W_in_to_cell': Uniform(5)
              }, {
                  'type': DimshuffleLayer,
                  'pattern': (0, 2, 1)
              }, {
                  'type': Conv1DLayer,
                  'num_filters': 60,
                  '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
示例#29
0
def exp_f(name):
    # two dense layers at start, batch norm
    
    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': identity,
            'W': Normal(std=1),
            'b': None
        },
        {
            'type': BatchNormLayer,
            'nonlinearity': tanh,
            'axes': (1)
        },
        {
            'type': DenseLayer,
            'num_units': 40,
            'nonlinearity': identity,
            'b': None
        },
        {
            'type': BatchNormLayer,
            'nonlinearity': tanh,
            'axes': (1)
        },
        {
            'type': BidirectionalRecurrentLayer,
            'num_units': 40,
            'gradient_steps': GRADIENT_STEPS,
            'nonlinearity': identity,
            'b': None,
            'learn_init': True, 'precompute_input': False
        },
        {
            'type': BatchNormLayer,
            'axes': (0, 1),
            'nonlinearity': tanh
        },
        {
            'type': DimshuffleLayer,
            'pattern': (0, 2, 1)
        },
        {
            'type': Conv1DLayer,
            'num_filters': 40,
            'filter_length': 4,
            'stride': 4,
            'nonlinearity': identity,
            'b': None
        },
        {
            'type': BatchNormLayer,
            'nonlinearity': tanh
        },
        {
            'type': DimshuffleLayer,
            'pattern': (0, 2, 1)
        },
        {
            'type': BidirectionalRecurrentLayer,
            'num_units': 40,
            'gradient_steps': GRADIENT_STEPS,
            'nonlinearity': identity,
            'b': None,
            'learn_init': True, 'precompute_input': False
        },
        {
            'type': BatchNormLayer,
            'axes': (0, 1),
            'nonlinearity': tanh
        },
        {
            'type': DenseLayer,
            'num_units': source.n_outputs,
            'nonlinearity': T.nnet.softplus
        }
    ]
    net = Net(**net_dict_copy)
    return net
示例#30
0
def exp_a(name):
    logger = logging.getLogger(name)
    real_appliance_source1 = RealApplianceSource(
        logger=logger,
        filename=UKDALE_FILENAME,
        appliances=[
            TARGET_APPLIANCE, ['fridge freezer', 'fridge', 'freezer'],
            'dish washer', 'kettle', ['washer dryer', 'washing machine']
        ],
        max_appliance_powers=[MAX_TARGET_POWER, 300, 2500, 2600, 2400],
        on_power_thresholds=[5] * 5,
        min_on_durations=[12, 60, 1800, 12, 1800],
        min_off_durations=[12, 12, 1800, 12, 600],
        divide_input_by_max_input_power=False,
        window_per_building=WINDOW_PER_BUILDING,
        seq_length=SEQ_LENGTH,
        output_one_appliance=True,
        train_buildings=TRAIN_BUILDINGS,
        validation_buildings=VALIDATION_BUILDINGS,
        n_seq_per_batch=N_SEQ_PER_BATCH,
        skip_probability=0.75,
        skip_probability_for_first_appliance=SKIP_PROBABILITY_FOR_TARGET,
        target_is_start_and_end_and_mean=True,
        standardise_input=True,
        input_stats=INPUT_STATS,
        independently_center_inputs=INDEPENDENTLY_CENTER_INPUTS)

    same_location_source1 = SameLocation(
        logger=logger,
        filename=UKDALE_FILENAME,
        target_appliance=TARGET_APPLIANCE,
        window_per_building=WINDOW_PER_BUILDING,
        seq_length=SEQ_LENGTH,
        train_buildings=TRAIN_BUILDINGS,
        validation_buildings=VALIDATION_BUILDINGS,
        n_seq_per_batch=N_SEQ_PER_BATCH,
        skip_probability=SKIP_PROBABILITY_FOR_TARGET,
        target_is_start_and_end_and_mean=True,
        standardise_input=True,
        offset_probability=1,
        divide_target_by=MAX_TARGET_POWER,
        input_stats=INPUT_STATS,
        independently_center_inputs=INDEPENDENTLY_CENTER_INPUTS)

    multi_source = MultiSource(sources=[{
        'source': real_appliance_source1,
        'train_probability': 0.5,
        'validation_probability': 0
    }, {
        'source': same_location_source1,
        'train_probability': 0.5,
        'validation_probability': 1
    }],
                               standardisation_source=same_location_source1)

    net_dict_copy = deepcopy(net_dict)
    net_dict_copy.update(
        dict(experiment_name=name,
             source=multi_source,
             plotter=StartEndMeanPlotter(n_seq_to_plot=32,
                                         n_training_examples_to_plot=16,
                                         max_target_power=MAX_TARGET_POWER)))
    net = Net(**net_dict_copy)
    net.load_params(730532)
    return net
示例#31
0
def exp_a(name):
    global source
    source_dict_copy = deepcopy(source_dict)
    source_dict_copy.update(dict(logger=logging.getLogger(name)))
    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': PadLayer,
            'width': 4
        },
        {
            'type': Conv1DLayer,  # convolve over the time axis
            'num_filters': 16,
            'filter_size': 4,
            'stride': 1,
            'nonlinearity': None,
            'border_mode': 'valid'
        },
        {
            'type': Conv1DLayer,  # convolve over the time axis
            'num_filters': 16,
            'filter_size': 4,
            'stride': 1,
            'nonlinearity': None,
            'border_mode': 'valid'
        },
        {
            'type': DimshuffleLayer,
            'pattern': (0, 2, 1),  # back to (batch, time, features)
            'label': 'dimshuffle3'
        },
        {
            'type': DenseLayer,
            'num_units': 512 * 16,
            'nonlinearity': rectify,
            'label': 'dense0'
        },
        {
            'type': DenseLayer,
            'num_units': 512 * 8,
            'nonlinearity': rectify,
            'label': 'dense1'
        },
        {
            'type': DenseLayer,
            'num_units': 512 * 4,
            'nonlinearity': rectify,
            'label': 'dense2'
        },
        {
            'type': DenseLayer,
            'num_units': 512,
            'nonlinearity': rectify
        },
        {
            'type': DenseLayer,
            'num_units': 3,
            'nonlinearity': None
        }
    ]
    net = Net(**net_dict_copy)
    net.load_params(300000)
    return net
示例#32
0
def exp_z(name):
    # N = 50, 5 layers (!), 2x2x subsampling
    #  avg valid cost =  0.4871760607
    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,
        updates=partial(nesterov_momentum, learning_rate=0.001),
        epoch_callbacks={},
        do_save_activations=False
    ))
    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': 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': 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': DenseLayer,
            'num_units': source.n_outputs,
            'nonlinearity': None,
            'W': Normal(std=(1/sqrt(N)))
        }
    ]
    net = Net(**net_dict_copy)
    net.load_params('e277z.hdf5', 1500)
    return net
示例#33
0
def exp_b(name):
    # conv at beginning
    logger = logging.getLogger(name)
    global multi_source

    SEQ_LENGTH = 256
    N_SEQ_PER_BATCH = 64

    real_appliance_source1 = RealApplianceSource(
        logger=logger,
        filename=UKDALE_FILENAME,
        appliances=[
            TARGET_APPLIANCE,
            ['fridge freezer', 'fridge', 'freezer'],
            'dish washer',
            'kettle',
            ['washer dryer', 'washing machine']
        ],
        max_appliance_powers=[MAX_TARGET_POWER, 300, 2500, 2600, 2400],
        on_power_thresholds=[ON_POWER_THRESHOLD] + [10] * 4,
        min_on_durations=[MIN_ON_DURATION, 60, 1800, 12, 1800],
        min_off_durations=[MIN_OFF_DURATION, 12, 1800, 12, 600],
        divide_input_by_max_input_power=False,
        window_per_building=WINDOW_PER_BUILDING,
        seq_length=SEQ_LENGTH,
        output_one_appliance=True,
        train_buildings=TRAIN_BUILDINGS,
        validation_buildings=VALIDATION_BUILDINGS,
        n_seq_per_batch=N_SEQ_PER_BATCH,
        skip_probability=0.75,
        skip_probability_for_first_appliance=SKIP_PROBABILITY_FOR_TARGET,
        standardise_input=True,
        input_stats=INPUT_STATS,
        independently_center_inputs=INDEPENDENTLY_CENTER_INPUTS,
        subsample_target=SUBSAMPLE_TARGET,
        input_padding=INPUT_PADDING
    )

    same_location_source1 = SameLocation(
        logger=logger,
        filename=UKDALE_FILENAME,
        target_appliance=TARGET_APPLIANCE,
        window_per_building=WINDOW_PER_BUILDING,
        seq_length=SEQ_LENGTH,
        train_buildings=TRAIN_BUILDINGS,
        validation_buildings=VALIDATION_BUILDINGS,
        n_seq_per_batch=N_SEQ_PER_BATCH,
        skip_probability=SKIP_PROBABILITY_FOR_TARGET,
        standardise_input=True,
        offset_probability=1,
        divide_target_by=MAX_TARGET_POWER,
        input_stats=INPUT_STATS,
        independently_center_inputs=INDEPENDENTLY_CENTER_INPUTS,
        on_power_threshold=ON_POWER_THRESHOLD,
        min_on_duration=MIN_ON_DURATION,
        min_off_duration=MIN_OFF_DURATION,
        include_all=True,
        allow_incomplete=True,
        subsample_target=SUBSAMPLE_TARGET,
        input_padding=INPUT_PADDING
    )

    multi_source = MultiSource(
        sources=[
            {
                'source': real_appliance_source1,
                'train_probability': 0.5,
                'validation_probability': 0
            },
            {
                'source': same_location_source1,
                'train_probability': 0.5,
                'validation_probability': 1
            }
        ],
        standardisation_source=same_location_source1
    )

    net_dict_copy = deepcopy(net_dict)
    net_dict_copy.update(dict(
        auto_reshape=True,
        experiment_name=name,
        source=multi_source,
        plotter=Plotter(
            n_seq_to_plot=32,
            n_training_examples_to_plot=16
        ),
        layers_config=[
            {
                'type': DimshuffleLayer,
                'pattern': (0, 2, 1)  # (batch, features, time)
            },
            {
                'type': Conv1DLayer,  # convolve over the time axis
                'num_filters': 16,
                'filter_size': 4,
                'stride': 1,
                'nonlinearity': None,
                'border_mode': 'same'
            },
            {
                'type': DimshuffleLayer,
                'pattern': (0, 2, 1),  # back to (batch, time, features)
                'label': 'dimshuffle3'
            },
            {
                'type': BLSTMLayer,
                'num_units': 128,
                'merge_mode': 'concatenate'
            },
            {
                'type': BLSTMLayer,
                'num_units': 256,
                'merge_mode': 'concatenate'
            },
            {
                'type': DenseLayer,
                'num_units': 128,
                'nonlinearity': tanh
            },
            {
                'type': DenseLayer,
                'num_units': 1,
                'nonlinearity': None
            }
        ]

    ))
    net = Net(**net_dict_copy)
    net.load_params(1500)
    return net
示例#34
0
    output_one_appliance=False,
    boolean_targets=False,
    min_on_duration=60,
    input_padding=4)

net = Net(experiment_name="e68",
          source=source,
          learning_rate=1e-1,
          save_plot_interval=50,
          loss_function=crossentropy,
          layers_config=[{
              'type': QuantizeLayer,
              'n_bins': 50
          }, {
              'type': DenseLayer,
              'num_units': 50,
              'nonlinearity': sigmoid
          }, {
              'type': LSTMLayer,
              'num_units': 50,
              'W_in_to_cell': Uniform(5)
          }, {
              'type': DenseLayer,
              'num_units': source.n_outputs,
              'nonlinearity': sigmoid
          }])

net.print_net()
net.compile()
net.fit()
示例#35
0
    subsample_target=5 * 5)

net = Net(experiment_name="e46",
          source=source,
          learning_rate=1e-1,
          save_plot_interval=50,
          loss_function=crossentropy,
          layers_config=[{
              'type': BLSTMLayer,
              'num_units': 20,
              'W_in_to_cell': Normal(1.0)
          }, {
              'type': SubsampleLayer,
              'stride': 5
          }, {
              'type': BLSTMLayer,
              'num_units': 40,
              'W_in_to_cell': Normal(1.0)
          }, {
              'type': SubsampleLayer,
              'stride': 5
          }, {
              'type': BLSTMLayer,
              'num_units': 80,
              'W_in_to_cell': Normal(1.0)
          }, {
              'type': DenseLayer,
              'num_units': source.n_outputs,
              'nonlinearity': sigmoid
          }])

net.fit()
示例#36
0
from __future__ import print_function, division
from neuralnilm import Net, RealApplianceSource
from lasagne.nonlinearities import sigmoid

source = RealApplianceSource(
    '/data/dk3810/ukdale.h5', 
    ['fridge freezer', 'hair straighteners', 'television'],
    max_input_power=1000, max_output_power=300,
    window=("2013-06-01", "2014-06-01")
)

net = Net(
    source=source,
    n_cells_per_hidden_layer=[50,50,50],
    output_nonlinearity=sigmoid,
    learning_rate=1e-1,
    n_dense_cells_per_layer=50
)

net.fit(n_iterations=1600)
net.plot_costs()
net.plot_estimates()
示例#37
0
def exp_a(name):
    # global source
    # source = RealApplianceSource(
    #     filename='/data/dk3810/ukdale.h5',
    #     appliances=[
    #         ['fridge freezer', 'fridge', 'freezer'], 
    #         'hair straighteners', 
    #         'television'
    #         # 'dish washer',
    #         # ['washer dryer', 'washing machine']
    #     ],
    #     max_appliance_powers=[2500] * 5,
    #     on_power_thresholds=[5] * 5,
    #     max_input_power=2500,
    #     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=1520,
    #     output_one_appliance=False,
    #     boolean_targets=False,
    #     train_buildings=[1],
    #     validation_buildings=[1], 
    #     skip_probability=0.7,
    #     n_seq_per_batch=25,
    #     input_padding=1,
    #     include_diff=False,
    #     clip_appliance_power=False
    # )

    net = Net(
        experiment_name=name,
        source=source,
        save_plot_interval=1000,
        loss_function=mse,
        updates=partial(nesterov_momentum, learning_rate=0.1, clip_range=(-1, 1)),
        layers_config=[
            {
                'type': DimshuffleLayer,
                'pattern': (0, 2, 1)  # (batch, features, time)
            },
            {
                'type': Conv1DLayer, # convolve over the time axis
                'num_filters': 10,
                'filter_length': 2,
                'stride': 1,
                'nonlinearity': sigmoid,
                'W': Uniform(5)
            },
            {
                'type': DimshuffleLayer,
                'pattern': (0, 2, 1) # back to (batch, time, features)
            },
            {
                'type': DenseLayer,
                'num_units': 50,
                'nonlinearity': rectify
            },
            {
                'type': DenseLayer,
                'num_units': source.n_outputs,
                'nonlinearity': None
#                'W': Uniform()
            }
        ]
    )
    return net
示例#38
0
def exp_a(name):
    # like 134a but linear outputs and MSE
    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=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.7,
        n_seq_per_batch=10)

    net = Net(
        experiment_name=name,
        source=source,
        save_plot_interval=5000,
        loss_function=mse,
        updates=partial(nesterov_momentum, learning_rate=1.0),
        layers_config=[{
            'type': DenseLayer,
            'num_units': 50,
            'nonlinearity': sigmoid,
            'W': Uniform(1),
            'b': Uniform(1)
        }, {
            'type': DenseLayer,
            'num_units': source.n_outputs,
            'nonlinearity': None
        }],
        layer_changes={
            50001: {
                'remove_from':
                -2,
                'new_layers': [{
                    'type': DenseLayer,
                    'num_units': 50,
                    'nonlinearity': sigmoid,
                    'W': Uniform(1),
                    'b': Uniform(1)
                }, {
                    'type': DenseLayer,
                    'num_units': source.n_outputs,
                    'nonlinearity': None
                }]
            },
            100001: {
                'remove_from':
                -2,
                'callback':
                set_save_plot_interval,
                'new_layers': [
                    {
                        'type': BLSTMLayer,
                        'num_units': 40,
                        #                        'W_in_to_cell': Uniform(5),
                        'gradient_steps': GRADIENT_STEPS,
                        'peepholes': False
                    },
                    {
                        'type': DenseLayer,
                        'num_units': source.n_outputs,
                        'nonlinearity': None
                    }
                ]
            },
            100501: {
                'remove_from':
                -3,
                'new_layers': [
                    {
                        'type': BLSTMLayer,
                        'num_units': 80,
                        #                        'W_in_to_cell': Uniform(5),
                        'gradient_steps': GRADIENT_STEPS,
                        'peepholes': False
                    },
                    {
                        'type': DenseLayer,
                        'num_units': source.n_outputs,
                        'nonlinearity': None
                    }
                ]
            }
        })
    return net
示例#39
0
source = RealApplianceSource(
    '/data/dk3810/ukdale.h5', 
    ['fridge freezer', 'hair straighteners', 'television'],
    max_input_power=1000, max_appliance_powers=[300, 500, 200],
    window=("2013-06-01", "2014-07-01"),
    output_one_appliance=False,
    boolean_targets=False,
    min_on_duration=60
#    sample_period=15, seq_length=400
)

net = Net(
    experiment_name="e43a",
    source=source,
    n_cells_per_hidden_layer=[50,50,50],
    output_nonlinearity=sigmoid,
    learning_rate=1e-1,
    n_dense_cells_per_layer=0,
    # validation_interval=2, 
    save_plot_interval=50,
    loss_function=crossentropy
)

# [200,200,200] n_dense_cells=200 got killed before training

net.fit()

#net.plot_costs()
#net.plot_estimates()
示例#40
0
def exp_a(name):
    """Results: Learning rate of 0.1 still NaNs."""
    """e91d but learning rate 0.01 
    and smaller inits (to try to capture 
    smaller changes) and larger first layer

    And e96 centres input data.  And I've fixed a problem where only the last
    instance of an appliance if multiple appliances occured within a batch would
    be shown in the targets.

    e98:
    Output just the fridge and use bool targets

    e99
    seq_length = 1000
    learning rate = 0.01 (tried 0.1 and 0.05 but both NaN'd)
    max_input_power = 500
    don't bother centering X
    only 50 units in first layer
    back to just 3 appliances
    skip prob = 0

    e100
    boolean_targets = False
    output_one_appliance=False
    """
    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=500,
        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,
        subsample_target=5,
        train_buildings=[1],
        validation_buildings=[1],
        skip_probability=0)

    net = Net(experiment_name=name + 'a',
              source=source,
              save_plot_interval=SAVE_PLOT_INTERVAL,
              loss_function=crossentropy,
              updates=partial(nesterov_momentum, learning_rate=0.01),
              layers_config=[{
                  'type': DenseLayer,
                  'num_units': 50,
                  'nonlinearity': sigmoid,
                  'W': Uniform(10),
                  'b': Uniform(10)
              }, {
                  'type': DenseLayer,
                  'num_units': 50,
                  'nonlinearity': sigmoid,
                  'W': Uniform(5),
                  'b': Uniform(5)
              }, {
                  'type': BLSTMLayer,
                  'num_units': 40,
                  'W_in_to_cell': Uniform(5),
                  'gradient_steps': GRADIENT_STEPS
              }, {
                  'type': DimshuffleLayer,
                  'pattern': (0, 2, 1)
              }, {
                  'type': Conv1DLayer,
                  'num_filters': 60,
                  'filter_length': 5,
                  'stride': 5,
                  'nonlinearity': sigmoid
              }, {
                  'type': DimshuffleLayer,
                  'pattern': (0, 2, 1)
              }, {
                  'type': BLSTMLayer,
                  'num_units': 80,
                  'W_in_to_cell': Uniform(5),
                  'gradient_steps': GRADIENT_STEPS
              }, {
                  'type': DenseLayer,
                  'num_units': source.n_outputs,
                  'nonlinearity': sigmoid
              }])
    return net
示例#41
0
def exp_a(name):
    global source
    source_dict_copy = deepcopy(source_dict)
    source = RandomSegmentsInMemory(**source_dict_copy)
    net_dict_copy = deepcopy(net_dict)
    net_dict_copy.update(dict(experiment_name=name, source=source))
    NUM_FILTERS = 4
    net_dict_copy['layers_config'] = [
        {
            'type': DimshuffleLayer,
            'pattern': (0, 2, 1)  # (batch, features, time)
        },
        {
            'label': 'conv0',
            'type': Conv1DLayer,  # convolve over the time axis
            'num_filters': NUM_FILTERS,
            'filter_length': 4,
            'stride': 1,
            'nonlinearity': None,
            'border_mode': 'valid'
        },
        {
            'type': DimshuffleLayer,
            'pattern': (0, 2, 1)  # back to (batch, time, features)
        },
        {
            'label': 'dense0',
            'type': DenseLayer,
            'num_units': (SEQ_LENGTH - 3) * NUM_FILTERS,
            'nonlinearity': rectify
        },
        {
            'label': 'dense1',
            'type': DenseLayer,
            'num_units': SEQ_LENGTH - 3,
            'nonlinearity': rectify
        },
        {
            'type': DenseLayer,
            'num_units': (SEQ_LENGTH - 3) * NUM_FILTERS,
            'nonlinearity': rectify
        },
        {
            'type': ReshapeLayer,
            'shape': (N_SEQ_PER_BATCH, SEQ_LENGTH - 3, NUM_FILTERS)
        },
        {
            'type': DimshuffleLayer,
            'pattern': (0, 2, 1)  # (batch, features, time)
        },
        {
            'type': DeConv1DLayer,
            'num_output_channels': 1,
            'filter_length': 4,
            'stride': 1,
            'nonlinearity': None,
            'border_mode': 'full'
        },
        {
            'type': DimshuffleLayer,
            'pattern': (0, 2, 1)  # back to (batch, time, features)
        }
    ]
    net = Net(**net_dict_copy)
    return net
示例#42
0
def exp_h(name):
    # Same as A but without gradient_steps = 100
    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=500,
        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,
        subsample_target=5,
        train_buildings=[1],
        validation_buildings=[1],
        skip_probability=0)

    net = Net(experiment_name=name + 'h',
              source=source,
              save_plot_interval=SAVE_PLOT_INTERVAL,
              loss_function=crossentropy,
              updates=partial(nesterov_momentum, learning_rate=0.01),
              layers_config=[{
                  'type': DenseLayer,
                  'num_units': 50,
                  'nonlinearity': sigmoid,
                  'W': Uniform(10),
                  'b': Uniform(10)
              }, {
                  'type': DenseLayer,
                  'num_units': 50,
                  'nonlinearity': sigmoid,
                  'W': Uniform(5),
                  'b': Uniform(5)
              }, {
                  'type': BLSTMLayer,
                  'num_units': 40,
                  'W_in_to_cell': Uniform(5)
              }, {
                  'type': DimshuffleLayer,
                  'pattern': (0, 2, 1)
              }, {
                  'type': Conv1DLayer,
                  'num_filters': 60,
                  '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
示例#43
0
net = Net(
    experiment_name="e89",
    source=source,
    save_plot_interval=50,
    loss_function=crossentropy,
    updates=partial(nesterov_momentum, learning_rate=0.001),
    layers_config=[
        {
            'type': LSTMLayer,  # TODO change to BLSTM
            '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': LSTMLayer,
            'num_units': 80,
            'W_in_to_cell': Uniform(5)
        },
        {
            'type': DenseLayer,
            'num_units': source.n_outputs,
            'nonlinearity': sigmoid
        }
    ])
示例#44
0
def exp_a(name):
    global source
    source_dict_copy = deepcopy(source_dict)
    source = SameLocation(**source_dict_copy)
    net_dict_copy = deepcopy(net_dict)
    net_dict_copy.update(dict(
        experiment_name=name,
        source=source
    ))
    NUM_FILTERS = 4
    net_dict_copy['layers_config'] = [
        {
            'type': DimshuffleLayer,
            'pattern': (0, 2, 1)  # (batch, features, time)
        },
        {
            'label': 'conv0',
            'type': Conv1DLayer,  # convolve over the time axis
            'num_filters': NUM_FILTERS,
            'filter_length': 4,
            'stride': 1,
            'nonlinearity': None,
            'border_mode': 'valid'
        },
        {
            'type': DimshuffleLayer,
            'pattern': (0, 2, 1)  # back to (batch, time, features)
        },
        {
            'label': 'dense0',
            'type': DenseLayer,
            'num_units': (SEQ_LENGTH - 3) * NUM_FILTERS,
            'nonlinearity': rectify
        },
        {
            'label': 'dense1',
            'type': DenseLayer,
            'num_units': SEQ_LENGTH - 3,
            'nonlinearity': rectify
        },
        {
            'type': DenseLayer,
            'num_units': (SEQ_LENGTH - 3) * NUM_FILTERS,
            'nonlinearity': rectify
        },
        {
            'type': ReshapeLayer,
            'shape': (N_SEQ_PER_BATCH, SEQ_LENGTH - 3, NUM_FILTERS)
        },
        {
            'type': DimshuffleLayer,
            'pattern': (0, 2, 1)  # (batch, features, time)
        },
        {
            'type': DeConv1DLayer,
            'num_output_channels': 1,
            'filter_length': 4,
            'stride': 1,
            'nonlinearity': None,
            'border_mode': 'full'
        },
        {
            'type': DimshuffleLayer,
            'pattern': (0, 2, 1)  # back to (batch, time, features)
        }
    ]
    net = Net(**net_dict_copy)
    net.load_params(15000)
    return net
示例#45
0
def exp_a(name):
    # conv, conv
    global source
    source_dict_copy = deepcopy(source_dict)
    source_dict_copy.update(dict(logger=logging.getLogger(name)))
    source = RealApplianceSource(**source_dict_copy)
    net_dict_copy = deepcopy(net_dict)
    net_dict_copy.update(dict(experiment_name=name, source=source))
    NUM_FILTERS = 16
    target_seq_length = source.output_shape_after_processing()[1]
    net_dict_copy['layers_config'] = [
        {
            'type': DimshuffleLayer,
            'pattern': (0, 2, 1)  # (batch, features, time)
        },
        {
            'type': Conv1DLayer,  # convolve over the time axis
            'num_filters': NUM_FILTERS,
            'filter_size': 4,
            'stride': 1,
            'nonlinearity': None,
            'border_mode': 'valid'
        },
        {
            'type': Conv1DLayer,  # convolve over the time axis
            'num_filters': NUM_FILTERS,
            'filter_size': 4,
            'stride': 1,
            'nonlinearity': None,
            'border_mode': 'valid'
        },
        {
            'type': DimshuffleLayer,
            'pattern': (0, 2, 1)  # back to (batch, time, features)
        },
        {
            'type': DropoutLayer,
            'p': 0.5
        },
        {
            'type': DenseLayer,
            'num_units': 512,
            'nonlinearity': rectify
        },
        {
            'type': DropoutLayer,
            'p': 0.5
        },
        {
            'type': DenseLayer,
            'num_units': 512,
            'nonlinearity': rectify
        },
        {
            'type': DropoutLayer,
            'p': 0.5
        },
        {
            'type': DenseLayer,
            'num_units': 512,
            'nonlinearity': rectify
        },
        {
            'type': DropoutLayer,
            'p': 0.5
        },
        {
            'type': DenseLayer,
            'num_units': target_seq_length,
            'nonlinearity': None
        }
    ]
    net = Net(**net_dict_copy)
    return net
示例#46
0
def exp_a(name):
    # conv, conv
    global source
    source_dict_copy = deepcopy(source_dict)
    source_dict_copy.update(dict(
        logger=logging.getLogger(name)
    ))
    source = RealApplianceSource(**source_dict_copy)
    net_dict_copy = deepcopy(net_dict)
    net_dict_copy.update(dict(
        experiment_name=name,
        source=source
    ))
    NUM_FILTERS = 16
    target_seq_length = source.output_shape_after_processing()[1]
    net_dict_copy['layers_config'] = [
        {
            'type': DimshuffleLayer,
            'pattern': (0, 2, 1)  # (batch, features, time)
        },
        {
            'type': Conv1DLayer,  # convolve over the time axis
            'num_filters': NUM_FILTERS,
            'filter_size': 4,
            'stride': 1,
            'nonlinearity': None,
            'border_mode': 'valid'
        },
        #  Need to do ugly dimshuffle, reshape, reshape, dimshuffle
        #  to get output of first Conv1DLayer ready for
        #  ConcatLayer
        # {
        #     'type': DimshuffleLayer,
        #     'pattern': (0, 2, 1),  # back to (batch, time, features)
        #     'label': 'dimshuffle1'
        # },
        # {
        #     'type': ReshapeLayer,
        #     'shape': (N_SEQ_PER_BATCH, -1),
        #     'label': 'reshape0'
        # },
        # {
        #     'type': ReshapeLayer,
        #     'shape': (N_SEQ_PER_BATCH, NUM_FILTERS, -1)
        # },
        # {
        #     'type': DimshuffleLayer,
        #     'pattern': (0, 2, 1),  # back to (batch, time, features)
        #     'label': 'dimshuffle2'
        # },
        {
            'type': Conv1DLayer,  # convolve over the time axis
            'num_filters': NUM_FILTERS,
            'filter_size': 4,
            'stride': 1,
            'nonlinearity': None,
            'border_mode': 'valid'
        },
        {
            'type': DimshuffleLayer,
            'pattern': (0, 2, 1),  # back to (batch, time, features)
            'label': 'dimshuffle3'
        },
        {
            'type': DenseLayer,
            'num_units': 512,
            'nonlinearity': rectify,
            'label': 'dense0'
        },
        {
            'type': DenseLayer,
            'num_units': 512,
            'nonlinearity': rectify,
            'label': 'dense1'
        },
        {
            'type': DenseLayer,
            'num_units': 512,
            'nonlinearity': rectify,
            'label': 'dense2'
        },
        {
            'type': ConcatLayer,
            'axis': 1,
            'incomings': ['dense0', 'dense2']
        },
        {
            'type': DenseLayer,
            'num_units': 512,
            'nonlinearity': rectify
        },
        {
            'type': DenseLayer,
            'num_units': target_seq_length,
            'nonlinearity': None
        }
    ]
    net = Net(**net_dict_copy)
    return net
示例#47
0
def exp_a(name):
    global source
    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,
        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.7,
        n_seq_per_batch=10,
        subsample_target=5,
        #input_padding=4,
        include_diff=False,
        clip_appliance_power=False,
        lag=32)

    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': 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': LSTMLayer,
                'num_units': 40,
                'W_in_to_cell': Uniform(5),
                'gradient_steps': GRADIENT_STEPS,
                'peepholes': False
            },
            {
                'type': DimshuffleLayer,
                'pattern': (0, 2, 1)
            },
            {
                'type': Conv1DLayer,
                'num_filters': 20,
                'filter_length': 5,
                'stride': 5,
                'nonlinearity': sigmoid
                #                'W': Uniform(1)
            },
            {
                'type': DimshuffleLayer,
                'pattern': (0, 2, 1)
            },
            # {
            #     'type': FeaturePoolLayer,
            #     'ds': 5, # number of feature maps to be pooled together
            #     'axis': 1 # pool over the time axis
            # },
            {
                'type': LSTMLayer,
                'num_units': 80,
                'W_in_to_cell': Uniform(5),
                'gradient_steps': GRADIENT_STEPS,
                'peepholes': False
            },
            {
                'type': DenseLayer,
                'num_units': source.n_outputs,
                'nonlinearity': sigmoid
                #                'W': Uniform(1)
            }
        ])
    return net
示例#48
0
def exp_a(name):
    logger = logging.getLogger(name)
    real_appliance_source1 = RealApplianceSource(
        logger=logger,
        filename=UKDALE_FILENAME,
        appliances=[
            TARGET_APPLIANCE, ['fridge freezer', 'fridge', 'freezer'],
            'dish washer', 'kettle', ['washer dryer', 'washing machine']
        ],
        max_appliance_powers=[MAX_TARGET_POWER, 300, 2500, 2600, 2400],
        on_power_thresholds=[ON_POWER_THRESHOLD] + [10] * 4,
        min_on_durations=[MIN_ON_DURATION, 60, 1800, 12, 1800],
        min_off_durations=[MIN_OFF_DURATION, 12, 1800, 12, 600],
        divide_input_by_max_input_power=False,
        window_per_building=WINDOW_PER_BUILDING,
        seq_length=SEQ_LENGTH,
        output_one_appliance=True,
        train_buildings=TRAIN_BUILDINGS,
        validation_buildings=VALIDATION_BUILDINGS,
        n_seq_per_batch=N_SEQ_PER_BATCH,
        skip_probability=0.75,
        skip_probability_for_first_appliance=SKIP_PROBABILITY_FOR_TARGET,
        #        target_is_start_and_end_and_mean=True,
        standardise_input=True,
        input_stats=INPUT_STATS,
        independently_center_inputs=INDEPENDENTLY_CENTER_INPUTS)

    #     same_location_source1 = SameLocation(
    #         logger=logger,
    #         filename=UKDALE_FILENAME,
    #         target_appliance=TARGET_APPLIANCE,
    #         window_per_building=WINDOW_PER_BUILDING,
    #         seq_length=SEQ_LENGTH,
    #         train_buildings=TRAIN_BUILDINGS,
    #         validation_buildings=VALIDATION_BUILDINGS,
    #         n_seq_per_batch=N_SEQ_PER_BATCH,
    #         skip_probability=SKIP_PROBABILITY_FOR_TARGET,
    # #        target_is_start_and_end_and_mean=True,
    #         standardise_input=True,
    #         offset_probability=1,
    #         divide_target_by=MAX_TARGET_POWER,
    #         input_stats=INPUT_STATS,
    #         independently_center_inputs=INDEPENDENTLY_CENTER_INPUTS,
    #         on_power_threshold=ON_POWER_THRESHOLD,
    #         min_on_duration=MIN_ON_DURATION,
    #         min_off_duration=MIN_OFF_DURATION
    #     )

    # multi_source = MultiSource(
    #     sources=[
    #         {
    #             'source': real_appliance_source1,
    #             'train_probability': 0.5,
    #             'validation_probability': 0
    #         },
    #         {
    #             'source': same_location_source1,
    #             'train_probability': 0.5,
    #             'validation_probability': 1
    #         }
    #     ],
    #     standardisation_source=same_location_source1
    # )

    net_dict_copy = deepcopy(net_dict)
    net_dict_copy.update(
        dict(experiment_name=name,
             source=real_appliance_source1,
             plotter=Plotter(n_seq_to_plot=32,
                             n_training_examples_to_plot=16)))
    net = Net(**net_dict_copy)
    return net
示例#49
0
def exp_a(name):
    """Results: Learning rate of 0.1 still NaNs."""
    """e91d but with smaller learning rate 0.01 
    (now that we're using gradient_steps=100) and smaller inits (to try to capture 
    smaller changes) and larger first layer"""
    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],
        min_on_durations=[60, 60, 60, 1800, 1800],
        window=("2013-06-01", "2014-07-01"),
        seq_length=1500,
        output_one_appliance=False,
        boolean_targets=False,
        min_off_duration=60,
        subsample_target=5,
        train_buildings=[1],
        validation_buildings=[1],
        skip_probability=0.7)

    net = Net(experiment_name=name + 'a',
              source=source,
              save_plot_interval=SAVE_PLOT_INTERVAL,
              loss_function=crossentropy,
              updates=partial(nesterov_momentum, learning_rate=0.01),
              layers_config=[{
                  'type': DenseLayer,
                  'num_units': 200,
                  'nonlinearity': sigmoid,
                  'W': Uniform(10),
                  'b': Uniform(10)
              }, {
                  'type': DenseLayer,
                  'num_units': 50,
                  'nonlinearity': sigmoid,
                  'W': Uniform(5),
                  'b': Uniform(5)
              }, {
                  'type': BLSTMLayer,
                  'num_units': 40,
                  'W_in_to_cell': Uniform(5),
                  'gradient_steps': GRADIENT_STEPS
              }, {
                  'type': DimshuffleLayer,
                  'pattern': (0, 2, 1)
              }, {
                  'type': Conv1DLayer,
                  'num_filters': 60,
                  'filter_length': 5,
                  'stride': 5,
                  'nonlinearity': sigmoid
              }, {
                  'type': DimshuffleLayer,
                  'pattern': (0, 2, 1)
              }, {
                  'type': BLSTMLayer,
                  'num_units': 80,
                  'W_in_to_cell': Uniform(5),
                  'gradient_steps': GRADIENT_STEPS
              }, {
                  'type': DenseLayer,
                  'num_units': source.n_outputs,
                  'nonlinearity': sigmoid
              }])
    return net
示例#50
0
from __future__ import print_function, division
from neuralnilm import Net, ToySource
from lasagne.nonlinearities import sigmoid

source = ToySource(seq_length=300, n_seq_per_batch=30)

net = Net(source=source,
          n_cells_per_hidden_layer=[10],
          output_nonlinearity=sigmoid,
          learning_rate=1e-1)

net.fit(n_iterations=1000)
net.plot_costs()
net.plot_estimates()