资源简介
RBM的python代码实现,里面可以改隐含层,和输入层的个数,有训练权重
代码片段和文件信息
from __future__ import print_function
import numpy as np
import openpyxl
class RBM:
def __init__(self num_visible num_hidden):
self.num_hidden = num_hidden
self.num_visible = num_visible
self.debug_print = True
np_rng = np.random.RandomState(1234)
self.weights = np.asarray(np_rng.uniform(
low=-0.1 * np.sqrt(261. / (num_hidden + num_visible))
high=0.1 * np.sqrt(261. / (num_hidden + num_visible))
size=(num_visible num_hidden)))
self.weights = np.insert(self.weights 0 0 axis = 0)
self.weights = np.insert(self.weights 0 0 axis = 1)
def train(self data max_epochs = 1000 learning_rate = 0.1):
“““
Train the machine.
Parameters
----------
data: A matrix where each row is a training example consisting of the
states of visible units.
评论
共有 条评论