def test_mse(): from lasagne.objectives import mse output = np.array([[1.0, 0.0, 1.0, 0.0], [-1.0, 0.0, -1.0, 0.0]]) target = np.zeros((2, 4)) result = mse(output, target) assert result.eval() == 0.5
validation_buildings=[1], n_seq_per_batch=N_SEQ_PER_BATCH, standardise_input=True, standardise_targets=True, ignore_incomplete=True, offset_probability=0.5, ignore_offset_activations=True ) net_dict = dict( save_plot_interval=SAVE_PLOT_INTERVAL, # loss_function=partial(ignore_inactive, loss_func=mdn_nll, seq_length=SEQ_LENGTH), # loss_function=lambda x, t: mdn_nll(x, t).mean(), # loss_function=lambda x, t: (mse(x, t) * MASK).mean(), loss_function=lambda x, t: mse(x, t).mean(), # loss_function=lambda x, t: binary_crossentropy(x, t).mean(), # loss_function=partial(scaled_cost, loss_func=mse), # loss_function=ignore_inactive, # loss_function=partial(scaled_cost3, ignore_inactive=False), # updates_func=momentum, updates_func=clipped_nesterov_momentum, updates_kwargs={'clip_range': (0, 10)}, learning_rate=1e-2, learning_rate_changes_by_iteration={ 1000: 1e-3, 5000: 1e-4 }, do_save_activations=True, auto_reshape=False, # plotter=CentralOutputPlotter
def exp_j(name): # like a but with max power = 1000W and 5 appliances # tanh and softplus output # sane inits for other layers # output one appliance 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, output_one_appliance=True )) 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-3, learning_rate_changes_by_iteration={ 1000: 1e-4, 2000: 1e-5 } )) 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(200)), 'b': Normal(std=1/sqrt(200)) }, { '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) return net
def exp_d(name): # tanh and softplus output # sane inits for other layers # batch norm 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': identity, 'W': Uniform(25), 'b': Uniform(25) }, { 'type': BatchNormLayer, 'axes': (0, 1), 'nonlinearity': tanh }, { 'type': DenseLayer, 'num_units': 50, 'nonlinearity': identity, 'W': Normal(std=1/sqrt(50)), 'b': Normal(std=1/sqrt(50)) }, { 'type': BatchNormLayer, 'axes': (0, 1), 'nonlinearity': tanh }, { 'type': BidirectionalRecurrentLayer, 'num_units': 40, 'W_in_to_hid': Normal(std=1/sqrt(50)), 'gradient_steps': GRADIENT_STEPS, 'nonlinearity': tanh, # need nonlinearity for hid_to_hid 'learn_init': False, 'precompute_input': False }, { 'type': BatchNormLayer, 'axes': (0, 1), 'nonlinearity': identity }, { 'type': DimshuffleLayer, 'pattern': (0, 2, 1) }, { 'type': Conv1DLayer, 'num_filters': 20, 'filter_length': 4, 'stride': 4, 'nonlinearity': identity, 'W': Normal(std=1/sqrt(50)) }, { 'type': BatchNormLayer, 'nonlinearity': tanh }, { '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': BatchNormLayer, 'nonlinearity': tanh, 'axes': (0, 1) }, { 'type': DenseLayer, 'num_units': source.n_outputs, 'nonlinearity': T.nnet.softplus } ] net = Net(**net_dict_copy) return net
# 'std': np.array([ 0.12636775], dtype=np.float32)}, # target_stats={ # 'mean': np.array([ 0.04066789, 0.01881946, # 0.24639061, 0.17608672, 0.10273963], # dtype=np.float32), # 'std': np.array([ 0.11449792, 0.07338708, # 0.26608968, 0.33463112, 0.21250485], # dtype=np.float32)} ) net_dict = dict( save_plot_interval=SAVE_PLOT_INTERVAL, # loss_function=partial(ignore_inactive, loss_func=mdn_nll, seq_length=SEQ_LENGTH), # loss_function=lambda x, t: mdn_nll(x, t).mean(), loss_function=lambda x, t: (mse(x, t) * MASK).mean(), # loss_function=lambda x, t: binary_crossentropy(x, t).mean(), # loss_function=partial(scaled_cost, loss_func=mse), # loss_function=ignore_inactive, # loss_function=partial(scaled_cost3, ignore_inactive=False), # updates_func=momentum, updates_func=clipped_nesterov_momentum, updates_kwargs={'clip_range': (0, 10)}, learning_rate=1e-7, learning_rate_changes_by_iteration={ # 5000: 1e-6, # 7000: 1e-7 # 800: 1e-4 # 500: 1e-3 # 4000: 1e-03, # 6000: 5e-06,
# 'std': np.array([ 0.12636775], dtype=np.float32)}, # target_stats={ # 'mean': np.array([ 0.04066789, 0.01881946, # 0.24639061, 0.17608672, 0.10273963], # dtype=np.float32), # 'std': np.array([ 0.11449792, 0.07338708, # 0.26608968, 0.33463112, 0.21250485], # dtype=np.float32)} ) N = 50 net_dict = dict( save_plot_interval=SAVE_PLOT_INTERVAL, # loss_function=partial(ignore_inactive, loss_func=mdn_nll, seq_length=SEQ_LENGTH), # loss_function=lambda x, t: mdn_nll(x, t).mean(), loss_function=lambda x, t: mse(x, t).mean(), # loss_function=lambda x, t: binary_crossentropy(x, t).mean(), # loss_function=partial(scaled_cost, loss_func=mse), # loss_function=ignore_inactive, # loss_function=partial(scaled_cost3, ignore_inactive=False), # updates_func=momentum, updates_func=clipped_nesterov_momentum, updates_kwargs={'clip_range': (0, 10)}, learning_rate=1e-5, learning_rate_changes_by_iteration={ 5000: 1e-6, 7000: 1e-7 # 800: 1e-4 # 500: 1e-3 # 4000: 1e-03, # 6000: 5e-06,
def exp_c(name): # tanh and softplus output 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': Uniform(10), 'b': Uniform(10) }, { 'type': BidirectionalRecurrentLayer, 'num_units': 40, 'W_in_to_hid': Uniform(5), '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 }, { 'type': DimshuffleLayer, 'pattern': (0, 2, 1) }, { 'type': BidirectionalRecurrentLayer, 'num_units': 80, 'W_in_to_hid': Uniform(5), '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