[37] | 1 | function test_sdpvar_geomean |
---|
| 2 | |
---|
| 3 | % Test real vector geomean, length == 2^n |
---|
| 4 | randn('seed',1234); |
---|
| 5 | rand('seed',1234); |
---|
| 6 | A = randn(15,2); |
---|
| 7 | b = rand(15,1)*5; |
---|
| 8 | x = sdpvar(2,1); |
---|
| 9 | obj = geomean(b-A*x); |
---|
| 10 | solvesdp([],-obj); |
---|
| 11 | mbg_asserttolequal(double(x'), [-0.05519469470525 0.26970610928222], 1e-5); |
---|
| 12 | mbg_asserttolequal(double(obj), 1.83896843735621, 1e-5); |
---|
| 13 | |
---|
| 14 | % Test real vector geomean, length == 2^n |
---|
| 15 | randn('seed',1234); |
---|
| 16 | rand('seed',1234); |
---|
| 17 | A = randn(16,2); |
---|
| 18 | b = rand(16,1)*5; |
---|
| 19 | x = sdpvar(2,1); |
---|
| 20 | obj = geomean(b-A*x); |
---|
| 21 | solvesdp([],-obj); |
---|
| 22 | mbg_asserttolequal(double(x'), [ -0.01148934254297 -0.20720944929269], 1e-5); |
---|
| 23 | mbg_asserttolequal(double(obj), 1.93924577959868, 1e-5); |
---|
| 24 | |
---|
| 25 | % Test real vector geomean, length == 1 |
---|
| 26 | randn('seed',1234); |
---|
| 27 | rand('seed',1234); |
---|
| 28 | A = randn(1,2); |
---|
| 29 | b = rand(1,1)*5; |
---|
| 30 | x = sdpvar(2,1); |
---|
| 31 | obj = geomean(b-A*x); |
---|
| 32 | sol = solvesdp([],-obj); |
---|
| 33 | mbg_asserttolequal(sol.problem,2); |
---|
| 34 | |
---|
| 35 | % Test real matrix geomean, length ~2^n |
---|
| 36 | randn('seed',1234); |
---|
| 37 | rand('seed',1234); |
---|
| 38 | D = randn(5,5); |
---|
| 39 | P = sdpvar(5,5); |
---|
| 40 | obj = geomean(P); |
---|
| 41 | solvesdp(set(P < D*D'),-obj); |
---|
| 42 | mbg_asserttolequal(double(obj), 2.00333629658259, 1e-5); |
---|
| 43 | |
---|
| 44 | % Test real matrix geomean, length == 2^n |
---|
| 45 | randn('seed',1234); |
---|
| 46 | rand('seed',1234); |
---|
| 47 | D = randn(8,8); |
---|
| 48 | P = sdpvar(8,8); |
---|
| 49 | obj = geomean(P); |
---|
| 50 | solvesdp(set(P < D*D'),-obj); |
---|
| 51 | mbg_asserttolequal(double(obj), 3.32199302165511, 1e-5); |
---|
| 52 | |
---|
| 53 | % Test real matrix geomean, length == 2 |
---|
| 54 | randn('seed',1234); |
---|
| 55 | rand('seed',1234); |
---|
| 56 | D = randn(2,2); |
---|
| 57 | P = sdpvar(2,2); |
---|
| 58 | obj = geomean(P); |
---|
| 59 | solvesdp(set(P < D*D'),-obj); |
---|
| 60 | mbg_asserttolequal(double(obj), 2.02896175488410, 1e-5); |
---|
| 61 | |
---|
| 62 | % Test complex matrix geomean, length ~2^n |
---|
| 63 | randn('seed',1234); |
---|
| 64 | rand('seed',1234); |
---|
| 65 | D = randn(5,5)+sqrt(-1)*randn(5,5);D = D + D'+eye(5)*10; |
---|
| 66 | P = sdpvar(5,5,'he','co'); |
---|
| 67 | obj = geomean(P); |
---|
| 68 | solvesdp(set(P < D),-obj); |
---|
| 69 | mbg_asserttolequal(double(obj),9.07516376113709, 1e-5); |
---|
| 70 | |
---|
| 71 | % Test complex matrix geomean, length == 2^n |
---|
| 72 | randn('seed',1234); |
---|
| 73 | rand('seed',1234); |
---|
| 74 | D = randn(8,8)+sqrt(-1)*randn(8,8);D = D + D'+eye(8)*20; |
---|
| 75 | P = sdpvar(8,8,'he','co'); |
---|
| 76 | obj = geomean(P); |
---|
| 77 | solvesdp(set(P < D),-obj); |
---|
| 78 | mbg_asserttolequal(double(obj), 18.42071980565500, 1e-5); |
---|
| 79 | |
---|
| 80 | |
---|
| 81 | |
---|
| 82 | |
---|
| 83 | |
---|
| 84 | |
---|
| 85 | |
---|
| 86 | |
---|
| 87 | |
---|
| 88 | |
---|
| 89 | |
---|
| 90 | |
---|
| 91 | |
---|