Beispiel #1
0
def test():
    data = np.random.rand(1000, 1)
    target = data ** 2
    net = am.mlp_network([1, 50, 1], 'tanh', 'identity')
    print('\nNet created.\n')
    am.fit_adaptive_gradient_descent(net, data, target, 0.1, 10, 10)
    print('\nFinished.\n')
    return net
Beispiel #2
0
 def test_poke_inputs(self, shape=(40, 3, 2)):
     # Stage 1: Poke data
     neural_network = mlp_network(list(shape), 'tanh', 'identity')
     sample_data = np.random.rand(shape[0])
     neural_network.poke_inputs(sample_data)
     # Stage 2: Verify previous operation
     input_layer = neural_network.layers[0]
     observed_data = np.asarray([neuron.output for neuron in input_layer])
     self.assertTrue((observed_data == sample_data).all)
Beispiel #3
0
 def test_pick_outputs(self, shape=(4, 6, 78)):
     # Stage 1: Write data in last layer neuron outputs
     neural_network = mlp_network(list(shape), 'tanh', 'identity')
     sample_data = np.random.rand(shape[-1])
     last_layer = neural_network.layers[-1]
     for neuron, output_value in zip(last_layer, sample_data):
         neuron.output = output_value
     # Stage 2: Check pick_outputs
     observed_data = np.asarray(neural_network.pick_outputs())
     self.assertTrue((observed_data == sample_data).all)
Beispiel #4
0
 def test_make_neuron_fit_strategy_neuron_in_hidden_layer(
         self, hidden_layer_size=20):
     neural_network = mlp_network([3, hidden_layer_size, 2], 'default',
                                  'default')
     factory = AdaptiveGradientDescentMaterialsFactory()
     for hidden_neuron in neural_network.layers[1]:
         fit_strategy = factory.make_neuron_fit_strategy(hidden_neuron)
         self.assertTrue(
             isinstance(fit_strategy,
                        AdaptiveGradientDescentHiddenNeuronFitStrategy))
Beispiel #5
0
 def test_make_neuron_fit_strategy_neuron_in_output_layer(
         self, output_layer_size=20):
     neural_network = mlp_network([3, 3, output_layer_size], 'default',
                                  'default')
     factory = AdaptiveGradientDescentMaterialsFactory()
     for output_neuron in neural_network.layers[-1]:
         fit_strategy = factory.make_neuron_fit_strategy(output_neuron)
         self.assertTrue(
             isinstance(fit_strategy,
                        AdaptiveGradientDescentOutputNeuronFitStrategy))
Beispiel #6
0
 def test_pick_outputs(self):
     neural_network = mlp_network([4, 3, 2], 'tanh', 'identity')
     self.assertRaises(NotImplementedError, Network.pick_outputs, neural_network)
Beispiel #7
0
 def test_poke_inputs(self):
     neural_network = mlp_network([4, 3, 2], 'tanh', 'identity')
     data = None
     self.assertRaises(NotImplementedError, Network.poke_inputs, neural_network, data)
Beispiel #8
0
 def test_call(self):
     neural_network = mlp_network([4, 3, 2], 'tanh', 'identity')
     self.assertRaises(NotImplementedError, Network.__call__, neural_network)
Beispiel #9
0
 def test_init(self):
     neural_network = mlp_network([4, 3, 2], 'tanh', 'identity')
     self.assertTrue(isinstance(neural_network.factory, AdaptiveGradientDescentMaterialsFactory))
     self.assertTrue(isinstance(neural_network.predict_strategy, MlpNetworkPredictStrategy))
     self.assertTrue(isinstance(neural_network.fit_strategy, AdaptiveNetworkFitStrategy))
Beispiel #10
0
 def test_call(self):
     neural_network = mlp_network([4, 3, 2], 'tanh', 'identity')
     test_neuron = neural_network.layers[1][1]
     self.assertEqual(test_neuron(), test_neuron.predict_strategy.predict())
Beispiel #11
0
 def test_shape(self, shape=(40, 52, 1, 7, 4)):
     neural_network = mlp_network(list(shape), 'tanh', 'identity')
     self.assertEqual(neural_network.shape, list(shape))
Beispiel #12
0
 def test_call(self, input_size=100, shape=(4, 3, 2)):
     neural_network = mlp_network(list(shape), 'tanh', 'identity')
     input_data = np.random.rand(input_size, shape[0])
     self.assertTrue((neural_network(input_data) == neural_network.predict_strategy(input_data)).all)
Beispiel #13
0
 def test_shape(self):
     neural_network = mlp_network([4, 3, 2], 'tanh', 'identity')
     self.assertRaises(NotImplementedError, Network.shape.__get__, neural_network)
Beispiel #14
0
 def test_make_neuron_fit_strategy_neuron_in_hidden_layer(self, hidden_layer_size=20):
     neural_network = mlp_network([3, hidden_layer_size, 2], 'default', 'default')
     factory = AdaptiveGradientDescentMaterialsFactory()
     for hidden_neuron in neural_network.layers[1]:
         fit_strategy = factory.make_neuron_fit_strategy(hidden_neuron)
         self.assertTrue(isinstance(fit_strategy, AdaptiveGradientDescentHiddenNeuronFitStrategy))
Beispiel #15
0
 def test_make_neuron_fit_strategy_neuron_in_output_layer(self, output_layer_size=20):
     neural_network = mlp_network([3, 3, output_layer_size], 'default', 'default')
     factory = AdaptiveGradientDescentMaterialsFactory()
     for output_neuron in neural_network.layers[-1]:
         fit_strategy = factory.make_neuron_fit_strategy(output_neuron)
         self.assertTrue(isinstance(fit_strategy, AdaptiveGradientDescentOutputNeuronFitStrategy))