Files
jens 7b34529b24 imported RBM
git-svn-id: http://moon:8086/svn/matlab/trunk@91 801c6759-fa7c-4059-a304-17956f83a07c
2016-07-12 11:24:12 +00:00

43 lines
1002 B
Matlab

function [ cost, grad, pred_prob] = supervised_dnn_cost( theta, ei, data, labels, pred_only)
%SPNETCOSTSLAVE Slave cost function for simple phone net
% Does all the work of cost / gradient computation
% Returns cost broken into cross-entropy, weight norm, and prox reg
% components (ceCost, wCost, pCost)
%% default values
po = false;
if exist('pred_only','var')
po = pred_only;
end;
%% reshape into network
stack = params2stack(theta, ei);
numHidden = numel(ei.layer_sizes) - 1;
hAct = cell(numHidden+1, 1);
gradStack = cell(numHidden+1, 1);
%% forward prop
%%% YOUR CODE HERE %%%
%% return here if only predictions desired.
if po
cost = -1; ceCost = -1; wCost = -1; numCorrect = -1;
grad = [];
return;
end;
%% compute cost
%%% YOUR CODE HERE %%%
%% compute gradients using backpropagation
%%% YOUR CODE HERE %%%
%% compute weight penalty cost and gradient for non-bias terms
%%% YOUR CODE HERE %%%
%% reshape gradients into vector
[grad] = stack2params(gradStack);
end