09.05.2023 Views

pdfcoffee

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Unsupervised Learning

#Find the error rate

err = tf.reduce_mean(tf.square(batch - v1))

print ('Epoch: %d' % epoch,'reconstruction error: %f' % err)

loss.append(err)

return loss

Now that our class is ready, we instantiate an object of RBM and train it on the MNIST

dataset:

(train_data, _), (test_data, _) = tf.keras.datasets.mnist.load_data()

train_data = train_data/np.float32(255)

train_data = np.reshape(train_data, (train_data.shape[0], 784))

test_data = test_data/np.float32(255)

test_data = np.reshape(test_data, (test_data.shape[0], 784))

#Size of inputs is the number of inputs in the training set

input_size = train_data.shape[1]

rbm = RBM(input_size, 200)

err = rbm.train(train_data,50)

In the following code, you can see the learning curve of our RBM:

plt.plot(err)

plt.xlabel('epochs')

plt.ylabel('cost')

Figure 8: Learning curve for the RBM model

[ 396 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!