def add_input_layer(self, dimension: int): """ Add an input layer to this DockNet after the last layer; note a Docknet is supposed to have a single input layer as first layer :param dimension: input vector size """ layer = InputLayer(dimension) self.layers.append(layer)
def test_initialize(initializer1): np.random.seed(1) expected_W1 = [[0.08121727, -0.03058782], [-0.02640859, -0.05364843], [0.04327038, -0.11507693]] expected_b1 = [[0.08724059], [-0.03806035], [0.01595195]] l0 = InputLayer(2) l1 = DenseLayer(2, 3, 'relu') layers = [l0, l1] initializer1.initialize(layers) assert l0.params == {} assert_array_almost_equal(l1.params['W'], expected_W1) assert_array_almost_equal(l1.params['b'], expected_b1)
def test_optimizer(optimizer1): l0 = InputLayer(2) l1 = DenseLayer(2, 3, 'relu') l1.W = W1 l1.b = b1 layers = [l0, l1] gradients = [{'W': dJdW1, 'b': dJdb1}] expected_optimized_W1 = optimized_W1 expected_optimized_b1 = optimized_b1 optimizer1.reset(layers) optimizer1.optimize(layers, gradients) assert_array_almost_equal(l1.params['W'], expected_optimized_W1, decimal=4) assert_array_almost_equal(l1.params['b'], expected_optimized_b1, decimal=4)