% Version 1.000
%
% Code provided by Ruslan Salakhutdinov and Geoff Hinton
%
% Permission is granted for anyone to copy, use, modify, or distribute this
% program and accompanying programs and documents for any purpose, provided
% this copyright notice is retained and prominently displayed, along with
% a note saying that the original programs are available from our
% web page.
% The programs and documents are distributed without any warranty, express or
% implied. As the programs were written for research purposes only, they have
% not been tested to the degree that would be advisable in any important
% application. All use of these programs is entirely at the user's own risk.
function [f, df] = CG_CLASSIFY_INIT(VV,Dim,w3probs,target); % 510 1, 2 1, 1000 51, 1000 10
l1 = Dim(1); % 50
l2 = Dim(2); % 10
N = size(w3probs,1); % 1000
% Do decomversion.
w_class = reshape(VV,l1+1,l2); % 51 10
w3probs = [w3probs ones(N,1)]; % 1000 51
targetout = exp(w3probs*w_class); % 1000 51 * 51 10 = 1000 10
targetout = targetout./repmat(sum(targetout,2),1,10); % repmat((1000 1),1,10) normalize
%
f = -sum(sum( target(:,1:end).*log(targetout))) ; % cross enthropy
IO = (targetout-target(:,1:end)); % 1000 10
Ix_class=IO;
dw_class = w3probs'*Ix_class; % 1000 51' * 1000 10 = 51 10
df = [dw_class(:)']'; % 510 1
%{
debug> a=[1,2,3;4,5,6]
a =
1 2 3
4 5 6
debug> sum(a,2)
ans =
6
15
debug> repmat(sum(a,2),1,10)
ans =
6 6 6 6 6 6 6 6 6 6
15 15 15 15 15 15 15 15 15 15
%}