-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathformulae.py
44 lines (28 loc) · 1.07 KB
/
formulae.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from numpy import exp, random
from math import atan, sin, cos
import parameters
def sigmoid(x):
return 1 / (1 + exp(-x))
def sigmoid_derivative(x):
return x * (1 - x)
def seed_random_number_generator():
random.seed(1)
def random_weight():
return 2 * random.random() - 1
def get_synapse_colour(weight):
if weight > 0:
return 0, 1, 0
else:
return 1, 0, 0
def adjust_line_to_perimeter_of_circle(x1, x2, y1, y2):
angle = atan((x2 - x1) / float(y2 - y1))
x_adjustment = parameters.neuron_radius * sin(angle)
y_adjustment = parameters.neuron_radius * cos(angle)
return x1 - x_adjustment, x2 + x_adjustment, y1 - y_adjustment, y2 + y_adjustment
def layer_left_margin(number_of_neurons):
return parameters.left_margin + parameters.horizontal_distance_between_neurons * (parameters.number_of_neurons_in_widest_layer - number_of_neurons) / 2
def calculate_average_error(cumulative_error, number_of_examples):
if cumulative_error:
return round(cumulative_error * 100 / number_of_examples, 2)
else:
return None