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)
| 26 | |
| 27 | |
| 28 | def 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 | |
| 56 | if __name__ == "__main__": |
no test coverage detected