diff --git a/docs/RBM.md b/docs/RBM.md index e9e7deb364..722ea270b8 100644 --- a/docs/RBM.md +++ b/docs/RBM.md @@ -42,3 +42,40 @@ - 推荐系统 - 协同过滤 - 深度信念网络的基础组件 +- +## 代码示例 + +使用 PyTorch 实现简单的 RBM: + +```python +import torch +import torch.nn as nn + +class RBM(nn.Module): + """受限玻尔兹曼机""" + def __init__(self, visible_dim, hidden_dim): + super(RBM, self).__init__() + self.W = nn.Parameter(torch.randn(hidden_dim, visible_dim) * 0.01) + self.b_v = nn.Parameter(torch.zeros(visible_dim)) + self.b_h = nn.Parameter(torch.zeros(hidden_dim)) + + def sample_hidden(self, v): + """从可见层采样隐藏层""" + p_h = torch.sigmoid(torch.matmul(v, self.W.t()) + self.b_h) + return p_h, torch.bernoulli(p_h) + + def sample_visible(self, h): + """从隐藏层采样可见层""" + p_v = torch.sigmoid(torch.matmul(h, self.W) + self.b_v) + return p_v, torch.bernoulli(p_v) +``` + +## 运行环境 + +- Python 3.7+ +- PyTorch 1.8+ + +## 参考资料 + +- [PyTorch 官方文档](https://pytorch.org/docs/stable/index.html) +- [深度信念网络介绍](https://www.cs.toronto.edu/~hinton/absps/fastnc.pdf) diff --git a/docs/gaussian_mixture.md b/docs/gaussian_mixture.md index 4f2ea7cbce..5bc0e45fb0 100644 --- a/docs/gaussian_mixture.md +++ b/docs/gaussian_mixture.md @@ -44,3 +44,34 @@ - 异常检测 - 图像分割 - 语音识别 +- +## 数学公式 + +GMM 的概率密度函数为: + +`p(x) = Σ π_k * N(x | μ_k, Σ_k)` + +其中: +- K 为高斯成分数量 +- π_k 为第 k 个成分的混合权重,满足 Σπ_k = 1 +- N(x | μ_k, Σ_k) 为第 k 个高斯分布 + +## 代码示例 + +使用 scikit-learn 拟合高斯混合模型: + +```python +from sklearn.mixture import GaussianMixture +import numpy as np + +# 生成示例数据 +X = np.random.randn(300, 2) + +# 创建并训练模型 +gmm = GaussianMixture(n_components=3, random_state=0) +gmm.fit(X) + +# 预测类别 +labels = gmm.predict(X) +print("各成分权重:", gmm.weights_) +``` diff --git a/ignore_users.json b/ignore_users.json index ed695fe839..584595373e 100644 --- a/ignore_users.json +++ b/ignore_users.json @@ -1,5 +1,8 @@ [ - "Haidong Wang", - "donghaiwang", - "whd@hutb.edu.cn" -] \ No newline at end of file + { + "name": "Haidong Wang", + "github": "donghaiwang", + "email": "whd@hutb.edu.cn", + "role": "author" + } +]