-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJarvisTest.py
44 lines (30 loc) · 989 Bytes
/
JarvisTest.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
# -*- coding: utf-8 -*-
"""
Created on Thu Feb 18 16:26:48 2021
@author: tobia
This is the first test building the groups neural network Jarvis
"""
import numpy as np
def sigmoid(x):
return 1 / (1 + np.exp(-x))
def sigmoid_derivative(x):
return x * (1-x)
traning_inputs = np.array([[0,0,1],
[1,1,1],
[1,0,1],
[0,1,1]])
traning_outputs = np.array([[0,1,1,0]]).T
np.random.seed(1)
synaptic_weights = 2 * np.random.random((3, 1))-1
print('random starting synaptic weights')
print(synaptic_weights)
for iteration in range(200000):
input_layer = traning_inputs
outputs = sigmoid(np.dot(input_layer, synaptic_weights))
error = traning_outputs - outputs
adjustments = error * sigmoid_derivative(outputs)
synaptic_weights += np.dot(input_layer.T, adjustments)
print('synaptic weights after traning')
print(synaptic_weights)
print('outputs after training')
print(outputs)