MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / forward_propagation

Function forward_propagation

neural_network/simple_neural_network.py:28–53  ·  view source on GitHub ↗

Return the value found after the forward propagation training. >>> res = forward_propagation(32, 450_000) # Was 10_000_000 >>> res > 31 and res < 33 True >>> res = forward_propagation(32, 1000) >>> res > 31 and res < 33 False

(expected: int, number_propagations: int)

Source from the content-addressed store, hash-verified

26
27
28def forward_propagation(expected: int, number_propagations: int) -> float:
29 """Return the value found after the forward propagation training.
30
31 >>> res = forward_propagation(32, 450_000) # Was 10_000_000
32 >>> res > 31 and res < 33
33 True
34
35 >>> res = forward_propagation(32, 1000)
36 >>> res > 31 and res < 33
37 False
38 """
39
40 # Random weight
41 weight = float(2 * (random.randint(1, 100)) - 1)
42
43 for _ in range(number_propagations):
44 # Forward propagation
45 layer_1 = sigmoid_function(INITIAL_VALUE * weight)
46 # How much did we miss?
47 layer_1_error = (expected / 100) - layer_1
48 # Error delta
49 layer_1_delta = layer_1_error * sigmoid_function(layer_1, True)
50 # Update weight
51 weight += INITIAL_VALUE * layer_1_delta
52
53 return layer_1 * 100
54
55
56if __name__ == "__main__":

Callers 1

Calls 1

sigmoid_functionFunction · 0.70

Tested by

no test coverage detected