pythonlasagnenolearn

removing bias from neural network layer


I want to remove the bias parameter. I tried to include thebias=None where I define my neural net, but it didn't work.

net1 = NeuralNet(
layers=[ # three layers: one hidden layer
('input', layers.InputLayer),
#('hidden', layers.DenseLayer),
('output', layers.DenseLayer),
],
# layer parameters:
input_shape=(None,2), # 2 inputs
#hidden_num_units=200, # number of units in hidden layer
output_nonlinearity=None, # output layer uses identity function
output_num_units=1, # 1 target value

# optimization method:
update=nesterov_momentum,
update_learning_rate=0.01,
update_momentum=0.9,

regression=True,  # flag to indicate we're dealing with regression problem
max_epochs=400,  # we want to train this many epochs
verbose=1,
bias = None
) 

Solution

  • # Build the network yourself
    inputs = InputLayer(shape=(None, 2))
    network = DenseLayer(inputs, num_units=1, nonlinearity=None, b = None)
    
    net1 = NeuralNet(
    network,
    #We don't need any of these parameters since we provided them above
    # layer parameters:
    #input_shape=(None,2), # 2 inputs
    #hidden_num_units=200, # number of units in hidden layer
    #output_nonlinearity=None, # output layer uses identity function
    #output_num_units=1, # 1 target value
    
    # optimization method:
    update=nesterov_momentum,
    update_learning_rate=0.01,
    update_momentum=0.9,
    
    regression=True,  # flag to indicate we're dealing with regression problem
    max_epochs=400,  # we want to train this many epochs
    verbose=1,
    bias = None
    ) 
    

    I think this should work. There might be a kwarg to pass in the network (I can't remember) but I think it's by default the first parameter if nothing's given.