%load data from text file and rearrange into matrix ( [X, Y, letter] )
load pattern1.txt;
letters = permute( reshape( pattern1, [12 26 13]), [1 3 2]);

%train rbm with 100 hidden units for 300 presentations of the 26 letters.
%input reshaped to avoid batching, but works fine with batching and more epochs
[rbm, output] = trainrbm(reshape(letters,[156 1 26]), 100, 300);

%can also specify learning rate, weight decay, and momentum (in that order):
%[rbm, output] = trainrbm(reshape(letters,[156 1 26]), 100, 500, .01, .0002, .9);

%plot reconstructions of noisy letters (20% of bits randomly flipped)
r = randomFlipMatrix(round(.2*156));
noisy_letters = abs(reshape(letters,[156 26]) - r);
reconstructInput(rbm, noisy_letters);

