single.rbm: Train a single layer RBM

Description Usage Arguments Value Examples

View source: R/rbm.R

Description

Train a single layer RBM

Usage

1
2
single.rbm(hidden, data, learning_rate = 0.1, epochs = 1000,
  batch_size = 100, momentum = 0.9, verbose = T, custom_verbose = "")

Arguments

hidden

number of units in the hidden layer

data

matrix with training data

learning_rate

a numeric value spacifying the learning rate

epochs

the number of iterations per batch

batch_size

during one epoch a single batch will be trained. This number must be divisible by the number of training items

momentum

a numeric value spacifying the momentum

verbose

logical value for showing the current status in the console

Value

RBM object

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Data availible at https://www.samverkoelen.com/data
data <- as.matrix(read.csv('mnist_sample.csv'));

#train the single RBM
model = single.rbm(hidden = 30, data=data, learning_rate=.09, epochs=1000, batch_size=100, momentum=0.9)

par(mfrow=c(1,2))
id <- 57

#Original
original <- matrix(data[ ,id], byrow = T, ncol = 16)
original <- t(original[16:1, 1:16]) #correct orientation
image(original, col = grey(seq(0, 1, 0.001)), main = 'Original')

#visible to hidden
features <- up.rbm(model, data)

#hidden back to visible
reconstructions <- down.rbm(model, features)

#Reconstruction
reconstruction <- matrix(reconstructions[id, ], byrow = T, ncol = 16)
reconstruction <- t(reconstruction[16:1, 1:16]) #correct orientation
image(reconstruction, col = grey(seq(0, 1, 0.001)), main = 'Reconstruction')

sdverkoelen/RBM documentation built on May 29, 2019, 4:23 p.m.