-
Notifications
You must be signed in to change notification settings - Fork 1
/
All simplified programs.py
122 lines (102 loc) · 1.97 KB
/
All simplified programs.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#normal perceptron
import numpy as np
def signum(x):
if x>0:
return 1
elif x==0:
return 0
else:
return -1
# inputs [bias=1,in1,in2]
x=np.array([[1,1],[1,-1],[-1,1],[-1,-1]])
d=np.array([1,-1,-1,-1]) #outputs
# Single Neuron
e=1
lr=1
w=np.array([0, 0])
b=0
r,c=x.shape
for k in range(e):
for i in range(r):
s=np.sum(x[i]*w)
y=signum(s+b)
if y!=d[i]:
w=w+lr*x[i]*d[i]
b=b+lr*d[i]
print(w,b)
#delta or Window Hoff rule perceptron
import numpy as np
def signum(x):
if x>0:
return 1
elif x==0:
return 0
else:
return -1
# inputs [bias=1,in1,in2]
x=np.array([[1,1],[1,-1],[-1,1],[-1,-1]])
d=np.array([1,-1,-1,-1]) #outputs
# Single Neuron
e=1
lr=1
w=np.array([0, 0])
b=0
[r,c]=x.shape
for k in range(e):
for i in range(r):
s=np.sum(x[i]*w)
y=signum(s+b)
if y!=d[i]:
w=w+lr*x[i]*(d[i]-y)
b=b+lr*(d[i]-y)
print(w,b)
#single neutron
from math import*
import numpy as np
def linear(x):
return x
def threshold(x):
if x>0:
return 1
else:
return 0
def ramp(x):
if x>1:
return 1
elif x<0:
return 0
else:
return x
def logsig(x):
return (1/(1+exp(-x)))
x=np.array([1,0,1,0])
w=np.array([0,0,1,1])
b=0
net=np.sum(x*w)
ch=int(input("Enter neuron 1. linear,2. threshold,3. ramp,4. logsigmoid"))
y=0
if ch==1:
y=linear(net+b)
elif ch==2:
y=threshold(net+b)
elif ch==3:
y=ramp(net+b)
elif ch==4:
y=logsig(net+b)
else:
print("Invalid choice of neuron")
print("out put for linear neuron",y)
#maculloch
from math import*
import numpy as np
def threshold(x):
if x>0:
return 1
else:
return 0
x=np.array([1,0,1,0])
w=np.array([0,0,1,1])
b=0
net=np.sum(x*w)
y=threshold(net+b)
print(y)