This is a static copy of a profile report

Home

Function details for newtonThis is a static copy of a profile report

Home

newton (Calls: 1, Time: 2204.774 s)
Generated 19-Jun-2021 04:39:11 using performance time.
function in file /nfs/inm_phd/07/d07944009/2021/0618-proj6/simpleNN/MATLAB/opt/newton.m
Copy to new window for comparing multiple runs

Parents (calling functions)

Function NameFunction TypeCalls
trainfunction1
Lines where the most time was spent

Line NumberCodeCallsTotal Time% TimeTime Plot
36
[net, f, grad] = fungrad_minib...
5933.018 s42.3%
18
[x, CGiter, gs, sGs] = CG(prob...
5656.868 s29.8%
28
[~, f, ~] = fungrad_minibatch(...
5421.656 s19.1%
3
[net, f, grad] = fungrad_minib...
1193.105 s8.8%
56
fprintf('total_#CG: %d\n', tot...
10.079 s0.0%
All other lines  0.049 s0.0%
Totals  2204.774 s100% 
Children (called functions)

Function NameFunction TypeCallsTotal Time% TimeTime Plot
fungrad_minibatchfunction111547.467 s70.2%
CGfunction5656.774 s29.8%
newton>update_weightssubfunction50.018 s0.0%
newton>assign_inst_idxsubfunction10.007 s0.0%
newton>calc_gnormsubfunction50.005 s0.0%
newton>update_lambdasubfunction50.003 s0.0%
Self time (built-ins, overhead, etc.)  0.501 s0.0%
Totals  2204.774 s100% 
Code Analyzer results
No Code Analyzer messages.
Coverage results
Show coverage for parent directory
Total lines in function56
Non-code lines (comments, blank lines)13
Code lines (lines that can run)43
Code lines that did run32
Code lines that did not run11
Coverage (did run/can run)74.42 %
Function listing
time 
Calls 
 line
   1 
function best_model = newton(prob, prob_v, param, model, net)
   2 

 193.105 
      1 
   3
[net, f, grad] = fungrad_minibatch(prob, param, model, net, 'fungrad'); 
< 0.001 
      1 
   4
fprintf('initial f: %g\n', f); 
   5 

< 0.001 
      1 
   6
best_model = model; 
< 0.001 
      1 
   7
if ~isempty(fieldnames(prob_v)) 
   8 
	best_val_acc = 0.0;
< 0.001 
      1 
   9
end 
  10 

< 0.001 
      1 
  11
total_CG = 0; 
  12 

< 0.001 
      1 
  13
for k = 1 : param.iter_max 
  0.002 
      5 
  14
	if mod(k, ceil(prob.l/param.GNsize)) == 1 || (prob.l == param.GNsize) 
  0.007 
      1 
  15
		batch_idx = assign_inst_idx(param.GNsize, prob.l); 
< 0.001 
      5 
  16
	end 
< 0.001 
      5 
  17
	current_batch = mod(k-1, ceil(prob.l/param.GNsize)) + 1; 
 656.868 
      5 
  18
	[x, CGiter, gs, sGs] = CG(prob.data(:, batch_idx{current_batch}), param, model, net, grad); 
< 0.001 
      5 
  19
	total_CG = total_CG + CGiter; 
  20 

  21 
	% line search
< 0.001 
      5 
  22
	fold = f; 
< 0.001 
      5 
  23
	alpha = 1; 
< 0.001 
      5 
  24
	while 1 
  0.019 
      5 
  25
		model = update_weights(model, alpha, x); 
< 0.001 
      5 
  26
		prered = alpha*gs + 0.5*(alpha^2)*sGs; 
  27 

 421.656 
      5 
  28
		[~, f, ~] = fungrad_minibatch(prob, param, model, net, 'funonly'); 
< 0.001 
      5 
  29
		actred = f - fold; 
< 0.001 
      5 
  30
		if (actred <= param.eta*alpha*gs) 
< 0.001 
      5 
  31
			break; 
  32 
		end
  33 
		alpha = alpha * 0.5;
  34 
	end
  0.004 
      5 
  35
	param = update_lambda(param, actred, prered); 
 933.018 
      5 
  36
	[net, f, grad] = fungrad_minibatch(prob, param, model, net, 'fungrad'); 
  37 

  38 
	% gradient norm
  0.008 
      5 
  39
	gnorm = calc_gnorm(grad, model.L); 
  40 

< 0.001 
      5 
  41
	if ~isempty(fieldnames(prob_v)) 
  42 
		% update best_model by val_acc
  43 
		val_results = predict(prob_v, param, model, net);
  44 
		val_acc = cal_accuracy(val_results, prob_v.y);
  45 
		if val_acc > best_val_acc
  46 
			best_model = model;
  47 
			best_val_acc = val_acc;
  48 
		end
  49 
		fprintf('%d-iter f: %g |g|: %g alpha: %g ratio: %g lambda: %g #CG: %d actred: %g prered: %g val_acc: %g\n', k, f, gnorm, alpha, actred/prered, param.lambda, CGiter, actred, prered, val_acc);
< 0.001 
      5 
  50
	else 
< 0.001 
      5 
  51
		best_model = model; 
  0.003 
      5 
  52
		fprintf('%d-iter f: %g |g|: %g alpha: %g ratio: %g lambda: %g #CG: %d actred: %g prered: %g\n', k, f, gnorm, alpha, actred/prered, param.lambda, CGiter, actred, prered); 
< 0.001 
      5 
  53
	end 
< 0.001 
      5 
  54
end 
  55 

  0.079 
      1 
  56
fprintf('total_#CG: %d\n', total_CG); 

Other subfunctions in this file are not included in this listing.