-
Notifications
You must be signed in to change notification settings - Fork 0
/
mydnn.py
49 lines (37 loc) · 1 KB
/
mydnn.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
# coding=utf-8
import os, sys
import requests
import numpy as np
import matplotlib.pyplot as plt
# ----------------------------------------------------------------------------感知器及模拟加法器---------------------------------------------------------
def Perceptor(x,a,b):
y = np.dot(np.array(x),np.array(a)) + b
return int(y > 0)
def AND(x):
return Perceptor(x,[0.5,0.5],-0.6)
def OR(x):
return Perceptor(x,[0.5,0.5],-0.4)
def NAND(x):
return Perceptor(x,[-0.5,-0.5],0.6)
def XOR(x):
return AND([NAND(x),OR(x)])
def testFunc(func):
xs = np.array([[0,0],[0,1],[1,0],[1,1]])
for x in xs:
print(x,'==>',func(x))
def test1():
print('AND test:')
testFunc(AND)
print('OR test:')
testFunc(OR)
print('NAND test:')
testFunc(NAND)
print('XOR test:')
testFunc(XOR)
# ----------------------------------------------------------------------------神经网络---------------------------------------------------------
def relu(x,n=0):
return x if x>n else 0
def initModel():
data={}
return data
test1()