當前位置:
首頁 >
径向基(RBF)神经网络
發(fā)布時間:2024/4/11
53
豆豆
生活随笔
收集整理的這篇文章主要介紹了
径向基(RBF)神经网络
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
RBF網(wǎng)絡能夠逼近任意非線性的函數(shù)。可以處理系統(tǒng)內(nèi)難以解析的規(guī)律性,具有很好的泛化能力,并且具有較快的學
習速度。當網(wǎng)絡的一個或多個可調(diào)參數(shù)(權(quán)值或閾值)對任何一個輸出都有影響時,這樣的網(wǎng)絡稱為全局逼近網(wǎng)絡。
由于對于每次輸入,網(wǎng)絡上的每一個權(quán)值都要調(diào)整,從而導致全局逼近網(wǎng)絡的學習速度很慢,比如BP網(wǎng)絡。如果對于
輸入空間的某個局部區(qū)域只有少數(shù)幾個連接權(quán)值影響輸出,則該網(wǎng)絡稱為局部逼近網(wǎng)絡,比如RBF網(wǎng)絡。接下來重點
先介紹RBF網(wǎng)絡的原理,然后給出其實現(xiàn)。先看如下圖
? ?
?正則化的RBF網(wǎng)絡參考這里。下面是網(wǎng)上找的一個比較好的Python的RBF網(wǎng)絡實現(xiàn)。
代碼:
from scipy import * from scipy.linalg import norm, pinvfrom matplotlib import pyplot as pltclass RBF:def __init__(self, indim, numCenters, outdim):self.indim = indimself.outdim = outdimself.numCenters = numCentersself.centers = [random.uniform(-1, 1, indim) for i in xrange(numCenters)]self.beta = 8self.W = random.random((self.numCenters, self.outdim))def _basisfunc(self, c, d):assert len(d) == self.indimreturn exp(-self.beta * norm(c-d)**2)def _calcAct(self, X):# calculate activations of RBFsG = zeros((X.shape[0], self.numCenters), float)for ci, c in enumerate(self.centers):for xi, x in enumerate(X):G[xi,ci] = self._basisfunc(c, x)return Gdef train(self, X, Y):""" X: matrix of dimensions n x indim y: column vector of dimension n x 1 """# choose random center vectors from training setrnd_idx = random.permutation(X.shape[0])[:self.numCenters]self.centers = [X[i,:] for i in rnd_idx]print "center", self.centers# calculate activations of RBFsG = self._calcAct(X)print G# calculate output weights (pseudoinverse)self.W = dot(pinv(G), Y)def test(self, X):""" X: matrix of dimensions n x indim """G = self._calcAct(X)Y = dot(G, self.W)return Yif __name__ == '__main__':n = 100x = mgrid[-1:1:complex(0,n)].reshape(n, 1)# set y and add random noisey = sin(3*(x+0.5)**3 - 1)# y += random.normal(0, 0.1, y.shape)# rbf regressionrbf = RBF(1, 10, 1)rbf.train(x, y)z = rbf.test(x)# plot original dataplt.figure(figsize=(12, 8))plt.plot(x, y, 'k-')# plot learned modelplt.plot(x, z, 'r-', linewidth=2)# plot rbfsplt.plot(rbf.centers, zeros(rbf.numCenters), 'gs')for c in rbf.centers:# RF prediction linescx = arange(c-0.7, c+0.7, 0.01)cy = [rbf._basisfunc(array([cx_]), array([c])) for cx_ in cx]plt.plot(cx, cy, '-', color='gray', linewidth=0.2)plt.xlim(-1.2, 1.2)plt.show()
最后提供Github上的一個C++實現(xiàn)的RBF,供日后參考。
總結(jié)
以上是生活随笔為你收集整理的径向基(RBF)神经网络的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 三种重要哈希介绍
- 下一篇: SlopOne推荐算法