本文整理汇总了Python中rbm.RBM.compute_cost方法的典型用法代码示例。如果您正苦于以下问题:Python RBM.compute_cost方法的具体用法?Python RBM.compute_cost怎么用?Python RBM.compute_cost使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rbm.RBM
的用法示例。
在下文中一共展示了RBM.compute_cost方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: RBM
# 需要导入模块: from rbm import RBM [as 别名]
# 或者: from rbm.RBM import compute_cost [as 别名]
import matplotlib.pyplot as plt
import numpy as np
import PreprocessGenerative as i
inputData = i.importData()
rbm1 = RBM(inputData[0].shape[0], 900, ['rbmw1', 'rbvb1', 'rbmhb1'], 0.3)
epoch = 1
# Train RBM
print('rbm')
for g in range(epoch):
for it in range(len(inputData)):
trX = inputData[it][np.newaxis]
rbm1.partial_fit(trX)
print(rbm1.compute_cost(trX))
print(rbm1.compute_cost(trX))
rbm1.save_weights('./rbmw1.chp')
print("Training Complete")
示例2: RBM
# 需要导入模块: from rbm import RBM [as 别名]
# 或者: from rbm.RBM import compute_cost [as 别名]
rbm1 = RBM(inputData[0].shape[0], 900, ['rbmw1', 'rbvb1', 'rbmhb1'], 0.3)
rbm2 = RBM(900, 500, ['rbmw2', 'rbvb2', 'rbmhb2'], 0.3)
rbm3 = RBM(500, 250, ['rbmw3', 'rbvb3', 'rbmhb3'], 0.3)
rbm4 = RBM(250, 2, ['rbmw4', 'rbvb4', 'rbmhb4'], 0.3)
epoch = 1
# Train First RBM
print('first rbm')
for g in range(epoch):
for it in range(len(inputData)):
trX = inputData[it][np.newaxis]
rbm1.partial_fit(trX)
print(rbm1.compute_cost(trX))
print(rbm1.compute_cost(trX))
#show_image("1rbm.jpg", rbm1.n_w, (28, 28), (30, 30))
rbm1.save_weights('./rbmw1.chp')
# Train Second RBM2
print('second rbm')
for g in range(epoch):
for it in range(len(inputData)):
trX = inputData[it][np.newaxis]
# Transform features with first rbm for second rbm
trX = rbm1.transform(trX)
rbm2.partial_fit(trX)
print(rbm2.compute_cost(trX))
print(rbm2.compute_cost(trX))
示例3: AutoEncoder
# 需要导入模块: from rbm import RBM [as 别名]
# 或者: from rbm.RBM import compute_cost [as 别名]
# Autoencoder
autoencoder = AutoEncoder(784, [900, 500, 250, 2], [['rbmw1', 'rbmhb1'],
['rbmw2', 'rbmhb2'],
['rbmw3', 'rbmhb3'],
['rbmw4', 'rbmhb4']], tied_weights=False)
iterations = len(trX) / FLAGS.batchsize
# Train First RBM
print('first rbm')
for i in range(FLAGS.epochs):
for j in range(iterations):
batch_xs, batch_ys = mnist.train.next_batch(FLAGS.batchsize)
rbmobject1.partial_fit(batch_xs)
print(rbmobject1.compute_cost(trX))
show_image("out/1rbm.jpg", rbmobject1.n_w, (28, 28), (30, 30))
rbmobject1.save_weights('./out/rbmw1.chp')
# Train Second RBM2
print('second rbm')
for i in range(FLAGS.epochs):
for j in range(iterations):
batch_xs, batch_ys = mnist.train.next_batch(FLAGS.batchsize)
# Transform features with first rbm for second rbm
batch_xs = rbmobject1.transform(batch_xs)
rbmobject2.partial_fit(batch_xs)
print(rbmobject2.compute_cost(rbmobject1.transform(trX)))
show_image("out/2rbm.jpg", rbmobject2.n_w, (30, 30), (25, 20))
rbmobject2.save_weights('./out/rbmw2.chp')