Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion NN/nnapplygrads.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
dW = nn.dW{i};
end

dW = nn.learningRate * dW;
% to apply different learning rates to each layer
if isempty(nn.learningRatePerLayer)
dW = nn.learningRate * dW;
else
dW = nn.learningRatePerLayer(i) * dW;
end

if(nn.momentum>0)
nn.vW{i} = nn.momentum*nn.vW{i} + dW;
Expand Down
1 change: 1 addition & 0 deletions NN/nnsetup.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

nn.activation_function = 'tanh_opt'; % Activation functions of hidden layers: 'sigm' (sigmoid) or 'tanh_opt' (optimal tanh).
nn.learningRate = 2; % learning rate Note: typically needs to be lower when using 'sigm' activation function and non-normalized inputs.
nn.learningRatePerLayer = []; % learning rate per layer - for transfer learning pre-training and fine-tuning different parts of the network (should be of length nn.n - 1)
nn.momentum = 0.5; % Momentum
nn.scaling_learningRate = 1; % Scaling factor for the learning rate (each epoch)
nn.weightPenaltyL2 = 0; % L2 regularization
Expand Down
11 changes: 11 additions & 0 deletions NN/nntrain.m
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,17 @@

disp(['epoch ' num2str(i) '/' num2str(opts.numepochs) '. Took ' num2str(t) ' seconds' '. Mini-batch mean squared error on training set is ' num2str(mean(L((n-numbatches):(n-1)))) str_perf]);
nn.learningRate = nn.learningRate * nn.scaling_learningRate;
if ~isempty(nn.learningRatePerLayer)
nn.learningRatePerLayer = nn.learningRatePerLayer * nn.scaling_learningRate;
end

if isfield(opts,'tol')
if opts.validation == 1 && loss.val.e(end)<opts.tol
break;
elseif loss.train.e(end)<opts.tol
break;
end
end
end
end