0001 function [r, params] = test_performance( imdls, fmdl );
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023 if ischar(imdls) && strcmp(imdls,'UNIT_TEST'); do_unit_test; return; end
0024
0025 if nargin==1
0026 fmdl = ng_mk_cyl_models([2,1,0.05],[16,1],[0.05]);
0027 fmdl.stimulation = mk_stim_patterns(16,1,[0,1],[0,1],{},1);
0028 end
0029 imgs= mk_image( fmdl, 1);
0030
0031 if ~iscell(imdls)
0032 imdls = {imdls};
0033 end
0034
0035 Nsim = 100;
0036 r = linspace(0,0.9,Nsim);
0037 ctr = [0,0, mean(fmdl.nodes(:,3))];
0038 maxx = max(abs(fmdl.nodes(:,1) - ctr(1)));
0039 maxy = max(abs(fmdl.nodes(:,2) - ctr(2)));
0040
0041 th= r*4321;
0042 xyzr = [maxx*r.*cos(th); maxy*r.*sin(th); ctr(3)*ones(1,Nsim);
0043 0.050*mean([maxx,maxy])*ones(1, Nsim)];
0044
0045 [vh,vi] = simulate_movement(imgs, xyzr);
0046 for i= 1:length(imdls);
0047 imgr = inv_solve(imdls{i}, vh, vi);
0048 imgr.calc_colours.npoints = 64;
0049 param_GR = eval_GREIT_fig_merit(imgr, xyzr);
0050 pnoise = calc_noise_figure( imdls{i}, vh, vi );
0051 params{i} = [param_GR; pnoise];
0052 end
0053
0054 clf; Nparams = 6;
0055 for j=1:Nparams;
0056 p = [];
0057 for i= 1:length(params);
0058 p = [p, params{i}(j,:)'];
0059 end
0060 m = mean([maxx,maxy]);
0061
0062 hig = 0.95/Nparams;
0063 axes('position',[0.1,0.05 + hig*(Nparams-j),.88, hig]);
0064 plot(r, p);
0065 if j==1; axis([0,0.9,0,2.1]); ylabel('AR');
0066 elseif j==2; axis([0,0.9,-0.16*m,0.16*m]); ylabel('PE');
0067 elseif j==3; axis([0,0.9,0,0.41]); ylabel('RES');
0068 elseif j==4; axis([0,0.9,0,0.31]); ylabel('SD');
0069 elseif j==5; axis([0,0.9,0,0.61]); ylabel('RNG');
0070 elseif j==6; set(gca,'YScale','log'); ylabel('NF');
0071 end
0072 if j<Nparams; set(gca,'XTickLabel',[]);end
0073 end
0074
0075 function do_unit_test;
0076
0077 imdl_gr = mk_common_gridmdl('GREITc1');
0078
0079
0080 imdl_bp = mk_common_gridmdl('backproj');
0081
0082
0083 imdl_gn = select_imdl( mk_common_model('d2c2', 16), {'Basic GN dif','Choose NF=0.5'});
0084
0085 test_performance( { imdl_gr, imdl_bp, imdl_gn } );
0086
0087
0088
0089 function [vh,vi,param]=test_performance_old(fmdl,imdl,r,N)
0090
0091 debug = false;
0092
0093
0094 boundary = fmdl.boundary;
0095 b_ver = unique(boundary);
0096 boundary = fmdl.nodes(b_ver,:);
0097 min_b = min(boundary)+repmat(0.5*r,1,3);
0098 max_b = max(boundary)-repmat(0.5*r,1,3);
0099 vol = get_elem_volume(fmdl);
0100
0101
0102 rand('state', sum(100*clock));
0103
0104 n_elems = size(fmdl.elems,1);
0105
0106
0107 c2f = eidors_obj('get-cache', {fmdl, N, r}, 'samples');
0108 xyzr_pt = eidors_obj('get-cache', {fmdl, N, r}, 'points');
0109
0110 count = 0;
0111
0112 if isempty(c2f) || isempty(xyzr_pt);
0113 disp('Generating sample points.');
0114 c2f = sparse(n_elems,N);
0115 while count < N
0116 n_pts = ceil(1.5 * (N - count) );
0117 vec = rand_pt ( repmat(min_b,n_pts,1), repmat(max_b,n_pts,1) );
0118 map = mk_c2f_circ_mapping(fmdl, [vec repmat(r,n_pts,1)]');
0119 frac = vol'*map/(4/3*pi*r^3);
0120 idx = find(frac > 0.9, N - count, 'first');
0121
0122 xyzr_pt = [xyzr_pt, vec(idx,:)'];
0123 newcount = count + length(idx);
0124 c2f(:, (count+1):newcount ) = map(:,idx);
0125 count = newcount;
0126 end
0127 eidors_obj('set-cache', {fmdl, N, r}, 'samples', c2f);
0128 eidors_obj('set-cache', {fmdl, N, r}, 'points', xyzr_pt );
0129 disp('Done.');
0130 end
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144 elem_data = ones(size(fmdl.elems,1),1);
0145 img = mk_image(fmdl, elem_data);
0146 disp('Calculating Jacobian. This may take a (long) while.');
0147 J = calc_jacobian( img );
0148 disp('Done.');
0149 vh= fwd_solve(img);
0150 vh = vh.meas;
0151 vi= vh*ones(1,N) + J*c2f;
0152
0153
0154
0155
0156
0157 img = inv_solve(imdl,vh,vi);
0158 img.calc_colours.npoints=32;
0159 imgs = calc_slices(img);
0160
0161 param= [calc_noise_figure(imdl, vh, vi); ...
0162 GREIT_sim_params( imgs, xyzr_pt)];
0163
0164 r = sqrt(sum(xyzr_pt(1:2,:).^2));
0165
0166 names = {'Noise','Amplitude','Position Error','Resolution', ...
0167 'Shape Deformation', 'Ringing'};
0168 for j=1:size(param,1)
0169 figure
0170 scatter(r, param(j,:));
0171 title(names{j});
0172 end
0173
0174
0175
0176
0177 function x = rand_pt(x_min, x_max)
0178 x = rand(size(x_min)) .* (x_max - x_min) + x_min;