2 %model=scm_greedy(model, model_data)
5 % computes the offline data
for the calculation of the coercive constant
6 % requires model and model data structure
12 % SCM_data.Ma : number of parameters with an already
13 % computed constant near to mu
14 % SCM_data.Mp : number of parameters without computed
16 % SCM_data.NumberOfParameters : size of the test set used in the SCM
18 % SCM_data.eps : error boundary of the
Greedy procedure
19 % SCM_data.max_iterations : maximal number of
Greedy iterations
20 % SCM_data.parallel : = 0 non parallel version
21 % = 1 parallel (pool stays active after
23 % = 2 parallel (closing pool afterwards)
24 % David Kreplin 05.01.2015
27 warning('No SCM properties are set -> using standart values')
31 params.NumberOfParameters = 100;
33 params.max_iterations=inf;
38 if ~isfield(params, 'Ma')
42 if ~isfield(params, 'Mp')
46 if ~isfield(params, 'NumberOfParameters')
47 warning('SCM: No Number of Parameters is set -> setting NumberOfParameters = 100');
48 params.NumberOfParameters = 100;
51 if ~isfield(params, 'eps')
55 if ~isfield(params, 'max_iterations')
56 params.max_iterations = inf;
59 if ~isfield(params, 'parallel')
63 if ~isfield(params, 'para_rand_seed')
64 params.para_rand_seed = 1234;
68 if ~isfield(params, 'ParameterSet')
69 rand('state',params.para_rand_seed);
70 params.ParameterSet = rand_uniform(params.NumberOfParameters,model.mu_ranges);
72 NumberOfParameters = length(params.ParameterSet(1,:));
74 SCM_data.params = params;
76 %% Boundary BOX for YLB
78 [A,~] = operator(model);
79 A=remove_dirichlet(A,1,params.dirichlet_gids);
81 SCM_data.params.Q=length(A);
82 SCM_data.lower_bound_coercivity = zeros(SCM_data.params.Q,1);
83 SCM_data.upper_bound_coercivity = zeros(SCM_data.params.Q,1);
85 %innerproduct_matrix = model.get_inner_product_matrix(model_data);
86 innerproduct_matrix(SCM_data.params.dirichlet_gids,:)=[];
87 innerproduct_matrix(:,SCM_data.params.dirichlet_gids)=[];
89 disp('-- SCM: computing boundary box');
90 for i = 1:SCM_data.params.Q
92 [msgstr, msgid] = lastwarn;
94 EV= eigs(0.5*(A{1,i}+transpose(A{1,i})),innerproduct_matrix,2,
'be');
95 [~, warnid] = lastwarn;
96 if strcmp(warnid,
'MATLAB:eigs:NotAllEigsConverged')
97 warning('Eigenvalues did not converged -> using the eig function (more expensive)');
98 EV= eig(full(A{1,i}),full(innerproduct_matrix));
101 lastwarn(msgstr, msgid);
103 SCM_data.lower_bound_coercivity(i) = min(EV);
104 SCM_data.upper_bound_coercivity(i) = max(EV);
111 SCM_data.C=AddC(params.ParameterSet(:,1),model,
operator,innerproduct_matrix,SCM_data);
112 SCM_data.params.ParameterSet(:,1)=[];
113 NumberOfParameters = NumberOfParameters-1;
118 if params.parallel >= 1
119 % s = matlabpool(
'size'); %OLDER MATLAB VERSION
121 % matlabpool(
'open');
123 if isempty(gcp(
'nocreate'))
126 %reduce parallel data amount
127 ParameterSet = SCM_data.params.ParameterSet;
128 while params.eps <= eta
130 eta_temp=zeros(NumberOfParameters,1);
131 parfor i = 1:NumberOfParameters
132 alpha_UB = scm_ub(ParameterSet(:,i),model,operator,SCM_data);
133 alpha_LB =
scm_coercive_lb(ParameterSet(:,i),model,opereator,SCM_data);
134 eta_temp(i) = (alpha_UB-alpha_LB)/(alpha_UB);
137 [eta,index]=max(eta_temp);
139 SCM_data.C=AddC(ParameterSet(:,index),model,operator,innerproduct_matrix,SCM_data);
140 ParameterSet(:,index) = [];
141 NumberOfParameters = NumberOfParameters-1;
143 disp(['-- SCM: step ' num2str(n) ' - error:' num2str(eta)]);
144 if n >= params.max_iterations
149 SCM_data.params.ParameterSet=ParameterSet;
150 if params.parallel == 2
151 % matlabpool('close'); %OLDER MATLAB VERSION
152 delete(gcp('nocreate'))
156 %% non-parallel version
157 while params.eps <= eta
159 eta_temp=zeros(NumberOfParameters,1);
160 for i = 1:NumberOfParameters
161 alpha_UB = scm_ub(SCM_data.params.ParameterSet(:,i),model,operator,SCM_data);
162 alpha_LB =
scm_coercive_lb(SCM_data.params.ParameterSet(:,i),model,operator,SCM_data);
163 eta_temp(i) = (alpha_UB-alpha_LB)/(alpha_UB);
166 [eta,index]=max(eta_temp);
168 SCM_data.C=AddC(SCM_data.params.ParameterSet(:,index),model,operator,innerproduct_matrix,SCM_data);
170 SCM_data.params.ParameterSet(:,index) = [];
171 NumberOfParameters = NumberOfParameters-1;
173 disp(['-- SCM: step ' num2str(n) ' - error:' num2str(eta)]);
174 if n >= SCM_data.params.max_iterations
186 function C=AddC(mu,model,operator,innerproduct_matrix,SCM_data)
188 if isempty(SCM_data.C)
190 model = set_mu(model,mu);
192 [A,~] = operator(model);
193 A=remove_dirichlet(A,0,SCM_data.params.dirichlet_gids);
194 A=0.5*(A+transpose(A));
195 % [V,D] = eig(full(A),full(innerproduct_matrix));
197 [v,d] = fast_eigs( A,innerproduct_matrix,'sm' );
200 [v,d] = eigs( A,innerproduct_matrix,1,'sm' );
202 warning('full spectrum needed, since eigs did not converged');
203 [v,d] = eig( full(A),full(innerproduct_matrix) );
208 C.coercivity = d;% min(max(D));
211 [A_para,~] = operator(model);
212 C.ParameterVector = A_para';
215 [A_Matrix,~] = operator(model);
216 A_Matrix=remove_dirichlet(A_Matrix,1,SCM_data.params.dirichlet_gids);
217 y_UB=zeros(SCM_data.params.Q,1);
218 norm_value = v'*innerproduct_matrix*v;
219 for i = 1:SCM_data.params.Q
220 y_UB(i) = v'*0.5*(A_Matrix{1,i}+transpose(A_Matrix{1,i}))*v/norm_value;
224 C.Set = [SCM_data.C.Set mu];
225 model = set_mu(model,mu);
227 [A,~] = operator(model);
228 A=remove_dirichlet(A,0,SCM_data.params.dirichlet_gids);
229 A=0.5*(A+transpose(A));
230 %[V,D] = eig(full(A),full(innerproduct_matrix));
232 [v,d] = fast_eigs( A,innerproduct_matrix,
'sm' );
235 [v,d] = eigs( A,innerproduct_matrix,1,
'sm' );
237 warning(
'full spectrum needed, since eigs did not converged');
238 [v,d] = eig( full(A),full(innerproduct_matrix) );
243 C.coercivity = [SCM_data.C.coercivity;d]; %min(max(D))];
246 [A,~] = operator(model);
247 C.ParameterVector = [SCM_data.C.ParameterVector;A(1:SCM_data.params.Q)
'];
250 [A_Matrix,~] = operator(model);
251 A_Matrix=remove_dirichlet(A_Matrix,1,SCM_data.params.dirichlet_gids);
252 y_UB=zeros(SCM_data.params.Q,1);
253 norm_value = v'*innerproduct_matrix*v;
254 for i = 1:SCM_data.params.Q
255 y_UB(i) = v
'*0.5*(A_Matrix{1,i}+transpose(A_Matrix{1,i}))*v/norm_value;
257 C.UBVector = [SCM_data.C.UBVector y_UB];
263 %% Upperbound computation
265 function alpha_UB = scm_ub(mu,model,operator,SCM_data)
267 model = set_mu(model,mu);
269 [theta_q,~] = operator(model);
270 alpha_UB=min(theta_q'*SCM_data.C.UBVector);
277 function A=remove_dirichlet(A,mode,I)
function alpha_LB = scm_coercive_lb(mu, model, operator, SCM_data)
alpha_LB = scm_lb(mu,model,model_data) computation of the lowerbound of the coercive constant equal t...
function SCM_data = scm_coercive_greedy(model, params, operator, innerproduct_matrix)
model=scm_greedy(model, model_data)
Customizable implementation of an abstract greedy algorithm.