当前位置: 首页 > news >正文

完整教程:Deep Learning|01 RBF Network

Deep Learning|01 RBF Network

Radial Basis Function Interpolation, RBF Interpolation

Radial basis functions are a class of real-valued functions that depend solely on the radial distance between the input vector and a fixed center point. Their core characteristic is that the function value is independent of the direction of the input and only related to the distance from the input to the center point.

Let Φ(x)\Phi (x)Φ(x)is a RBF , for any input vectorx\boldsymbol{x}x, and center vectorsc\boldsymbol{c}c,we defineΦ(x)\Phi (x)Φ(x)uesd Gauss functon :

Φ(x)=e−β∥x−c∥2\Phi(\boldsymbol{x})=e^{-\beta \|\boldsymbol{x}-\boldsymbol{c}\|^2}Φ(x)=eβxc2

which β\betaβcontrol the width of Gauss functon .

Note: It is not the only way. In fact, any similar δ\deltaδfunction is available.

Radial Basis Function Interpolation, RBF Interpolation , is essentially an interpolation method that use a linear combination of radial basis functions (RBFs) to
“exactly approximate” the functionf(x)f(x)f(x)at known points.The formular is as follows:

f(x)=∑j=1nλjΦj(x)=∑j=1nλje−βj∥x−cj∥2f(x)= \sum_{j=1}^{n} \lambda_j\Phi_j (\boldsymbol{x})= \sum_{j=1}^{n} \lambda_je^{-\beta_j \|\boldsymbol{x}-\boldsymbol{c}_j\|^2}f(x)=j=1nλjΦj(x)=j=1nλjeβjxcj2

This defination is likeMaximum Likelihood Estimation。This likely unrigorous?No! Brommehead and Lowe had given the proof of
RBF
. Magically!

RBF Network

Radial Basis Function Network (RBF Network) is a type of feedforward neural network with a single hidden layer. Its core feature is that it adopts “radial basis functions (RBFs)” as the activation functions of the hidden layer, and it is specifically used to solve supervised learning tasks such as nonlinear regression, pattern classification, and function approximation. Its key advantages lie in “strong local approximation capability, fast training speed, and stable generalization performance”, making it widely applied in small and medium-sized nonlinear problems.

RBF Network

RBF Network=∑j=1nλjΦj(x)\text{RBF Network}=\sum_{j=1}^{n} \lambda_j\Phi_j (\boldsymbol{x})RBF Network=j=1nλjΦj(x)

How to build a simple RBF network?

Aassuming we have series data{(x,y)}i=1n\{\left(\boldsymbol{x},y\right)\}_{i=1}^n{(x,y)}i=1n, the training objective of an RBF network is to determine three types of parameters: hidden layer centers{ci}inc\{\boldsymbol{c}_i\}_{i}^{n_c}{ci}inc, hidden layer widths{σi}inσ\{\sigma_i\}_{i}^{n_\sigma}{σi}inσ, and output layer weights{wi}inw\{w_i\}_{i}^{n_w}{wi}inw.

Step1: load data and K-means clustering

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.cluster import KMeans
from sklearn.preprocessing import StandardScaler
import os
def preprocess_data(data):
data = data.dropna()
if data.dtypes.iloc[-1] == 'object' or len(data.iloc[:, -1].unique()) < 10:
X = data.iloc[:, :-1].values
has_labels = True
labels = data.iloc[:, -1].values
else:
X = data.values
has_labels = False
labels = None
scaler = StandardScaler()
X_scaled = scaler.fit_transform(X)
return X_scaled, has_labels, labels
def perform_kmeans(X, n_clusters=neural_numbers, random_state=42):
kmeans = KMeans(n_clusters=n_clusters, random_state=random_state)
clusters = kmeans.fit_predict(X)
centroids = kmeans.cluster_centers_
return clusters, centroids
def visualize_results(X, original_labels, clusters, centroids, has_original_labels=False):
fig, axes = plt.subplots(1, 2, figsize=(16, 8))
has_original_labels and original_labels is not None:
scatter1 = axes[0].scatter(X[:, 0], X[:, 1], c=original_labels, cmap='viridis', alpha=0.7)
axes[0].set_title('oringal data distrbution', fontsize=14)
plt.colorbar(scatter1, ax=axes[0], label='oringal lable')
scatter2 = axes[1].scatter(X[:, 0], X[:, 1], c=clusters, cmap='viridis', alpha=0.7)
axes[1].scatter(centroids[:, 0], centroids[:, 1], s=300, c='red', marker='X', label='clustering center')
axes[1].set_title('result of clustering', fontsize=14)
plt.colorbar(scatter2, ax=axes[1], label='clustering label')
axes[1].legend()
for ax in axes:
ax.set_xlabel('feature_1(标准化)', fontsize=12)
ax.set_ylabel('feature_2(标准化)', fontsize=12)
ax.grid(True, linestyle='--', alpha=0.6)
plt.tight_layout()
if not os.path.exists('results'):
os.makedirs('results')
plt.savefig('results/clustering_comparison.png', dpi=300, bbox_inches='tight')
print("figures save to : results/clustering_comparison.png")
plt.show()
def main(file_path, n_clusters=3):
data = load_data(file_path)
if data is None:
return
X, has_labels, original_labels = preprocess_data(data)
if X.shape[1] > 2:
from sklearn.decomposition import PCA
print(f"data dimension is {X.shape[1]},use PCA to 2-dimension to showase")
pca = PCA(n_components=2)
X = pca.fit_transform(X)
clusters, centroids = perform_kmeans(X, n_clusters)
visualize_results(X, original_labels, clusters, centroids, has_labels)
if __name__ == "__main__":
datapath="data.csv"
neural_numbers=3
data = pd.read_csv(file_path) # Must .csv
main(datapath, neural_numbers)

