rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
scm_online.m
Go to the documentation of this file.
1 function scm_results = scm_online(mu, Theta_mu, scm_offline_data, M_alpha, M_plus, desired_constant)
2 %scm_results = scm_online(mu, Theta_mu, scm_offline_data, M_alpha, M_plus, desired_constant)
3 %
4 % function which computes the online-stage of the SCM including the
5 % computation of both a lower and an upper bound to the desired constant.
6 % See scm_offline.m for the description of the various model-fields
7 % controlling the SCM.
8 %
9 % The upper bound is computed as a simple search for a minimum, the lower
10 % bound is computed by solving a linear program.
11 
12 % Dominik Garmatter 17.09 2012
13 
14 
15 warningstate = warning('off','MATLAB:rankDeficientMatrix');
16 %comment by Dominik Garmatter regarding this disable:
17 % the disabled warning occured sometimes in qpsub.m (lines 742 nd 632) when
18 % using a 'lin_evol' problem_type and the standard active-set algorithm (in
19 % the linear program - see scm_offline_data.Options). We couldn't find a
20 % reason why this warning should occur but neglected it because it didn't
21 % seem to be a huge problem (even if the 'lin_evol'-case isn't fully
22 % working yet - but in qpsub other warnings regarding singularity of
23 % matrices are also disabled for the respective lines)
24 
25 % preparing the sets P_M_alpha and P_M_plus. But it is sufficient to have
26 % the indices of the selected parmeters!
27 [~, ind_alpha] = scm_get_neighbours(M_alpha, mu, scm_offline_data.C);
28 [~, ind_plus] = scm_get_neighbours(M_plus, mu, scm_offline_data.D);
29 
30 %% computation of the lower bound
31 
32 % if the offline-data is feasable we choose the upper end of the bounding
33 % box as starting vector.
34 if scm_offline_data.isfeasable == 1
35  x0 = scm_offline_data.sigma_plus;
36 else
37  warning('ONLINE:infeasable_data', 'offline_data can cause infeasable Problems. Check them!');
38 end
39 
40 % now compute the lower bound via a linear program min_x (f'*x) with the
41 % inequality constriants A*x <= b
42 f = Theta_mu;
43 b = [scm_offline_data.sigma_plus; -scm_offline_data.sigma_minus; -scm_offline_data.alpha_C(ind_alpha); zeros(size(ind_plus,2),1)];
44 A = [eye(size(scm_offline_data.sigma_plus,1)); -eye(size(scm_offline_data.sigma_plus,1)); -scm_offline_data.Theta_C(:,ind_alpha)'; -scm_offline_data.Theta_D(:,ind_plus)'];
45 
46 [~, fval, exitflag, ~] = linprog(f, A, b, [], [], [], [], x0, scm_offline_data.Options);
47 
48 if exitflag < 0 % if you also want to include the case that the maximum number of iterations is reached choose if exitflag < 1 here
49  warning('ONLINE:lin_prog', ['Optimization exited with exitflag = ' mat2str(exitflag)]);
50  keyboard;
51 end
52 
53 warning(warningstate) % reset the warning state of the above warning
54 
55 %% inf-sup differntiation and computation of the upper bound
56 
57 % get information about the parent-function using dbstack. In the coercive
58 % case or if the parenting function is the offline-phase never use sqrt. In
59 % other cases (online-phase of infsup) use sqrt!
60 % This solves the problem that the SCM for the inf-sup case (i.e.
61 % model.scm_desired_constant = 2) is cast for beta^2. But in an
62 % online-phase of such a SCM one wants beta as a result and not beta^2.
63 % This is solved with this block of code.
64 % Also the upper bound is computed via a simple minimum search.
65 stack = dbstack;
66 if size(stack,1) > 1 && strcmp(stack(2,1).name,'scm_offline_new') == 1 || desired_constant == 1
67  Lower_Bound = fval;
68  Upper_Bound = min(scm_offline_data.ystern_C'*Theta_mu);
69 else
70  Lower_Bound = sqrt(fval);
71  Upper_Bound = sqrt(min(scm_offline_data.ystern_C'*Theta_mu));
72 end
73 
74 %% output
75 
76 scm_results.Upper_Bound = Upper_Bound;
77 scm_results.Lower_Bound = Lower_Bound;
function scm_results = scm_online(mu, Theta_mu, scm_offline_data, M_alpha, M_plus, desired_constant)
scm_results = scm_online(mu, Theta_mu, scm_offline_data, M_alpha, M_plus, desired_constant) ...
Definition: scm_online.m:17
function scm_offline_data = scm_offline(model, detailed_data, M_train, D_train)
scm_offline_data = scm_offline(model, detailed_data, M_train, D_train)
Definition: scm_offline.m:17