27 lines
939 B
Matlab
27 lines
939 B
Matlab
function ret = cd1(rbm_w, visible_data)
|
|
% <rbm_w> is a matrix of size <number of hidden units> by <number of visible units>
|
|
% <visible_data> is a (possibly but not necessarily binary) matrix of size <number of visible units> by <number of data cases>
|
|
% The returned value is the gradient approximation produced by CD-1. It's of the same shape as <rbm_w>.
|
|
|
|
|
|
% This is needed for questions up to question #9
|
|
%v0 = visible_data;
|
|
%
|
|
|
|
v0 = sample_bernoulli(visible_data);
|
|
|
|
h0p = visible_state_to_hidden_probabilities(rbm_w, v0);
|
|
h0 = sample_bernoulli(h0p);
|
|
|
|
v1p = hidden_state_to_visible_probabilities(rbm_w, h0);
|
|
v1 = sample_bernoulli(v1p);
|
|
|
|
h1p = visible_state_to_hidden_probabilities(rbm_w, v1);
|
|
|
|
% h1 = sample_bernoulli(h1p); % We don't need this. But instead we could use
|
|
% probabilities.
|
|
|
|
ret = configuration_goodness_gradient(v0,h0) .- configuration_goodness_gradient(v1,h1p);
|
|
|
|
end
|