**Step2: Calculate the hidden layer widths **$

The widths do not require training and are usually calculated automatically based on the distribution of the centers.Most commonly used,adaptive calculation based on “nearest neighbor center distance”

For each centercj\boldsymbol{c}_jcj, first find another centerck\boldsymbol{c}_kckthat is closest to it (k≠jk \neq jk=j), and denote this distance asdjd_jdj:

dj=min⁡k=1,2,...,nk≠j∥cj−ck∥d_j = \min_{\substack{k=1,2,...,n \\ k \neq j}} \|\boldsymbol{c}_j - \boldsymbol{c}_k\|dj=k=1,2,...,nk=jmincjck

(wheredjd_jdjrepresents the Euclidean distance from thejjj-th center to its nearest neighboring center)

Then, defineβj\beta_jβjas a quantity related todjd_jdjto ensure that the “effective range” of the RBF matches the distance between adjacent centers:

βj=12⋅dj2\beta_j = \frac{1}{2 \cdot d_j^2}βj=2dj21

Step3: Solve for the output layer weights

After the centers{ci}\{\boldsymbol{c}_i\}{ci}and widths{σi}\{\sigma_i\}{σi}are determined, the hidden layer outputhi(x)h_i(\boldsymbol{x})hi(x)can be regarded as a “fixed nonlinear feature”. At this point, the solution for the output layer weights is transformed into alinear regression problem(gradient descent is not required, and the least squares method can be used directly).

Suppose the training set containsNNNsamples(xk,yk)(\boldsymbol{x}_k, y_k)(xk,yk)(whereyky_kykis the true label), and the network output is$y^k=∑i=1mwihi(xk)+w0\hat{y}_k = \sum_{i=1}^m w_i h_i(\boldsymbol{x}_k) + w_0y^k=i=1mwihi(xk)+w0. By minimizing the “squared error between the predicted value and the true value”:

L=∑k=1N(y^k−yk)2\mathcal{L} = \sum_{k=1}^N (\hat{y}_k - y_k)^2L=k=1N(y^kyk)2

This can be converted into the matrix equationH⋅w=y\mathbf{H} \cdot \boldsymbol{w} = \boldsymbol{y}Hw=y), where:

  • H\mathbf{H}H is an N×(m+1)N \times (m+1)N×(m+1)“feature matrix”, and each row is[1,h1(xk),h2(xk),...,hm(xk)][1, h_1(\boldsymbol{x}_k), h_2(\boldsymbol{x}_k), ..., h_m(\boldsymbol{x}_k)][1,h1(xk),h2(xk),...,hm(xk)](the 1 corresponds to the bias termw0w_0w0);
  • w=[w0,w1,...,wm]T\boldsymbol{w} = [w_0, w_1, ..., w_m]^Tw=[w0,w1,...,wm]Tis the weight vector to be solved;
  • y=[y1,y2,...,yN]T\boldsymbol{y} = [y_1, y_2, ..., y_N]^Ty=[y1,y2,...,yN]Tis the true label vector.

The weights are solved using thepseudoinverse matrix(to avoid the problem of matrix singularity):

w=(HTH)−1HTy\boldsymbol{w} = (\mathbf{H}^T \mathbf{H})^{-1} \mathbf{H}^T \boldsymbol{y}w=(HTH)1HTy

This step is the key to the fast training of the RBF network — linear problems can be solved directly without repeated iterations.

Later, we will construct a Radial Basis Function (RBF) network to accomplish the prediction task.
http://www.jsqmd.com/news/26431/

相关文章:

  • 个人微信号二次开发api协议,微信个人号开发API接口
  • HTML常规 - ng
  • 2025年知名的铁碳填料厂家最新TOP实力排行
  • 2025年热门的特种纸印刷包装厂家推荐及选择参考
  • 2025年口碑好的定制托辊厂家最新实力排行
  • W3
  • 2025年知名的冲击波驱鸟器高评价厂家推荐榜
  • 2025年热门的EPDM泡棉厂家最新用户好评榜
  • 专家并行和其他并行策略对比
  • 2025年口碑好的活塞式制冷压缩机厂家最新权威推荐排行榜
  • 为什么我的应用会卡顿?垃圾回收中的STW难题与破解之道
  • 一份简短的LaTeX相关术语的介绍 - Invinc
  • 2025年热门的坐骑式割草机厂家推荐及选购指南
  • 2025年口碑好的小型/微型微动开关优质厂家推荐榜单
  • 【日记】出差就是没时间写日记呢(826 字)
  • 2025年口碑好的染色金丝绒TOP实力厂家推荐榜
  • 2025年质量好的Q235钢材TOP品牌厂家排行榜
  • ppt导出高清图片pdf的方法!
  • 完整教程:提升准确率的处理
  • 2025年热门的锌钢阳台栏杆最新TOP厂家排名
  • 在线代办事项 | AI 设计
  • 2025年质量好的RJ45网口插座TOP实力厂家推荐榜
  • 2025年热门的不锈钢鹦鹉笼用户口碑最好的厂家榜
  • 第一章——了解prompt以及一些基础技巧方法 - 实践
  • 广州地铁App绿色无广告版本可刷珠三角城际
  • STM32与7038芯片通过SPI通信读取寄存器数据
  • 色彩空间基础 —— 颜色模式RGB、YUV
  • 2025年质量好的铁氟龙喷涂厂家选购指南与推荐
  • 2025年老年急救病房及CPR实训室企业权威推荐榜单:基础护理实训/OT康复实训室 /PT康复实训室源头厂家精选
  • 2025年跨境电商服务商权威推荐榜单:海外跨境电商/跨境电商培训/跨境电商系统服务商精选