matlab - Blockdiagonal variation grid -
i have feeling missing intuitive in solution generating partially varied block-diagonal grid. in case, rid of loop in function (for sake of challenge...)
given tuples of parameters, number of intervals , percentage variation:
params = [100 0.5 1 24 1 0.9]; nint = 1; perc = 0.1; the desired output should be:
pspacegrid(params,perc,nint) ans = 90.0000 0.5000 1.0000 100.0000 0.5000 1.0000 110.0000 0.5000 1.0000 100.0000 0.4500 1.0000 100.0000 0.5000 1.0000 100.0000 0.5500 1.0000 100.0000 0.5000 0.9000 100.0000 0.5000 1.0000 100.0000 0.5000 1.1000 21.6000 1.0000 0.9000 24.0000 1.0000 0.9000 26.4000 1.0000 0.9000 24.0000 0.9000 0.9000 24.0000 1.0000 0.9000 24.0000 1.1000 0.9000 24.0000 1.0000 0.8100 24.0000 1.0000 0.9000 24.0000 1.0000 0.9900 where can see variation occurs @ values expressed mask:
mask = 1 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 1 1 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 1 the function pspacegrid() is:
function out = pspacegrid(params, perc, nint) % pspacegrid generates parameter space grid sensitivity analysis % size , number of variation steps sz = size(params); nsteps = nint*2+1; % preallocate output out = reshape(permute(repmat(params,[1,1,nsteps*sz(2)]),[3,1,2]),[],sz(2)); % mask index positions place interpolated [tmp{1:sz(2)}] = deal(true(nsteps,1)); mask = repmat(logical(blkdiag(tmp{:})),sz(1),1); zi = cell(sz(1),1); % loop per each parameter tuple r = 1:sz(1) % columns, rows, rows interpolate , lower/upper parameter values x = 1:sz(2); y = [1; nint*2+1]; yi = (1:nint*2+1)'; z = [params(r,:)*(1-perc); params(r,:)*(1+perc)]; % interpolated parameters zi{r} = interp2(x,y,z, x, yi); end out(mask) = cat(1,zi{:});
i think got it, building off pre-loop code:
params = [100 0.5 1 24 1 0.9]; nint = 1; perc = 0.1; sz = size(params); nsteps = nint*2+1; % preallocate output out = reshape(permute(repmat(params,[1,1,nsteps*sz(2)]),[3,1,2]),[],sz(2)); %map of percentage moves [tmp{1:sz(2)}] = deal(linspace(-perc,perc,nint*2+1)'); mask = repmat(blkdiag(tmp{:}),sz(1),1) + 1; %add 1 can multiply @ end mask.*out so instead of making mask replicate ones made replicate percentage moves each element makes repeating pattern, basic element made this:
linspace(-perc,perc,nint*2+1)' then it's simple adding 1 whole thing , multiplying out matrix
i tested follows:
me = mask.*out; = pspacegrid(params, perc, nint); check = me - < 0.0001; mean(check(:)) seemed work when fiddled inputs. did error function, had change true(...) ones(...). might because i'm running online uses octave rather matlab.
Comments
Post a Comment