Debian Codegraph @

tests/optimizers/optimizer_function_count.inc

raw
1 profile off;
2 if ~isoctave
3 profData = profile('info');
4 % profile viewer % this opens the GUI
5
6 % define the functions to look for that call 'dsge_likelihood.m' during optimization
7 switch options_.mode_compute
8 case {1, 3, 7, 12, 102}
9 % These are optimization algorithms provided by MATLAB
10 % The direct caller of our function is not documented and can change
11 % across MATLAB versions.
12 % In any case, we do not have to test that MATLAB optimizers correctly
13 % counts function calls, that’s not the purpose of our testsuite.
14 fun = {};
15 case 2
16 fun = {'simulated_annealing'};
17 case 4
18 fun = {'penalty_objective_function'};
19 case 5
20 fun = {'penalty_objective_function'};
21 case 6
22 fun = {'gmhmaxlik','gmhmaxlik_core'};
23 case 8
24 fun = {'simplex_optimization_routine', 'simplex_optimization_routine>simplex_initialization'};
25 case 9
26 fun = {'cmaes'};
27 case 10
28 fun = {'simpsa>CALCULATE_COST'};
29 case 101
30 if options_.analytic_derivation
31 fun = {'analytic_gradient_wrapper'};
32 else
33 fun = {'solvopt', 'apprgrdn'};
34 end
35 otherwise
36 fun = {'penalty_objective_function'};
37 end
38 % find dsge_likelihood function
39 dsge_idx = find(strcmp({profData.FunctionTable.FunctionName}, 'dsge_likelihood'));
40 dsge_func = profData.FunctionTable(dsge_idx);
41 % get all parent function names using their indices
42 parent_indices = [dsge_func.Parents.Index];
43 parent_names = {profData.FunctionTable(parent_indices).FunctionName};
44 % find matching functions and sum their NumCalls
45 matching_idx = ismember(parent_names, fun);
46 NumCalls = sum([dsge_func.Parents(matching_idx).NumCalls]);
47
48 if options_.analytic_derivation
49 fprintf('OPTIMIZATION INFO WITH ANALYTICAL DERIVATIVES\n');
50 else
51 fprintf('OPTIMIZATION INFO\n');
52 end
53 fprintf('- funcCount: %d\n', oo_.posterior.optimization.optimization_info.funcCount);
54 fprintf('- runtime: %s\n', dynsec2hms(oo_.posterior.optimization.optimization_info.runtime));
55 fprintf('- iterations: %d\n', oo_.posterior.optimization.optimization_info.iterations);
56 fprintf('- exitflag: %d\n', oo_.posterior.optimization.optimization_info.exitflag);
57 fprintf('- termination message: %s\n', oo_.posterior.optimization.optimization_info.message);
58
59 if ~isempty(fun) && ~isequal(oo_.posterior.optimization.optimization_info.funcCount,NumCalls)
60 error('counting of function evaluations is not correct');
61 end
62 end