-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_solver.m
45 lines (41 loc) · 1.42 KB
/
test_solver.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
function [] = test_solver(problem_name, iter_cnt)
% clc;
addpath("solvers/"+problem_name);
addpath("problems");
%% Tests are performed with the same value of R, T, F_true. All that changes is the sampled point correspondence measurements.
all_results=[];
solverGenFunc = str2func(problem_name);
[eqsHandler, cfg] = solverGenFunc();
vars = arrayfun(@(k) sym(char(strjoin({'a',num2str(k)},''))), [[1:cfg.numOfVars]], 'UniformOutput', false);
data = arrayfun(@(k) sym(char(strjoin({'c',num2str(k)},''))), [[1:cfg.numOfCoeff]], 'UniformOutput', false);
p = [vars, data];
symeqs = eqsHandler(p{:});
hiddenvar = strjoin({'a',num2str(cfg.hiddenVarNum)},'');
vars = [vars{:}];
coeffs = [data{:}];
vars = transpose([strjoin({'a', num2str(cfg.hiddenVarNum)}, ''), vars(find(vars~=hiddenvar))]);
for index = 1:iter_cnt
data = randn(length(coeffs), 1);
res = [];
[PEPSolutions] = solver(data);
eqs = subs(symeqs, coeffs, data');
PEPSolutions = transpose(PEPSolutions);
for i = 1:size(PEPSolutions,2)
sol = PEPSolutions([1:end-1],i);
try
kthres = max(abs(eval(subs(eqs, vars, sol))))/norm(abs(sol));
if kthres == 0
kthres = 1e-20;
end
res = [res, kthres];
catch
end
end
all_results = [all_results, res];
disp(mean(log10(all_results)));
end
%%
disp(mean(log10(all_results)));
rmpath("problems");
rmpath("solvers/"+problem_name);
end