import numpy as np import matplotlib.pylab as plt def diff(f,x0,x1,select=1): # select = -1 is x0 derivation, select =1 is x1 derivation h=1e-4 x0=x0*select*-1 x1=x1*(select+1) y=f((x0+x1)+h)-f((x0+x1)-h) return y/(2*h) def fuction(x): return x**2 print(diff(fuction,3,4,-1))几句代码之实...

阅读全文

就是那么一丢丢事

阅读全文

import numpy as np def mean_square_error(input,t): return 0.5*np.sum((input-t)**2) def cross_error(input,t): delta=1e-7 return -np.sum(t*np.log(input)+delta) y=np.array([0.1,0.005,0.1,0.0,0.05,0.1,0.0,0.6,0.0,0.0]) t=np.array([0,0,1,0,0,0,0,0,0,0]) print(mean_square_error(y,...

阅读全文

import numpy as np def Initilize_Net(): nets={} nets['w1']=np.array([[0.1,0.3,0.5],[0.2,0.4,0.6]]) nets['w2']=np.array([[0.1,0.4],[0.2,0.5],[0.3,0.6]]) nets['w3']=np.array([[0.1,0.3],[0.2,0.4]]) nets['b1']=np.array([0.1,0.2,0.3]) nets['b2']=np.array([0.1,0.2]) nets['b3']=np.array([0.1,0.2]) return nets def sigmodis(x): return 1/(1+np.exp(-x)) def softmax(a): c=np.max(a) exp_a=np.exp(a-c) sum_exp=np.sum(exp_a) y=exp_a/sum_exp return y def forword(nets,x): w1,w2,w3=nets['w1'],nets['w2'],nets['w3'] b1,b2,b3=nets['b1'],nets['b2'],nets['b3'] a1=np.dot(x,w1)+b1 z1=sigmodis(a1) a2=np.dot(z1,w2)+b2 z2=sigmodis(a2) a3=np.dot(z2,w3)+b3 y=sigmodis(a3) return y Nets=Initilize_Net() x=np.array([1.0,0.5]) y=forword(Nets,x) print(y) print(softmax(...

阅读全文

FuctionStep-to-step Fuction1,0,1,0Sigmoid FuctionH(x)=1/(1+exp(-x))PictureStep-to-step Fuction Sigmoid FuctionCodeStep-to-step Fuctionimport numpy as np import matplotlib.pylab as plt def step_fuction(x): # x_=[] # for i in x: # if(i>0): # x_.append(1) # else: # x_.append(0) # return x_ return np.array(x>0,dtype=np.int) x=np.arange(-5,5,0.1) # formation -5~5 andArithmetic sequence 0.1 y=step_fuction(x) print(y) plt.plot(x,y) plt.ylim(-0.1,1.1) plt.show() Sigmoid Fuction Fuctionimport numpy as np import matplotlib.pylab as plt def step_fuction(x): return 1/(1+np.exp(-x)) x=np.arange(-5,5,0.1) # formation -5~5 andArithmetic sequence 0.1 y=step_fuction(x) print(y) plt.plot(x,y) plt.ylim(-0.1,1.1) plt.sho...

阅读全文

回到顶部