1 function eop_master_gui(varargin)
2 %
function eop_master_GUI(model,detailed_data,[sim_data.U],[reduced_data], [callbackfigure], [cbhandle])
5 %
for the 4 differnet parameters, another slider
for the time and a last
6 % slider
for N, the number of used reduced basis vectors. In the top right
7 % the reduced simulation to the current settings is plottet and in the top
8 % left the error ||u-u_N|| in a discrete L2-Norm is plottet, dependant on
9 % the number N of used reduced basis vectors. With the button
"Knopf" in
10 % the center a detailed simulation is done and plottet to the current
11 % setting and theerror ||u-u_N||
for the current settings is updated.
15 if nargin < 6 % no callback ->
new figure
16 % create
new figure g and extract the input and write the important parts in ud.
17 % ud will be passed on
for callbacks etc.
31 ud.detailed_data = list{2};
33 error(
'see description for the right input arguments!');
35 % write size of RB in ud.model
36 if ~isfield(ud.model,
'N')
37 ud.model.N = ceil(ud.model.get_rb_size(ud.model,ud.detailed_data)/2);
39 % write reduced data in ud
41 disp(
'Preparing offline-quantities...')
42 ud.reduced_data = gen_reduced_data(ud.model, ud.detailed_data);
44 ud.reduced_data = list{4};
46 %
if not in the input
do a detailed_simulation
for the current mu and save
47 % it. If in the input the detailed_simulation should have been done
for the
50 detailed_simulation_data = detailed_simulation(ud.model, ud.detailed_data);
51 ud.detailed_simulation_data = detailed_simulation_data.U;
53 ud.detailed_simulation_data = list{3};
55 ud.first_mu = ud.model.get_mu(ud.model); % save
this first mu, since the detailed_simulation was done with it (later used
for the error)
57 % setting GUI size parameters
61 yscale_uicontrols = 1;
62 % define some stuff so that the slider positioning works
63 for i=1:length(ud.model.mu_names)
64 Positioner1 = ceil(i/2);
67 elseif i/2 == floor(i/2)
70 % various sliders for the parameters - use current mus as first slider value/position
71 mu = ud.model.get_mu(ud.model);
73 ra = ud.model.mu_ranges{i};
74 norm_val = (val-ra(1))/(ra(2)-ra(1));
75 txt(i) = uicontrol(g,
'Style',
'text',
'Units',
'normalized',...
77 [di+Positioner2,(Positioner1*di+(Positioner1-1)*textheight)*yscale_uicontrols,...
78 textwidth,textheight*yscale_uicontrols],...
79 'String',[ud.model.mu_names{i},
'=',num2str(val)],...
80 'Tag',[
'text_',ud.model.mu_names{i}]);
81 slider(i) = uicontrol(g,
'Style',
'slider',
'Units',
'normalized',...
83 [ 2*di+textwidth+Positioner2, ...
84 (Positioner1*di+(Positioner1-1)*textheight)*yscale_uicontrols, ...
85 (1-3*di-textwidth)/3,...
86 textheight*yscale_uicontrols],...
87 'Tag',[
'slider_',ud.model.mu_names{i}],...
91 'Callback',
'eop_master_gui([],[],[],[],[],[],gcbf,gcbo)');
94 % N = number of RB slider
95 i = ceil(length(ud.model.mu_names)/2)+1;
96 txt(i) = uicontrol(g,
'Style',
'text',
'Units',
'normalized',...
98 [di,(i*di+(i-1)*textheight)*yscale_uicontrols,...
99 textwidth,textheight*yscale_uicontrols],...
100 'String',[
'RB-size N = ',num2str(ud.model.N)],...
102 slider(i) = uicontrol(g,
'Style',
'slider',
'Units',
'normalized',...
105 (i*di + (i-1)*textheight)*yscale_uicontrols, ...
106 (1-3*di-textwidth)/3,textheight*yscale_uicontrols],...
109 ud.model.get_rb_size(ud.model,ud.detailed_data),...
110 'value',ud.model.N, ...
111 'Callback',
'eop_master_gui([],[],[],[],[],[],gcbf,gcbo)',...
113 [1/((ud.model.get_rb_size(ud.model,ud.detailed_data))-1),0.1]);
115 txt(i) = uicontrol(g,
'Style',
'text',
'Units',
'normalized',...
117 [di+0.5,(i*di+(i-1)*textheight)*yscale_uicontrols,...
118 textwidth,textheight*yscale_uicontrols],...
119 'String',
'timestep 1',
'Tag',
'text_time');
120 slider(i) = uicontrol(g,
'Style',
'slider',
'Units',
'normalized',...
122 [2*di+textwidth+0.5, ...
123 (i*di + (i-1)*textheight)*yscale_uicontrols, ...
124 (1-3*di-textwidth)/3,textheight*yscale_uicontrols],...
125 'Tag',
'slider_time',...
126 'min',1,
'max',ud.model.nt+1,
'value',1, ...
127 'Callback',
'eop_master_gui([],[],[],[],[],[],gcbf,gcbo)',...
128 'sliderstep',[1/ud.model.nt,0.1]);
131 axes(
'Units',
'normalized',...
132 'Position',[di,((i+2)*di+i*textheight)*yscale_uicontrols,...
133 di+textwidth+(1-3*di-textwidth)/3,1-((i+3)*di + i*textheight)*yscale_uicontrols],...
136 axes(
'Units',
'normalized',...
137 'Position',[di+0.5,((i+2)*di+i*textheight)*yscale_uicontrols,...
138 di+textwidth+(1-3*di-textwidth)/3,1-((i+3)*di + i*textheight)*yscale_uicontrols],...
140 Master_Button = uicontrol(g,
'Style',
'pushbutton',
'Units',
'normalized',
'String',
'Knopf',...
141 'Position',[0.5-di/4,((i+2)*di+i*textheight)*yscale_uicontrols-6/4*di,di,di],...
142 'Tag',
'Master_button',
'Callback',
'eop_master_gui([],[],[],[],[],[],gcbf,gcbo)');
144 set(g,
'Color',[0.8147 0.9058 0.1270]); % fancy backgroundcolour
145 set(g,
'Userdata',ud); % take the structure ud into the Userdata in g, so it is enough to have g.
151 if nargin >=6 % callback
152 %
get the handles of the current figure and the current callback
object
155 ud =
get(cbf,
'Userdata'); % extract data
156 tag =
get(cbo,
'Tag'); % tag of the callback
object
157 % updates the correct callbackobject and gives back a sourcestring
for the
158 % replot
function to work properly
159 if isequal(tag,
'slider_time')
160 val = round(get(cbo,'value'));
161 set(cbo,'value',val);
163 txt = findobj(cbf,'Tag','text_time');
164 set(txt,'String',['timestep = ',num2str(val)]);
166 elseif isequal(tag,'slider_N')
167 val = round(get(cbo,'value'));
168 set(cbo,'value',val);
170 txt = findobj(cbf,'Tag','text_N');
171 set(txt,'String',['RB-size N = ',num2str(val)]);
173 elseif isequal(tag,'Master_button')
174 sourcestr = 'Master';
177 for i=1:length(ud.model.mu_names)
178 if isequal(tag,['slider_',ud.model.mu_names{i}])
180 % rescaling of the mu values since the slider is normed to [0,1]
181 val =
get(cbo,
'value')*...
182 (ud.model.mu_ranges{i}(2)-...
183 ud.model.mu_ranges{i}(1)) + ...
184 ud.model.mu_ranges{i}(1);
185 mu = ud.model.get_mu(ud.model);
187 ud.model = ud.model.set_mu(ud.model,mu);
188 txt = findobj(cbf,
'Tag',[
'text_',ud.model.mu_names{i}]);
189 set(txt,
'String',[ud.model.mu_names{i},
' = ',num2str(val)]);
194 error(
'callback object unknown!!');
197 set(cbf,
'Userdata',ud); % update userdata
198 replot(cbf, sourcestr);
202 function replot(g,tag)
203 ud = get(g,'Userdata'); % extract userdata
205 if ismember(tag,{
'new',
'mu',
'N',
'time'})
206 if strcmp(tag,
'new') == 1
209 reduced_data = extract_reduced_data_subset(ud.model,ud.reduced_data); % reduced data of the desired size
210 simulation_data = rb_simulation(ud.model,reduced_data);
211 rb_sim_data=rb_reconstruction(ud.model,ud.detailed_data,simulation_data);
212 ud.sim_data = rb_sim_data; % save the
new rb_simulation
213 % go to the correct axis
214 ax2 = findobj(g,
'Tag',
'axes_2');
215 set(gcf,
'CurrentAxes',ax2);
216 % to plot the
new data of the correct time step
217 plot_vertex_data(ud.detailed_data.grid,ud.sim_data.U(:,ud.timestep),[]);
218 set(gca,
'Title',text(
'String',
'the reduced simulation')) % has to be set again :(
219 if strcmp(tag,
'N') == 1 || strcmp(tag,
'new') == 1 % plot the error above N the actual size of the RB
220 disp([
'performing RB simulation with N = ',num2str(ud.model.N)]);
221 if strcmp(tag,
'new') == 1
222 ud.model = ud.model.set_mu(ud.model,ud.first_mu);
223 ud.current_mu = ud.first_mu;
225 ud.model = ud.model.set_mu(ud.model,ud.current_mu);
227 reduced_data = extract_reduced_data_subset(ud.model,ud.reduced_data);
228 simulation_data = rb_simulation(ud.model,reduced_data);
229 rb_sim_data=rb_reconstruction(ud.model,ud.detailed_data,simulation_data);
230 ud.sim_data = rb_sim_data;
232 Fehler =
eop_fd_norm(ud.detailed_simulation_data, ud.sim_data.U, ud.detailed_data.grid);
234 ax = findobj(g,
'Tag',
'axes_1');
235 set(gcf,
'CurrentAxes',ax);
236 fprintf(
'plotting...\n');
238 plot(0:ud.model.deltaT:ud.model.T,Fehler
','r o :
');
239 set(gca,'Tag
','axes_1
');
240 set(gca,'Title
',text('String
','the error ||u-u_N|| above N
'))
241 set(get(gca,'XLabel
'),'String
','time t
');
242 set(get(gca,'YLabel
'),'String
','error
');
243 set(gca,'XTick
',0:2*ud.model.deltaT:ud.model.T);
246 elseif isequal(tag,'Master
')
247 % master button performs a detailed_simulation to the current mu and
249 detailed_simulation_data = detailed_simulation(ud.model, ud.detailed_data);
250 ud.detailed_simulation_data = detailed_simulation_data.U;
251 if ud.model.compute_output_functional == 1
252 params.plot_output_title = ['the output functional
for mu =
' mat2str(get_mu(ud.model))];
253 params.plot_title = ['the detailed simulation
for the current parameter mu =
', mat2str(round((get_mu(ud.model).*1000))/1000)];
255 params.plot_title = ['the detailed simulation
for the current parameter mu =
', mat2str(round((get_mu(ud.model).*1000))/1000)];
257 % plots it in a seperate window
258 lin_evol_plot_sim_data(ud.model,ud.detailed_data,detailed_simulation_data,params);
259 ud.current_mu = get_mu(ud.model);
260 reduced_data = extract_reduced_data_subset(ud.model,ud.reduced_data);
261 simulation_data = rb_simulation(ud.model,reduced_data);
262 rb_sim_data=rb_reconstruction(ud.model,ud.detailed_data,simulation_data);
263 ud.sim_data = rb_sim_data;
264 % error update in the GUI
265 Fehler = eop_fd_norm(ud.detailed_simulation_data, ud.sim_data.U, ud.detailed_data.grid);
266 ax = findobj(g,'Tag
','axes_1
');
267 set(g,'CurrentAxes
',ax);
269 fprintf('plotting...\n
');
270 plot(0:ud.model.deltaT:ud.model.T,Fehler',
'r o :');
271 set(gca,
'Tag',
'axes_1');
272 set(gca,
'Title',text(
'String',
'the error ||u-u_N|| above N'))
273 set(get(gca,'XLabel'),'String','time t');
274 set(get(gca,'YLabel'),'String','error');
275 set(gca,'XTick',0:2*ud.model.deltaT:ud.model.T);
277 set(g,'Userdata',ud); % update user data
function model = european_option_pricing_model(params)
model = european_option_pricing_model(params)
function norm = eop_fd_norm(fd_function1, fd_function2,gridbase grid, unused1)
norm = eop_fd_norm(fd_function1, fd_function2, grid, ~)