rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
calculate_Lipschitz_const.m
1 function [Lip_H,model] = calculate_Lipschitz_const(model, varargin)
2 %function Lip_H = calculate_Lipschit_const(model, varargin)
3 %
4 % function caluclates the Lipschitz constant using detailed simulations, which is needed for the
5 % non-iterative error estimator in optimization.
6 %
7 % Optional inputs:
8 % model_data
9 % mu
10 %
11 
12 % Markus Dihlmann 03.01.2013
13 
14 compute_derivative_info_old = model.compute_derivative_info;
15 
16 %see if there's model_data
17 if nargin>=2
18  model_data = varargin{1};
19  if isempty(model_data)
20  model_data = gen_model_data(model);
21  end
22 else
23  model_data = gen_model_data(model);
24 end
25 
26 %see if there's a mu given
27 if nargin>2
28  mu = varargin{2};
29  if ~isempty(mu)
30  model = set_mu(model, mu);
31  end
32 end
33 
34 %claculate the Hessian
35 disp('performing detailed simulations to calculate the Lipschitz constant')
36 H_der = lin_evol_opt_fd_Hessian_der(model, model_data,[]);
37 
38 model = setfield_in_model_and_base_model(model,'compute_derivative_info', 0);
39 HgradJ = zeros(size(H_der));
40 for k=1:size(H_der,1)
41  for l=1:size(H_der,2)
42  sim_data_dummy.U = H_der{k,l};
43  sim_data_dummy = model.get_output(model, sim_data_dummy,model_data);
44  HgradJ(k,l) = sim_data_dummy.y(end);
45  end
46 end
47 
48 %reset model
49 model = setfield_in_model_and_base_model(model,'compute_derivative_info', compute_derivative_info_old);
50 
51 %return Lipschitz constant
52 Lip_H = norm(HgradJ);