samer@4
|
1 function M=expmap(p1,p2,p3)
|
samer@4
|
2 % expmap - Create exponentially spaced discretisation map
|
samer@4
|
3 %
|
samer@4
|
4 % expmap :: Min:real, Max:real, N:natural -> dmap(N).
|
samer@4
|
5 % expmap :: [Min,Max]:[[1,2]], N:natural -> dmap(N).
|
samer@4
|
6 %
|
samer@4
|
7 % Parameters work almost but not quite like logspace: the
|
samer@4
|
8 % third parameter is the number of GAPS, not the number of
|
samer@4
|
9 % points, defining the map, So for a map with edges at 0:10,
|
samer@4
|
10 % use linmap(0,10,10). To get the same edges from linspace,
|
samer@4
|
11 % you would need linspace(0,10,11).
|
samer@4
|
12
|
samer@4
|
13 % unpack parameters
|
samer@4
|
14 if nargin==2, min=log(p1(1)); max=log(p1(2)); bins=p2;
|
samer@4
|
15 else min=log(p1); max=log(p2); bins=p3; end
|
samer@4
|
16
|
samer@4
|
17 dx=(max-min)/bins;
|
samer@4
|
18 M=dmap(bins,@(t)map(bins,min,1/dx,t),@(t)revmap(min,dx,t));
|
samer@4
|
19
|
samer@4
|
20 function I=map(N,min,k,X)
|
samer@4
|
21 U=log(X);
|
samer@4
|
22 I=1+floor(k*(U-min));
|
samer@4
|
23 I(I<1)=-inf;
|
samer@4
|
24 I(I>N)=inf;
|
samer@4
|
25
|
samer@4
|
26 function X=revmap(min,ik,I)
|
samer@4
|
27 I=shiftdim(shiftdim(I),-1);
|
samer@4
|
28 U1=min+(I-1)*ik;
|
samer@4
|
29 U2=min+(I)*ik;
|
samer@4
|
30 X=exp(cat(1,U1,U2));
|
samer@4
|
31
|