CG (Calls: 5, Time: 656.774 s)
Generated 19-Jun-2021 04:39:10 using performance time.
function in file /nfs/inm_phd/07/d07944009/2021/0618-proj6/simpleNN/MATLAB/opt/CG.m
Copy to new window for comparing multiple runs
Function Name | Function Type | Calls |
newton | function | 5 |
Line Number | Code | Calls | Total Time | % Time | Time Plot |
26 | Gv = JTBJv(data, param, model,... | 72 | 431.985 s | 65.8% | ![]() |
21 | net = Jacobian(data, param, mo... | 5 | 219.889 s | 33.5% | ![]() |
48 | sGs = s' * (-g - r - param.lam... | 5 | 4.809 s | 0.7% | ![]() |
30 | Gv = (param.lambda + 1/param.C... | 72 | 0.022 s | 0.0% | ![]() |
32 | alpha = rTr / (v' * Gv); | 72 | 0.014 s | 0.0% | ![]() |
All other lines | 0.055 s | 0.0% | ![]() | ||
Totals | 656.774 s | 100% |
Function Name | Function Type | Calls | Total Time | % Time | Time Plot |
CG>JTBJv | subfunction | 72 | 431.982 s | 65.8% | ![]() |
Jacobian | function | 5 | 219.885 s | 33.5% | ![]() |
gpu | function | 15 | 0.003 s | 0.0% | ![]() |
Self time (built-ins, overhead, etc.) | 4.904 s | 0.7% | ![]() | ||
Totals | 656.774 s | 100% |
Line number | Message |
7 | The value assigned to variable 'Gv' might be unused. |
Total lines in function | 48 |
Non-code lines (comments, blank lines) | 10 |
Code lines (lines that can run) | 38 |
Code lines that did run | 36 |
Code lines that did not run | 2 |
Coverage (did run/can run) | 94.74 % |
time | Calls | line | |
---|---|---|---|
1 | function [s, CGiter, gs, sGs] = CG(data, param, model, net, grad) | ||
2 | |||
< 0.001 | 5 | 3 | var_ptr = model.var_ptr; |
< 0.001 | 5 | 4 | n = var_ptr(end) - 1; |
< 0.001 | 5 | 5 | GNsize = size(data, 2); |
0.002 | 5 | 6 | s = gpu(@zeros, [n, 1]); |
0.002 | 5 | 7 | Gv = gpu(@zeros, [n, 1]); |
0.002 | 5 | 8 | g = gpu(@zeros, [n, 1]); |
0.001 | 5 | 9 | for m = 1 : model.L |
0.002 | 20 | 10 | var_range = var_ptr(m) : var_ptr(m+1) - 1; |
0.006 | 20 | 11 | g(var_range) = [grad.dfdW{m}(:); grad.dfdb{m}]; |
0.002 | 20 | 12 | end |
0.001 | 5 | 13 | r = -g; |
< 0.001 | 5 | 14 | v = r; |
15 | |||
0.002 | 5 | 16 | gnorm = norm(g); |
< 0.001 | 5 | 17 | rTr = gnorm^2; |
< 0.001 | 5 | 18 | cgtol = param.xi * gnorm; |
19 | |||
< 0.001 | 5 | 20 | if param.Jacobian |
219.889 | 5 | 21 | net = Jacobian(data, param, model, net); |
< 0.001 | 5 | 22 | end |
23 | |||
0.001 | 5 | 24 | for CGiter = 1 : param.CGmax |
< 0.001 | 72 | 25 | if param.Jacobian |
431.985 | 72 | 26 | Gv = JTBJv(data, param, model, net, v); |
27 | else | ||
28 | Gv = R_JTBJv(data, param, model, net, v); | ||
< 0.001 | 72 | 29 | end |
0.022 | 72 | 30 | Gv = (param.lambda + 1/param.C) * v + Gv/GNsize; |
31 | |||
0.014 | 72 | 32 | alpha = rTr / (v' * Gv); |
0.007 | 72 | 33 | s = s + alpha * v; |
0.006 | 72 | 34 | r = r - alpha * Gv; |
35 | |||
0.003 | 72 | 36 | rnewTrnew = r' * r; |
37 | % Stopping condition | ||
0.005 | 72 | 38 | if (sqrt(rnewTrnew) <= cgtol) || (CGiter == param.CGmax) |
0.001 | 5 | 39 | break |
< 0.001 | 67 | 40 | end |
< 0.001 | 67 | 41 | beta = rnewTrnew / rTr; |
< 0.001 | 67 | 42 | rTr = rnewTrnew; |
0.003 | 67 | 43 | v = r + beta * v; |
< 0.001 | 67 | 44 | end |
45 | |||
46 | % Values used for predicting function-value reduction | ||
0.002 | 5 | 47 | gs = s' * g; |
4.809 | 5 | 48 | sGs = s' * (-g - r - param.lambda*s); |
Other subfunctions in this file are not included in this listing.