def test_invalid_error_function(repeat): """ Test the errors raised by initialising an instance of the NeuralNetwork class when there is an invalid value for the error_func argument """ set_random_seed_from_args("test_invalid_error_function", repeat) n = NeuralNetwork(error_func=models.errors._SumOfSquares) x, N_D = get_random_inputs(n.input_dim) t = get_random_targets(n.output_dim, N_D) n.forward_prop(x) with pytest.raises(TypeError): # Network is initialised with the SumOfSquares class, not an instance n.mean_total_error(t) n = NeuralNetwork(error_func=sum) x, N_D = get_random_inputs(n.input_dim) t = get_random_targets(n.output_dim, N_D) n.forward_prop(x) # Error function sum is callable, so mean_error is okay n.mean_total_error(t) with pytest.raises(AttributeError): # Error function sum has no dydx method, so backprop fails n.back_prop(x, t)
def test_invalid_act_function(repeat): """ Test the errors raised by initialising an instance of the NeuralNetwork class when there is an invalid value for the act_funcs argument """ set_random_seed_from_args("test_invalid_act_function", repeat) with pytest.raises(TypeError): # act_funcs argument should be a list of activation function objects n = NeuralNetwork(act_funcs=models.activations.gaussian) n = NeuralNetwork(act_funcs=[models.activations._Gaussian]) x, _ = get_random_inputs(n.input_dim) with pytest.raises(TypeError): # Network is initialised with the Gaussian class, not an instance n.forward_prop(x) n = NeuralNetwork(act_funcs=[None]) x, _ = get_random_inputs(n.input_dim) with pytest.raises(TypeError): # Activation function None is not callable n.forward_prop(x) n = NeuralNetwork(act_funcs=[abs]) x, N_D = get_random_inputs(n.input_dim) t = get_random_targets(n.output_dim, N_D) # Activation function abs is callable, so forward_prop is okay n.forward_prop(x) with pytest.raises(AttributeError): # Activation function abs has no dydx method, so backprop fails n.back_prop(x, t)