sklearn.neural_network.BernoulliRB

class sklearn.neural_network.BernoulliRBM(n_components=256, *, learning_rate=0.1, batch_size=10, n_iter=10, verbose=0, random_state=None)

[源码]

伯努利限制玻尔兹曼机(RBM)。

具有二值化可见单位和二值化隐藏单位的限制玻尔兹曼机。参数估计使用随机最大似然(SML),也称为持久对比散度(PCD)[2]。

这个实现的时间复杂度为O(d ** 2)假定d〜n_features〜n_components。

用户指南中阅读更多内容。

参数 说明
n_components int, default=256
二值化隐藏单位数
learning_rate float, default=0.1
用于权重更新的学习率。强烈建议调优这个超参数。合理值在10 ** [0.,-3.]范围内。
batch_size int, default=10
每个小批量的样本数量。
n_iter int, default=10
训练数据集在训练期间要执行的迭代或扫描次数。
verbose int, default=0
详细程度。默认为零,表示静默模式。
random_state integer or RandomState, default=None
确定以下各项的随机数生成:

- 从可见层和隐藏层进行吉布斯(Gibbs)采样。
- 初始化组件,在拟合过程中从层中采样。
- 在对样本评分时破坏数据。

在多个函数调用之间传递一个整数以获得可重复的结果。请参阅词汇表
属性 说明
intercept_hidden_ array-like, shape (n_components,)
隐藏单位的偏差。
intercept_visible_ array-like, shape (n_features,)
可见单位的偏差。
components_ array-like, shape (n_components, n_features)
权重矩阵,可见单元数中的n_features和n_components是隐藏单元数。
h_samples_ array-like, shape (batch_size, n_components)
隐藏激活是从模型分布中采样的,其中,每个小批量的示例数中的batch_size和n_components是隐藏单元数。

参考文献

[1] Hinton, G. E., Osindero, S. and Teh, Y. A fast learning algorithm for

deep belief nets. Neural Computation 18, pp 1527-1554. https://www.cs.toronto.edu/~hinton/absps/fastnc.pdf

[2] Tieleman, T. Training Restricted Boltzmann Machines using

Approximations to the Likelihood Gradient. International Conference on Machine Learning (ICML) 2008

示例

>>> import numpy as np
>>> from sklearn.neural_network import BernoulliRBM
>>> X = np.array([[000], [011], [101], [111]])
>>> model = BernoulliRBM(n_components=2)
>>> model.fit(X)
BernoulliRBM(n_components=2)

方法

方法 说明
fit(X[, y]) 将模型拟合到数据X。
fit_transform(X[, y]) 拟合数据,然后对其进行转换。
get_params([deep]) 获取这个估计器的参数
gibbs(v) 执行一个吉布斯采样步骤。
partial_fit(X[, y]) 将模型拟合到数据X,其中应包含数据的一部分。
score_samples(X) 计算X的伪似然。
set_params(**params) 为这个估计器设置参数
transform(X) 计算隐藏层激活概率P(h = 1/v=X)
__init__(n_components=256, *, learning_rate=0.1, batch_size=10, n_iter=10, verbose=0, random_state=None)

[源码]

初始化self。详情可参阅 type(self)的帮助。

fit(X, y=None)

[源码]

将模型拟合到数据X。

参数 说明
X {array-like, sparse matrix} of shape (n_samples, n_features)
用于训练的数据。
返回值 说明
self BernoulliRBM
拟合的模型。
fit_transform(X, y=None, **fit_params)

[源码]

拟合数据,然后对其进行转换。

使用可选参数fit_params将拟合转换到X和y,并返回X的转换版本。

参数 说明
X {array-like, sparse matrix, dataframe} of shape (n_samples, n_features)
y ndarray of shape (n_samples,), default=None
目标值
**fit_params dict
其他拟合参数。
返回值 说明
X_new ndarray array of shape (n_samples, n_features_new)
转换后的数组。
get_params(deep=True)

[源码]

获取这个估计器的参数

参数 说明
deep bool, default=True
如果为True,则将返回这个估计器的参数和所包含的估计器子对象。
返回值 说明
params mapping of string to any
参数名映射到其值。
gibbs(v)

[源码]

执行一个吉布斯采样步骤。

参数 说明
v ndarray of shape (n_samples, n_features)
可见层的起始值
返回值 说明
v_new ndarray of shape (n_samples, n_features)
一个吉布斯步骤后,可见层的值。
partial_fit(X, y=None)

[源码]

将模型拟合到数据X,其中应包含数据的一部分。

参数 说明
X ndarray of shape (n_samples, n_features)
用于训练的数据
返回值 说明
self BernoulliRBM
拟合的模型
score_samples(X)

[源码]

计算X的伪似然。

参数 说明
X {array-like, sparse matrix} of shape (n_samples, n_features)
可见层的值。必须为全布尔值(不检查)。
返回值 说明
pseudo_likelihood ndarray of shape (n_samples,)
伪似然的值(似然的代理)。

这种方法是不确定的:它计算一个称为X上的自由能的量,然后计算一个随机损坏的X版本,并返回差的logistic函数的对数。

set_params(**params)

[源码]

为这个估计器设置参数

参数 说明
**params dict
估计器参数
返回值 说明
self object
估计器实例
transform(X)

[源码]

计算隐藏层激活概率P(h = 1 | v = X)。

参数 说明
X {array-like, sparse matrix} of shape (n_samples, n_features)
要转换的数据。
返回值 说明
h ndarray of shape (n_samples, n_components)
数据的潜在表示。

sklearn.neural_network.BernoulliRBM使用示例