samer@4: function M=expmap(p1,p2,p3) samer@4: % expmap - Create exponentially spaced discretisation map samer@4: % samer@4: % expmap :: Min:real, Max:real, N:natural -> dmap(N). samer@4: % expmap :: [Min,Max]:[[1,2]], N:natural -> dmap(N). samer@4: % samer@4: % Parameters work almost but not quite like logspace: the samer@4: % third parameter is the number of GAPS, not the number of samer@4: % points, defining the map, So for a map with edges at 0:10, samer@4: % use linmap(0,10,10). To get the same edges from linspace, samer@4: % you would need linspace(0,10,11). samer@4: samer@4: % unpack parameters samer@4: if nargin==2, min=log(p1(1)); max=log(p1(2)); bins=p2; samer@4: else min=log(p1); max=log(p2); bins=p3; end samer@4: samer@4: dx=(max-min)/bins; samer@4: M=dmap(bins,@(t)map(bins,min,1/dx,t),@(t)revmap(min,dx,t)); samer@4: samer@4: function I=map(N,min,k,X) samer@4: U=log(X); samer@4: I=1+floor(k*(U-min)); samer@4: I(I<1)=-inf; samer@4: I(I>N)=inf; samer@4: samer@4: function X=revmap(min,ik,I) samer@4: I=shiftdim(shiftdim(I),-1); samer@4: U1=min+(I-1)*ik; samer@4: U2=min+(I)*ik; samer@4: X=exp(cat(1,U1,U2)); samer@4: