In [1]:
library(rrbm);
In [2]:
# mnist <- readRDS("../datasets/mnist.rds");
data(mnist)
In [3]:
training_x <- mnist$train$x / 255;
training_y <- mnist$train$y;
testing_x <- mnist$test$x / 255;
testing_y <- mnist$test$y;
Let's reduce the dataset size for this example
In [4]:
training_x <- training_x[1:1000,, drop=FALSE];
training_y <- training_y[1:1000, drop=FALSE];
testing_x <- testing_x[1:1000,, drop=FALSE];
testing_y <- testing_y[1:1000, drop=FALSE];
In [5]:
rbm_mnist <- train.rbm(n_hidden = 30,
dataset = training_x,
learning_rate = 1e-3,
training_epochs = 10,
batch_size = 10,
momentum = 0.5
);
There are 3 methods: predict.rbm, forward.rbm and backward.rbm
In [6]:
result <- predict(rbm_mnist, training_x);
str(result);
In [7]:
act1 <- forward.rbm(rbm_mnist, training_x);
str(act1);
In [8]:
recons1 <- backward.rbm(rbm_mnist, act1);
str(recons1);
You can pass a trained RBM as initial values for a new RBM. The properties of the RBM must match with the RBM passed as init_rbm. The function returns a new updated copy of the old RBM
In [9]:
rbm_mnist_update <- train.rbm(n_hidden = 30,
dataset = training_x,
learning_rate = 1e-3,
training_epochs = 10,
batch_size = 10,
momentum = 0.5,
init_rbm = rbm_mnist
);
In [10]:
rm (list = ls());
In [11]:
setwd("..");
source("./rbm.R");
setwd("./notebooks");
In [12]:
# mnist <- readRDS("../datasets/mnist.rds");
data(mnist)
In [13]:
training_x <- mnist$train$x / 255;
training_y <- mnist$train$y;
testing_x <- mnist$test$x / 255;
testing_y <- mnist$test$y;
In [14]:
training_x <- training_x[1:1000,, drop=FALSE];
training_y <- training_y[1:1000, drop=FALSE];
testing_x <- testing_x[1:1000,, drop=FALSE];
testing_y <- testing_y[1:1000, drop=FALSE];
In [15]:
rbm_mnist <- train_rbm(n_hidden = 30,
dataset = training_x,
learning_rate = 1e-3,
training_epochs = 10,
batch_size = 10,
momentum = 0.5
);
There are 3 methods: predict_rbm, forward_rbm and backward_rbm
In [16]:
result <- predict_rbm(rbm_mnist, training_x);
str(result);
In [17]:
act1 <- forward_rbm(rbm_mnist, training_x);
str(act1);
In [18]:
recons1 <- backward_rbm(rbm_mnist, act1);
str(recons1);