Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Incorporated the PDF routines from JLAB directly into CalculateLSHPar…

…ameters.

No longer necessary to download the entire package, and put it on the path.
  • Loading branch information...
commit 916370f57f33e73d5e22d728ed3db32db64d70d0 1 parent 8f4922f
@MalcolmSlaney MalcolmSlaney authored
Showing with 1,447 additions and 3 deletions.
  1. +1,439 −3 CalculateLSHParameters.m
  2. +8 −0 doc/matlab.html
View
1,442 CalculateLSHParameters.m
@@ -89,7 +89,7 @@
end
% Create the results structure
-results = struct('uHash', uHash, 'uCheck', uCheck, 'N', N, 'D', D, ...
+results = struct('uHash', uHash, 'uCheck', uCheck, 'N', N, ...
'multiprobeR', r);
results.dnnBins = dnnBins;
results.dnnHist = dnnHist;
@@ -287,7 +287,7 @@
Cc * (binAnyProb(simpleBin)/binNnProb(simpleBin))^simpleK;
fprintf('Simple Approximation:\n');
-fprintf('\tFor %d %d-d data use: ', N, D);
+fprintf('\tFor %d points of data use: ', N);
fprintf('w=%g and get %g hits per bin and %g nn.\n', ...
simpleW, binAnyProb(simpleBin), ...
binNnProb(simpleBin));
@@ -383,7 +383,7 @@
results.wExactL = binL;
fprintf('Exact Optimization:\n');
-fprintf('\tFor %d %d-d data use: ', N, D);
+fprintf('\tFor %d points of data use: ', N);
fprintf('w=%g and get %g hits per bin and %g nn.\n', ...
optimalW, binAnyProb(optimalBin), ...
binNnProb(optimalBin));
@@ -565,3 +565,1439 @@
hold off
end
+
+%%%%%%%%%%%%%%%%%%% JLAB Routines %%%%%%%%%%%%%%%%%%%%%%%%%
+% The following routines were written by J. M. Lilly
+% as part of the Matlab jlab package. The entire package can be found at
+% http://www.jmlilly.net/jmlsoft.html
+% I am grateful for permission to include Dr. Lilly's PDF code in this
+% package.
+%%%%%%%%%%%%%%%%%%% JLAB Routines %%%%%%%%%%%%%%%%%%%%%%%%%
+
+%JLAB_LICENSE License statement and permissions for JLAB package.
+%
+% Copyright (C) 1993--2011 J.M. Lilly
+% _______________________________________________________________________
+%
+% Citation
+%
+% If you use this software in research resulting in a scientific
+% publication, the software should be acknowledged and cited as
+%
+% Lilly, J. M. (2011), JLAB: Matlab freeware for data analysis,
+% Version 0.92, http://www.jmlilly.net/software.html.
+% _______________________________________________________________________
+%
+% License
+%
+% JLAB is distributed under the
+%
+% "Creative Commons Attribution Noncommercial-Share Alike License"
+%
+% Version 3.0, available at
+%
+% http://creativecommons.org/licenses/by-nc-sa/3.0/us/
+%
+% You are free:
+%
+% To Share -- To copy, distribute and transmit the work
+%
+% To Remix -- To adapt the work
+%
+% Under the following conditions:
+%
+% Attribution -- You must attribute the work in the manner specified
+% by the author or licensor (but not in any way that suggests that
+% they endorse you or your use of the work).
+%
+% Noncommercial -- You may not use this work for commercial purposes.
+%
+% Share Alike -- If you alter, transform, or build upon this work,
+% you may distribute the resulting work only under the same or
+% similar license to this one.
+%
+% See the above link for the full text of the license.
+% _______________________________________________________________________
+%
+% Disclaimer
+%
+% This software is provided 'as-is', without any express or implied
+% warranty. In no event will the author be held liable for any damages
+% arising from the use of this software.
+% _______________________________________________________________________
+%
+% This is part of JLAB --- type 'help jlab' for more information
+% (C) 1993--2011 J.M. Lilly --- type 'help jlab_license' for details
+
+function[f]=simplepdf(x,mu,sig,flag)
+%SIMPLEPDF Gaussian, uniform, Cauchy, and exponential pdfs.
+%
+% F=SIMPLEPDF(X,MU,SIG,'gaussian') computes a Gaussian pdf with mean
+% MU and standard deviation SIG.
+%
+% F=SIMPLEPDF(X,MU,SIG,'boxcar') computes a uniform pdf with mean MU
+% and standard deviation SIG.
+%
+% F=SIMPLEPDF(X,XO,ALPHA,'cauchy') computes a Cauchy pdf with location
+% parameter XO and scale parameter ALPHA.
+%
+% F=SIMPLEPDF(X,BETA,'exponential') computes an exponential pdf with
+% scale parameter, hence mean and standard deviation, equal to BETA.
+%
+% 'simplepdf --f' generates a sample figure
+%
+% Usage: f=simplepdf(x,mu,sig,'gaussian');
+% f=simplepdf(x,mu,sig,'boxcar');
+% f=simplepdf(x,xo,alpha,'cauchy');
+% f=simplepdf(x,beta,'exponential');
+% __________________________________________________________________
+% This is part of JLAB --- type 'help jlab' for more information
+% (C) 2001--2008 J.M. Lilly --- type 'help jlab_license' for details
+
+warning('off','MATLAB:divideByZero')
+
+if strcmp(x,'--f')
+ simplepdf_fig;
+ return
+end
+dx=x(2)-x(1);
+
+if nargin==3
+ flag=sig;
+end
+
+if nargin<3&&strcmp(flag,'exponential')||nargin<4&&~strcmp(flag,'exponential')
+ error('Not enough input arguments.')
+end
+
+if strcmp(flag,'gaussian')
+ f=exp(-(x-mu).^2./2./sig.^2)./sig./sqrt(2*pi);
+elseif strcmp(flag,'boxcar')
+ f=0*x;
+ ia=min(find(x-mu>-3.4641*sig/2))-1;
+ ib=min(find(x-mu>3.4641*sig/2));
+ f(ia:ib)=1;
+ f=f./vsum(f*dx,1);
+elseif strcmp(flag,'cauchy')
+ alpha=sig;
+ f=frac(alpha./pi,(x-mu).^2 + alpha.^2);
+elseif strcmp(flag,'exponential')
+ f=frac(1,mu).*exp(-abs(x)./mu);
+end
+
+
+warning('on','MATLAB:divideByZero')
+
+function[]=simplepdf_fig
+
+x=(-100:.1:100)';
+mu=25;
+sig=10;
+f=simplepdf(x,mu,sig,'gaussian');
+%[mu2,sig2]=pdfprops(x,f);
+figure,plot(x,f),vlines(mu,'r')
+%a=conflimit(x,f,95);
+%vlines(mu+a,'g'),vlines(mu-a,'g')
+title('Gaussian with mean 25 and standard deviation 10')
+function[fz]=pdfmult(xi,yi,fx,fy,zi)
+%PDFMULT Probability distribution from multiplying two random variables.
+%
+% FZ=PDFMULT(XI,YI,FX,FY,ZI), given two probability distribution
+% functions FX and FY defined over XI and YI, returns the pdf FZ
+% corresponding to Z=X*Y over values ZI.
+%
+% PDFMULT uses PDFDIVIDE.
+%
+% Usage: yn=pdfmult(xi,yi,fx,fy,zi);
+%
+% 'pdfmult --f' generates a sample figure.
+% __________________________________________________________________
+% This is part of JLAB --- type 'help jlab' for more information
+% (C) 2001--2009 J.M. Lilly --- type 'help jlab_license' for details
+
+if strcmp(xi,'--f')
+ pdfmult_fig;
+ return
+end
+
+vcolon(xi,yi,fx,fy,zi);
+fyi=jinterp(yi,fy,zi);
+fxi=jinterp(xi,fx,zi);
+vswap(fyi,nan,0);
+vswap(fxi,nan,0);
+fyinv=pdfinv(zi,fyi);
+fz=pdfdivide(zi,zi,fxi,fyinv,zi);
+[mu,sigma]=pdfprops(zi,fz);
+
+function[]=pdfmult_fig
+
+dx=0.1;
+dy=0.05;
+dz=0.025;
+s1=1;
+s2=2;
+xi=(-10:dx:10)';
+yi=(-10:dy:10)';
+zi=(-10:dz:10)';
+
+fx=simplepdf(xi,0,s1,'gaussian');
+fy=simplepdf(yi,0,s2,'gaussian');
+
+fz0=s1.*s2./pi./(s2.^2.*xi.^2+s1.^2);
+fz0=fz0./vsum(fz0*dx,1);
+fz=pdfmult(xi,yi,fx,fy,zi);
+
+figure,plot(zi,fz),hold on,plot(xi,fx)
+plot(yi,fy)
+linestyle default
+title('RV with green pdf multiplied by RV with red pdf equals RV with blue pdf')
+x1=randn(100000,1)*s1;
+y1=randn(100000,1)*s2;
+[fz1,n]=hist(x1.*y1,(-10:.1:10));
+plot(n,fz1/10000,'.')
+
+text(4,0.4,'Green and red are Gaussian')
+text(4,0.35,'Blue is disribution of product')
+text(4,0.30,'Dots are from a random trial')
+
+axis([-10 10 0 0.45])
+function[varargout]=vcolon(varargin)
+%VCOLON Condenses its arguments, like X(:).
+%
+% [Y1,Y2, ... YN]=VCOLON(X1,X2, ... XN) is equivalent to
+%
+% Y1=X1(:); Y2=X2(:); ... YN=XN(:);
+%
+% VCOLON(X1,X2,...XN) with no output arguments overwrites the
+% original input variables.
+% __________________________________________________________________
+% This is part of JLAB --- type 'help jlab' for more information
+% (C) 2000, 2004 J.M. Lilly --- type 'help jlab_license' for details
+
+if strcmp(varargin{1}, '--t')
+ vcolon_test,return
+end
+
+for i=1:nargin
+ x=varargin{i};
+ varargout{i}=x(:);
+end
+
+eval(to_overwrite(nargin));
+
+
+function[]=vcolon_test
+x=[1 3; 2 4];
+y=x;
+
+vcolon(x,y);
+reporttest('VCOLON ', all(x==(1:4)'&y==(1:4)'))
+function[]=reporttest(str,bool)
+%REPORTTEST Reports the result of an m-file function auto-test.
+%
+% Called by JLAB_RUNTESTS.
+% _________________________________________________________________
+% This is part of JLAB --- type 'help jlab' for more information
+% (C) 2003--2009 J.M. Lilly --- type 'help jlab_license' for details
+
+
+global BOOL_JLAB_RUNTEST
+global FUNCTION_NUMBER
+global FUNCTION_NUMBER_ARRAY
+
+FUNCTION_NUMBER_ARRAY=[FUNCTION_NUMBER_ARRAY;FUNCTION_NUMBER];
+
+if bool
+ disp([str ' test: passed'])
+ BOOL_JLAB_RUNTEST=[BOOL_JLAB_RUNTEST;1];
+else
+ disp([str ' test: FAILED'])
+ BOOL_JLAB_RUNTEST=[BOOL_JLAB_RUNTEST;0];
+end
+function[str]=to_overwrite(N)
+%TO_OVERWRITE Returns a string to overwrite original arguments.
+%
+% STR=TO_OVERWRITE(N), when called from within an m-file which has
+% VARARGIN for the input variable, returns a string which upon
+% EVAL(STR) will cause the first N input variables in the caller
+% workspace with the values contained in the first N elements of
+% VARARGOUT.
+%
+% See also TO_GRAB_FROM_CALLER.
+%
+% Usage: eval(to_overwrite(N))
+% __________________________________________________________________
+% This is part of JLAB --- type 'help jlab' for more information
+% (C) 2001--2006 J.M. Lilly --- type 'help jlab_license' for details
+
+str{1}= 'if nargout==0';
+str{end+1}= ' global ZZoutput';
+str{end+1}= ' evalin(''caller'',[''global ZZoutput''])';
+str{end+1}=[' for i=1:' int2str(N)];
+str{end+1}= ' if ~isempty(inputname(i))';
+str{end+1}= ' ZZoutput=varargout{i};';
+str{end+1}= ' assignin(''caller'',inputname(i), ZZoutput)';
+str{end+1}= ' end';
+str{end+1}= ' end';
+str{end+1}=' evalin(''caller'',[''clear ZZoutput''])';
+str{end+1}='end';
+
+str=strs2row(str);
+
+
+function[row]=strs2row(x)
+%STRS2ROW Converts a cell array of strings into a row array
+
+M=length(x);
+for i=1:M
+ n(i)=length(x{i});
+end
+N=max(n);
+
+row=[];
+
+for i=1:M
+ row=[row,char(10),x{i}];
+end
+function[yi]=jinterp(x,y,xi,str)
+%JINTERP Matrix-matrix 1-D interpolation.
+%
+% YI=JINTERP(X,Y,XI), returns the linear interpolation of Y onto XI
+% based on the functional relationship Y(X).
+%
+% Unlike INTERP1, JINTERP allows X,Y, and XI to be either vectors or
+% matrices. If more than one argument is a matrix, those matrices must
+% be of the same size. YI is a matrix if any input argument is a
+% matrix. All vectors should be column vectors and all matrices should
+% have data in columns.
+%
+% Also, only data points of XI in between the maximum and minimum
+% values of X are interpolated.
+%
+% This useful, for example, in interpolating section data with
+% nonuniform pressure levels onto standard levels.
+%
+% See also INTERP1.
+% __________________________________________________________________
+% This is part of JLAB --- type 'help jlab' for more information
+% (C) 2000--2008 J.M. Lilly --- type 'help jlab_license' for details
+if nargin~=4
+ str='linear';
+end
+
+%convert row vectors to column vectors
+if size(x,1)==1
+ x=conj(x');
+end
+if size(y,1)==1
+ y=conj(y');
+end
+if size(xi,1)==1
+ xi=conj(xi');
+end
+
+%ensure sizes are compatible
+Lx=size(x,2);
+Ly=size(y,2);
+Lxi=size(xi,2);
+maxL=max([Lx Ly Lxi]);
+bool=(Lx==1|Lx==maxL)&(Ly==1|Ly==maxL)&(Lxi==1|Lxi==maxL);
+if ~bool,
+ error('Arguments are not of compatible size')
+end
+
+%convert vectors to matrices
+if Lx==1
+ x=x*ones(1,maxL);
+end
+if Ly==1
+ y=y*ones(1,maxL);
+end
+if Lxi==1
+ xi=xi*ones(1,maxL);
+end
+
+yi=nan*ones(size(xi,1),maxL);
+
+%check x for monotonicity
+mdx=min(min(diff(x)));
+if mdx<=0
+ disp('Ensuring monotonicity of X by adding noise and sorting.')
+ mx=min(min(x));
+ x=x+randn(size(x))/1000/1000;
+ x=sort(x,1);
+end
+
+for i=1:size(x,2)
+ colmin=min(x(isfinite(x(:,i)),i));
+ colmax=max(x(isfinite(x(:,i)),i));
+
+% a=min(find(xi(:,i)>=colmin));
+% b=max(find(xi(:,i)<=colmax));
+ index=find(xi(:,i)>=colmin&xi(:,i)<=colmax&isfinite(xi(:,i)));
+
+ if ~isempty(index)>=0,
+ yi(index,i)=interp1(x(:,i),y(:,i),xi(index,i),str);
+ end
+end
+
+
+
+
+function[b]=allall(x)
+%ALLALL(X)=ALL(X(:))
+% _________________________________________________________________
+% This is part of JLAB --- type 'help jlab' for more information
+% (C) 2004 J.M. Lilly --- type 'help jlab_license' for details
+b=all(x(:));
+function[fz]=pdfinv(yi,fy)
+%PDFINV Probability distribution of the inverse of a random variable.
+%
+% YN=PDFMULT(YI,FY) given a probability distribution functions FY
+% defined over YI, returns the pdf of the inverse random variable 1/Y.
+%
+% 'pdfinv --t' runs a test
+% 'pdfinv --f' generates a sample figure
+% __________________________________________________________________
+% This is part of JLAB --- type 'help jlab' for more information (C)
+% 2001, 2004 J.M. Lilly --- type 'help jlab_license' for details
+
+if strcmp(yi,'--t')
+ pdfinv_test;
+ return
+end
+
+if strcmp(yi,'--f')
+ pdfinv_fig;
+ return
+end
+
+%tol=1e-10;
+%index=find(yi==0);
+%if ~isempty(index)
+% yi(index)=1e-10;
+%end
+
+index=1:round(length(yi)/2)-1;
+N=round(length(yi)/2)-1;
+
+%index=(N:-1:1 length(yi):-1:N+1);
+%fz=pdfchain(yi(index),fy(index),1./yi(index),yi);
+warning('off','MATLAB:divideByZero')
+fz=pdfchain(yi,fy,1./yi,yi);
+warning('on','MATLAB:divideByZero')
+
+vswap(fz,nan,0);
+
+function[]=pdfinv_test
+
+alpha=2;
+
+dy=0.01;
+yi=(-40:dy:40)';
+fx=simplepdf(yi,0,alpha,'cauchy');
+fy=simplepdf(yi,0,1./alpha,'cauchy');
+fy2=pdfinv(yi,fx);
+
+tol=1e-3;
+bool=vmean(abs(fy-fy2).^2,1)<tol;
+reporttest('PDFINV for Cauchy, Papoulis special case p. 94',bool)
+
+function[]=pdfinv_fig
+
+s2=2;
+dy=0.01;
+yi=(-40:dy:40)';
+fy=simplepdf(yi,0,s2,'gaussian');
+
+fz=pdfinv(yi,fy);
+
+y1=randn(100000,1)*s2;
+[fz1,n]=hist(1./y1,(-11:.1:11));
+
+figure,
+plot(yi,fz)
+hold on
+plot(n,fz1/10000,'.'),xlim([-10 10])
+title('PDF of the inverse of a Gaussian RV')
+text(4,0.30,'Dots are from a random trial')
+function[fy]=pdfchain(x,fx,g,yi)
+%PDFCHAIN The "chain rule" for probabilty density functions.
+%
+% FY=PDFCHAIN(X,FX,G,Y), where FX is a probability density function
+% defined over values X, and G is some function of X, returns the
+% probility density function of random variable G(X) over values Y.
+% __________________________________________________________________
+% This is part of JLAB --- type 'help jlab' for more information
+% (C) 2001, 2004 J.M. Lilly --- type 'help jlab_license' for details
+
+warning('off','MATLAB:divideByZero')
+
+vcolon(g,x,fx);
+
+index=find(~isnan(x)&~isnan(fx)&~isnan(g));
+
+x=x(index);
+fx=fx(index);
+g=g(index);
+
+[g,index]=sort(g);
+vindex(x,fx,index,1);
+
+gprime=vdiff(g,1);
+%gprime=gprime*ones(size(fx(1,:)));
+%x=x*ones(size(fx(1,:)));
+%g=g*ones(size(fx(1,:)));
+
+fyx=fx./abs(gprime);
+fyx(1)=0;
+fyx(end)=0;
+index=find(~isfinite(fyx)|fyx==0);
+index=index(2:end-1);
+if ~isempty(index)
+ fyx(index)=fyx(index-1)./2+fyx(index+1)./2;
+end
+%figure,plot(fyx)
+fy=jinterp(g,fyx,yi);
+
+dy=yi(2)-yi(1);
+fy=fy./(ones(size(fy(:,1)))*vsum(fy*dy,1));
+
+warning('on','MATLAB:divideByZero')
+
+function[varargout]=vindex(varargin)
+%VINDEX Indexes an N-D array along a specified dimension.
+%
+% Y=VINDEX(X,INDEX,DIM) indexes the multidimensional array X along
+% dimension DIM. This is equivalent to
+%
+% 1 2 DIM DIMS(X)
+% | | | |
+% Y=X(:,:, ... INDEX, ..., :);
+%
+% where the location of INDEX is specified by DIM.
+%
+% VINDEX is defined to return an empty array if INDEX is empty.
+%
+% Note that VINDEX does not index along singleton dimensions, thus
+% when X is a column vector, VINDEX(X,INDEX,2) returns X.
+%
+% [Y1,Y2,...YN]=VINDEX(X1,X2,...XN,INDEX,DIM) also works.
+%
+% VINDEX(X1,X2,...XN,INDEX,DIM); with no output arguments overwrites
+% the original input variables.
+%
+% VINDEX also supports logical indexing with INDEX a boolean array
+% of the same size as the dimension being indexed.
+%
+% See also VINDEXINTO, SQUEEZE, DIMS, PERMUTE, SHIFTDIM.
+%
+% 'vindex --t' runs a test.
+% __________________________________________________________________
+% This is part of JLAB --- type 'help jlab' for more information
+% (C) 2001--2009 J.M. Lilly --- type 'help jlab_license' for details
+
+
+if strcmp(varargin{1}, '--t')
+ vindex_test,return
+end
+
+index=varargin{end-1};
+dim=varargin{end};
+
+nvars=nargin-2;
+vars=varargin(1:nvars);
+
+%eval(to_grab_from_caller(2)) %assigns vars, varnames, nvars
+
+for i=1:nvars
+ varargout{i}=vindex1(vars{i},index,dim);
+end
+
+eval(to_overwrite(nargin-2));
+
+%now to_overwrite uses
+%varnames not inputnames ... and does not take input argument
+
+function[y]=vindex1(x,index,dim)
+
+y=[];
+if ~isempty(x)
+ if size(x,dim)==1
+ %X has only one element along dimension DIM; do nothing
+ if ~isempty(index)
+ y=x;
+ end
+ else
+ %You would think Matlab would provide a simpler way to do this.
+ str='y=x(';
+ ndx=length(find(size(x)>=1));
+ if ~isempty(index)
+ for i=1:ndx
+ if i~=dim
+ str=[str ':,'];
+ else
+ str=[str 'index,'];
+ end
+ end
+ str=[str(1:end-1) ');'];
+ eval(str);
+ end
+ end
+end
+
+function[]=vindex_test
+x1=[1 1; 2 2];
+index=2;
+ans1=x1(:,index);
+vindex(x1,index,2);
+reporttest('VINDEX col case', aresame(x1,ans1))
+
+x1=[1 1; 2 2];
+index=2;
+ans1=x1(index,:);
+vindex(x1,index,1);
+reporttest('VINDEX row case', aresame(x1,ans1))
+
+x1=[1 1; 2 2];
+index=[false; true];
+ans1=x1(:,index);
+vindex(x1,index,2);
+reporttest('VINDEX col case, logical', aresame(x1,ans1))
+
+x1=[1 1; 2 2];
+index=[false; true];
+ans1=x1(index,:);
+vindex(x1,index,1);
+reporttest('VINDEX row case, logical ', aresame(x1,ans1))
+
+x1=[1 2];
+index=1:10;
+ans1=x1;
+vindex(x1,index,1);
+reporttest('VINDEX row vector indexed along rows case', aresame(x1,ans1))
+
+x1=[1 2]';
+index=1:10;
+ans1=x1;
+vindex(x1,index,2);
+reporttest('VINDEX column vector indexed along columns case', aresame(x1,ans1))
+
+x1=[1 2]';
+index=[];
+ans1=[];
+vindex(x1,index,2);
+reporttest('VINDEX empty index case', aresame(x1,ans1))
+
+x1=[];
+index=(1:2);
+ans1=[];
+vindex(x1,index,2);
+reporttest('VINDEX empty array case', aresame(x1,ans1))
+function[varargout]=vdiff(varargin)
+%VDIFF Length-preserving first central difference.
+%
+% DX=VDIFF(X,DIM) differentiates X along dimension DIM using the first
+% central difference; DX is the same size as X.
+%
+% [D1,D2,...,DN]=VDIFF(X1,X2,...,XN,DIM) for multiple input variables
+% also works.
+%
+% VDIFF(X1,X2,...,DIM); with no output arguments overwrites the
+% original input variables.
+%
+% DXDT=VDIFF(DT,...) optionally uses scalar timestep DT to approximate
+% a time derivative, i.e. DXDT equals DX divided by DT.
+% _____________________________________________________________________
+%
+% First and last points
+%
+% The first and last points must be treated differently, as the central
+% difference is not defined there. Three different methods can be used.
+%
+% VDIFF(...,STR) specifies which method to use.
+%
+% 'endpoint' uses the first forwards / first backwards difference
+% at the first and last point, respectively.
+% 'periodic' treats the array as being periodic along dimension DIM,
+% so that the central difference is defined at endpoints.
+% 'nans' fills in the first and last values with NANs.
+%
+% The default behavior is 'endpoint'.
+% _____________________________________________________________________
+%
+% 'vdiff --t' runs some tests.
+%
+% Usage: x=vdiff(x,dim);
+% x=vdiff(dt,x,dim);
+% x=vdiff(dt,x,dim,'periodic');
+% __________________________________________________________________
+% This is part of JLAB --- type 'help jlab' for more information
+% (C) 2000--2011 J.M. Lilly --- type 'help jlab_license' for details
+
+% I am so irritated by diff
+
+
+if strcmp(varargin{1}, '--t')
+ vdiff_test,return
+end
+
+
+if length(varargin{1})==1
+ dt=varargin{1};
+ varargin=varargin(2:end);
+else
+ dt=1;
+end
+
+if ischar(varargin{end})
+ str=varargin{end};
+ varargin=varargin(1:end-1);
+else
+ str='endpoints';
+end
+
+%if length(varargin{end})==1
+ n=varargin{end};
+ varargin=varargin(1:end-1);
+%else
+ % n=1;
+%end
+
+for i=1:length(varargin)
+ varargout{i}=vdiff1(varargin{i},n,str)./dt;
+end
+
+if nargin>1
+ eval(to_overwrite(length(varargin)))
+end
+
+function[y]=vdiff1(x,n,str)
+
+if ~isempty(x)
+ y=vshift(x,1,n)./2-vshift(x,-1,n)./2;
+ %y=vshift(x,1,n)-x;
+
+ if strcmp(str(1:3),'end')
+ y=vindexinto(y,vindex(x,2,n)-vindex(x,1,n),1,n);
+ y=vindexinto(y,vindex(x,size(x,n),n)-vindex(x,size(x,n)-1,n),size(x,n),n);
+ %y(1,:)=x(2,:)-x(1,:);
+ %y(end,:)=x(end,:)-x(end-1,:);
+ elseif strcmp(str(1:3),'nan')
+ y=vnan(y,1,n);
+ y=vnan(y,size(y,n),n);
+ elseif strcmp(str(1:3),'per')
+ %Do nothing
+ end
+else
+ y=[];
+end
+
+function[]=vdiff_test
+
+y1=(1:4)';
+y2=2*(1:4)';
+[x1,x2]=vdiff(y1,y2,1);
+bool=aresame(x1,[1 1 1 1]').*aresame(x2,2*[1 1 1 1]');
+reporttest('VDIFF', bool)
+vdiff(y1,y2,1);
+bool=aresame(y1,[1 1 1 1]').*aresame(y2,2*[1 1 1 1]');
+reporttest('VDIFF output overwrite', bool)
+
+dt=pi;
+y1=(1:4)';
+y2=2*(1:4)';
+[x1,x2]=vdiff(pi,y1,y2,1);
+bool=aresame(x1,[1 1 1 1]'./dt).*aresame(x2,2*[1 1 1 1]'./dt,1e-10);
+reporttest('VDIFF with non-unit time step', bool)
+
+function[varargout]=vshift(varargin)
+% VSHIFT Cycles the elements of an array along a specified dimension.
+%
+% Y=VSHIFT(X,N,DIM) cycles the elements of X N places along dimension DIM.
+%
+% Example: x=[1 2 3 4 5];
+% vshift(x,+1,2)=[2 3 4 5 1]
+% vshift(x,-1,2)=[5 1 2 3 4]
+%
+% Note shifting by N and then by -N recovers the original array.
+%
+% [Y1,Y2,...YN]=VSHIFT(X1,X2,...XN,N,DIM) also works.
+%
+% VSHIFT(X1,X2,...XN,N,DIM); with no arguments overwrite the original
+% input variables.
+%
+% ------------------------------------------------------------------
+% Y=VSHIFT(X,N,DIM,INDEX,DIM2) applies this shift selectively, only to
+% that subset of X obtained by indexing X with INDEX along DIM2, i.e.
+%
+% 1 2 DIM2 DIMS(X)
+% | | | |
+% X(:,:, ... INDEX, ..., :)
+%
+% is cycled N places along dimension DIM, but the remainder of X is not.
+% DIM and DIM2 cannot be the same. The above extensions to multiple
+% output varibles work in this case as well.
+% ------------------------------------------------------------------
+%
+% See also: VINDEX
+% __________________________________________________________________
+% This is part of JLAB --- type 'help jlab' for more information
+% (C) 2001--2006 J.M. Lilly --- type 'help jlab_license' for details
+
+
+if strcmp(varargin{1}, '--t')
+ vshift_test,return
+end
+
+%/********************************************************
+%Sort out input arguments
+nax=2;
+if nargin>4
+ if length(varargin{end-3}(:))==1
+ nax=4;
+ dim2=(varargin{end});
+ jj=varargin{end-1}(:);
+ dim=varargin{end-2};
+ n=varargin{end-3};
+ if dim==dim2
+ error('DIM and DIM2 cannot be the same.')
+ end
+ %n, jj, dim,dim2
+ end
+end
+
+if nax==2
+ dim=varargin{end};
+ n=varargin{end-1};
+end
+%\********************************************************
+
+for i=1:length(varargin)-nax
+ if nax==2
+ varargout{i}=vshift1(varargin{i},n,dim);
+ else
+ varargout{i}=vshift1(varargin{i},n,dim,jj,dim2);
+ end
+end
+eval(to_overwrite(nargin-nax))
+
+
+function[y]=vshift1(x,n,ndim,jj,ndim2)
+
+N=size(x,ndim);
+if n>0
+ ii=[(n+1:N) (1:n)];
+elseif n<0
+ n=-n;
+ ii=[(N-(n-1):N) (1:N-n)];
+elseif n==0
+ ii=(1:N);
+end
+
+if nargin==3
+ y=vindex(x,ii,ndim);
+else
+ y1=vindex(x,jj,ndim2);
+ y1=vindex(y1,ii,ndim);
+ %vsize(x,y1,jj,ndim2);
+ %x,y1,ii,jj,ndim2
+ y=vindexinto(x,y1,jj,ndim2);
+end
+
+
+function[]=vshift_test
+x=(1:10);
+ans1=[(2:10) 1];
+reporttest('VSHIFT col case', aresame(vshift(x,1,2),ans1))
+
+x=(1:10)';
+ans1=[10 (1:9)]';
+reporttest('VSHIFT row case', aresame(vshift(x,-1,1),ans1))
+
+clear x ans1
+x(:,:,1)=[1 2; 3 4];
+x(:,:,2)=2*[1 2; 3 4];
+ans1(:,:,2)=x(:,:,1);
+ans1(:,:,1)=x(:,:,2);
+reporttest('VSHIFT mat case', aresame(vshift(x,1,3),ans1))
+
+clear x ans1
+x(:,:,1)=[1 2; 3 4];
+x(:,:,2)=2*[1 2; 3 4];
+ans1(:,:,1)=[3 2;1 4];
+ans1(:,:,2)=2*[3 2;1 4];
+reporttest('VSHIFT mat selective case one', aresame(vshift(x,1,1,1,2),ans1))
+
+clear x ans1
+x(:,:,1)=[1 2; 3 4];
+x(:,:,2)=2*[1 2; 3 4];
+ans1(:,:,1)=[3 4;1 2];
+ans1(:,:,2)=2*[3 4;1 2];
+reporttest('VSHIFT mat selective case two', aresame(vshift(x,1,1,1:2,2),ans1))
+
+function[varargout]=vindexinto(varargin)
+%VINDEXINTO Indexes into N-D array along a specified dimension.
+%
+% Y=VINDEXINTO(Y,X,INDEX,DIM) indexes the array X into the multi-
+% dimensional array Y along dimension DIM. This is equivalent to
+%
+% 1 2 DIM DIMS(X)
+% | | | |
+% Y(:,:, ... INDEX, ..., :)=X;
+%
+% where the location of INDEX is specified by DIM. X must have the
+% exact same size as the block it replaces, or be a scalar.
+%
+% VINDEXINTO is defined leave Y unchanged if INDEX is empty, and to
+% ignore NANs and INFs in INDEX.
+%
+% VINDEXINTO(Y,X,INDEX,0) with DIM=0 is equivalent to Y(INDEX)=X;
+%
+% [Y1,Y2,...YN]=VINDEXINTO(Y1,Y2,...YN,X1,X2,...XN,INDEX,DIM) also
+% works.
+%
+% VINDEXINTO(Y1,Y2,...YN,X1,X2,...XN,INDEX,DIM); with no output
+% arguments overwrites the original input variables ,Y2,...YN.
+%
+% See also VINDEX, SQUEEZE, DIMS, PERMUTE, SHIFTDIM
+%
+% 'vindexinto --t' runs a test.
+% __________________________________________________________________
+% This is part of JLAB --- type 'help jlab' for more information
+% (C) 2005--2006 J.M. Lilly --- type 'help jlab_license' for details
+
+if strcmp(varargin{1}, '--t')
+ vindexinto_test,return
+end
+
+index=varargin{end-1};
+dim=varargin{end};
+
+nvars=nargin-2;
+if ~iseven(nvars)
+ error('There should be an even number of input arguments.')
+end
+
+vars=varargin(1:nvars/2);
+fromvars=varargin(nvars/2+1:nvars);
+
+for i=1:nvars/2
+varargout{i}=vindexinto1(vars{i},fromvars{i},index,dim);
+end
+eval(to_overwrite(nvars/2));
+
+function[y]=vindexinto1(y,x,index,dim)
+%You would think Matlab would provide a simpler way to do this.
+
+if dim==0
+ y(index)=x;
+else
+ str='y(';
+
+ %[index,sorter]=sort(index);
+ %x=x(sorter);
+
+ ii=find(isfinite(index));
+ if ~isempty(ii)
+ index=index(ii);
+ else
+ x=[];
+ index=[];
+ end
+
+
+ ndx=length(find(size(y)>=1));
+ if ~isempty(index) && ~isempty(x)
+ for i=1:ndx
+ if i~=dim
+ str=[str ':,'];
+ else
+ str=[str 'index,'];
+ end
+ end
+ str=[str(1:end-1) ')=x;'];
+ eval(str);
+ end
+end
+
+if any(~isfinite(y(:)))
+ if all(isreal(y(isfinite(y))))
+ y(~isfinite(y(:)))=nan;
+ else
+ y(~isfinite(y(:)))=nan+sqrt(-1)*nan;
+ end
+end
+
+
+function[]=vindexinto_test
+y1=[1 1; 2 2];
+index=2;
+x=[5 6]';
+ans1=y1;
+ans1(:,2)=x;
+vindexinto(y1,x,index,2);
+reporttest('VINDEXINTO col case', aresame(y1,ans1))
+
+y1=[1 1; 2 2];
+index=2;
+x=[5 6];
+ans1=y1;
+ans1(2,:)=x;
+vindexinto(y1,x,index,1);
+reporttest('VINDEXINTO row case', aresame(y1,ans1))
+
+clear y1 ans1
+y1(:,:,1)=[1 2; 3 4];
+y1(:,:,2)=2*[1 2; 3 4];
+index=1;
+x=[5 6]';x=vrep(x,2,3);
+ans1(:,:,1)=[5 6; 3 4];
+ans1(:,:,2)=[5 6; 2*3 2*4];
+vindexinto(y1,x,index,1);
+reporttest('VINDEXINTO 3-D col case', aresame(y1,ans1))
+
+vindexinto(y1,[],index,1);
+reporttest('VINDEXINTO empty x case', aresame(y1,ans1))
+
+
+y1=[1 1; 2 2];
+index=[1 4];
+x=[3 5];
+ans1=[3 1; 2 5];
+vindexinto(y1,x,index,0);
+reporttest('VINDEXINTO DIM=0 case', aresame(y1,ans1))
+function[bool]=iseven(x)
+%ISEVEN Tests whether the elements of an array are even
+% _________________________________________________________________
+% This is part of JLAB --- type 'help jlab' for more information
+% (C) 2001, 2004 J.M. Lilly --- type 'help jlab_license' for details
+
+bool=floor(x/2)==x/2;
+function[varargout] = vsum(varargin)
+%VSUM Sum over finite elements along a specified dimension.
+%
+% Y=VSUM(X,DIM) takes the sum of all finite elements of X along
+% dimension DIM.
+%
+% [Y,NUM]=VSUM(X,DIM) also outputs the number of good data points NUM,
+% which has the same dimension as X.
+%
+% [Y1,Y2,...YN]=VSUM(X1,X2,...XN,DIM) also works.
+%
+% VSUM(X1,X2,...XN,DIM); with no output arguments overwrites the
+% original input variables.
+% __________________________________________________________________
+% This is part of JLAB --- type 'help jlab' for more information
+% (C) 2001, 2004 J.M. Lilly --- type 'help jlab_license' for details
+
+if strcmp(varargin{1}, '--t')
+ vsum_test,return
+end
+
+dim=varargin{end};
+
+for i=1:length(varargin)-1
+ [varargout{i},numi{i}]=vsum1(varargin{i},dim);
+end
+
+for i=length(varargin):nargout
+ varargout{i}=numi{i-length(varargin)+1};
+end
+
+eval(to_overwrite(nargin-1))
+
+function[y,num]=vsum1(x,dim)
+
+%find sum of all good data points
+bnan=~isfinite(x);
+nani=find(bnan);
+clear bnan
+if ~isempty(nani)
+ x(nani)=0;
+end
+y=sum(x,dim);
+
+%find number of good data points
+if ~isempty(nani)
+ x(nani)=nan;
+end
+clear nani
+x=~isfinite(x);
+x=~x;
+num=sum(x,dim);
+
+index=find(num==0);
+if ~isempty(index)
+ y(index)=nan;
+end
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+function[]=vsum_test
+x1=[1 2 ; nan 4];
+x2=[inf 6; nan 5];
+ans1=[3 4]';
+ans2=[6 5]';
+
+vsum(x1,x2,2);
+reporttest('VSUM output overwrite', aresame(x1,ans1) && aresame(x2,ans2))
+
+x1=[1 2 ; nan 4];
+ans1=[3 4]';
+ans2=[2 1]';
+
+[y1,y2]=vsum(x1,2);
+reporttest('VSUM sum & num', aresame(y1,ans1) && aresame(y2,ans2))
+
+
+x1=[1 2 ; 0 4];
+ans1=[3 4]';
+ans2=[2 2]';
+
+[y1,y2]=vsum(x1,2);
+reporttest('VSUM sum & num, no NaNs', aresame(y1,ans1) && aresame(y2,ans2))
+
+
+
+
+
+
+
+
+function[fz]=pdfdivide(xi,yi,fx,fy,zi)
+%PDFDIVIDE Probability distribution from dividing two random variables.
+%
+% YN=PDFDIVIDE(XI,YI,FX,FY,ZI) given two probability distribution
+% functions FX and FY, defined over XI and YI, returns the pdf FZ
+% corresponding to Z=X/Y over values ZI.
+%
+% For a discussion of the algorithm, see Papoulis (1991), page 138.
+%
+% Usage: yn=pdfdivide(xi,yi,fx,fy,zi);
+%
+% 'pdfdivide --f' generates a sample figure
+% __________________________________________________________________
+% This is part of JLAB --- type 'help jlab' for more information
+% (C) 2001, 2004 J.M. Lilly --- type 'help jlab_license' for details
+
+
+if strcmp(xi,'--f')
+ pdfdivide_fig;
+ return
+end
+
+dx=xi(2)-xi(1);
+
+vcolon(xi,yi,fx,fy);
+zi=conj(zi(:)');
+
+
+ym=yi*ones(size(zi));
+%fxm=fx*[1+0*zi];
+fym=fy*ones(size(zi));
+zm=ones(size(yi))*zi;
+zym=zm.*ym;
+
+fxmi=jinterp(xi,fx,zym);
+mat=abs(ym).*fxmi.*fym;
+fz=vsum(mat*dx,1)';
+
+dz=zi(2)-zi(1);
+fz=fz./vsum(fz*dz,1);
+[mu,sigma]=pdfprops(zi',fz);
+
+function[]=pdfdivide_fig
+
+%test with cauchy
+dx=0.1;
+dy=0.05;
+dz=0.025;
+s1=1;
+s2=2;
+xi=(-10:dx:10)';
+yi=(-10:dy:10)';
+zi=(-10:dz:10)';
+
+
+fx=simplepdf(xi,0,s1,'gaussian');
+fy=simplepdf(yi,0,s2,'gaussian');
+
+fz0=s1.*s2./pi./(s2.^2.*xi.^2+s1.^2);
+fz0=fz0./vsum(fz0*dx,1);
+fz=pdfdivide(xi,yi,fx,fy,zi);
+
+figure,plot(zi,fz),hold on,plot(xi,fx)
+plot(yi,fy)
+linestyle default
+title('RV with green pdf divided by RV with red pdf equals RV with blue pdf')
+text(4,0.4,'Green and red are Gaussian')
+text(4,0.35,'Blue is Cauchy')
+text(4,0.30,'Dots are from a random trial')
+
+x1=randn(100000,1)*s1;
+y1=randn(100000,1)*s2;
+[fz1,n]=hist(x1./y1,(-10:.1:10));
+plot(n,fz1/10000,'.')
+
+
+
+
+
+function[y]=frac(x1,x2)
+%FRAC FRAC(A,B)=A./B;
+% _________________________________________________________________
+% This is part of JLAB --- type 'help jlab' for more information
+% (C) 2004 J.M. Lilly --- type 'help jlab_license' for details
+warning('off','MATLAB:divideByZero')
+y=x1./x2;
+warning('on','MATLAB:divideByZero')
+function[varargout]=vrep(varargin)
+%VREP Replicates an array along a specified dimension.
+%
+% Y=VREP(X,N,DIM) replicates the (1-D) array by N times along
+% dimension DIM. For instance:
+%
+% VREP([1:4]',3,2)=[ [1:4]' [1:4]' [1:4]' ]
+%
+% This is often useful in array algebra.
+%
+% [Y1,Y2,...,YP]=VREP(X1,X2,...,XP,N,DIM) also works.
+%
+% See also VINDEX, DIM.
+% __________________________________________________________________
+% This is part of JLAB --- type 'help jlab' for more information
+% (C) 2001--2008 J.M. Lilly --- type 'help jlab_license' for details
+
+if strcmp(varargin{1}, '--t')
+ vrep_test,return
+end
+
+n=varargin{end-1};
+ndim=varargin{end};
+
+for i=1:length(varargin)-2
+ varargout{i}=vrep1(varargin{i},n,ndim);
+end
+
+eval(to_overwrite(nargin-2))
+
+%You would think Matlab would provide a simpler way to do this.
+function[y]=vrep1(x,n,dim)
+
+str='y=repmat(x,[';
+ndx=ndims(x);
+for i=1:max(ndx,dim)
+ if i~=dim
+ str=[str '1,'];
+ else
+ str=[str 'n,'];
+ end
+end
+str=[str(1:end-1) ']);'];
+eval(str);
+
+
+function[]=vrep_test
+
+ans1=vrep((1:4)',3,2);
+ans2=[ (1:4)' (1:4)' (1:4)' ];
+reporttest('VREP', aresame(ans1,ans2))
+
+x1=(1:4)';x2=(1:4)';
+vrep(x1,x2,3,2);
+reporttest('VREP output redirect', aresame(x1,ans1) && aresame(x2,ans2))
+function[mu,sigma,skew,kurt]=pdfprops(x,fx)
+%PDFPROPS Mean and variance associated with a probability distribution.
+%
+% [MU,SIGMA]=PDFPROPS(X,FX), given a probability distribution
+% function FX over values X, returns the mean MU and the standard
+% deviation SIGMA. Each column of X must have uniform spacing.
+%
+% The statistics are computed using a trapezoidal integration.
+% FX is multiplied by a constant so that it integrates to one.
+%
+% [MU,SIGMA,SKEW,KURT]=PDFPROPS(X,FX) also retuns the skewness and
+% the kurtosis, which are the third and fourth central moments,
+% respectively normalized by the third and fourth powers of the
+% standard deviation.
+%
+% 'pdfprops --t' runs a test.
+%
+% Usage: [mu,sigma]=pdfprops(x,fx);
+% [mu,sigma,skew,kurt]=pdfprops(x,fx);
+% __________________________________________________________________
+% This is part of JLAB --- type 'help jlab' for more information
+% (C) 2001--2009 J.M. Lilly --- type 'help jlab_license' for details
+
+if strcmp(x,'--t')
+ pdfprops_test;
+ return
+end
+
+if jisrow(x)
+ x=x(:);
+end
+if jisrow(fx)
+ fx=fx(:);
+end
+
+if size(x,2)==1
+ x=x*ones(size(fx(1,:)));
+end
+
+
+%dx=vrep(x(2,:)-x(1,:),size(x,1),1);
+dx=x(2,:)-x(1,:);
+fx=fx./vrep(trapint(fx,dx),size(x,1),1);
+mu=real(trapint(fx.*x,dx));
+murep=vrep(mu,size(x,1),1);
+sigma=sqrt(trapint((x-murep).^2.*fx,dx));
+if nargout>=3
+ skew=trapint((x-murep).^3.*fx,dx);
+ skew=skew./sigma.^3;
+end
+if nargout==4
+ kurt=trapint((x-murep).^4.*fx,dx);
+ kurt=kurt./sigma.^4;
+end
+
+
+% for i=1:size(fx,2)
+% if trapint(fx(:,i),dx(i))~=1
+% %disp('Normalizing FX to unit area.')
+% fx(:,i)=fx(:,i)./trapint(fx(:,i),dx(i));
+% end
+% end
+%
+% for i=1:size(fx,2)
+% mu(i,1)=real(trapint(fx(:,i).*x(:,i),dx(i)));
+% sigma(i,1)=sqrt(trapint((x(:,i)-mu(i,1)).^2.*fx(:,i),dx(i)));
+% end
+%
+
+
+function[y]=trapint(f,dx)
+%Trapezoidal integration
+
+fa=f;
+fb=vshift(fa,1,1);
+fa(1,:)=0;
+fb(1,:)=0;
+fa(end,:)=0;
+fb(end,:)=0;
+y=vsum(frac(fa+fb,2),1).*dx;
+vswap(y,0,1e-10);
+
+function[]=pdfprops_test
+x=(-30:.001:30)';
+
+mu0=2;
+sigma0=5;
+
+f=simplepdf(x,mu0,sigma0,'gaussian'); %f=simplepdf(x,mu,sig,flag)
+[mug,sigmag,skewg,kurtg]=pdfprops(x,f);
+
+f=simplepdf(x,mu0,sigma0,'boxcar'); %f=simplepdf(x,mu,sig,flag)
+[mu,sigma]=pdfprops(x,f);
+tol=1e-3;
+
+bool(1)=aresame(mu,mu0,tol).*aresame(sigma,sigma0,tol);
+bool(2)=aresame(mug,mu0,tol).*aresame(sigmag,sigma0,tol);
+bool(3)=aresame(skewg,0,tol).*aresame(kurtg,3,tol);
+
+reporttest('PDFPROPS with uniform pdf', bool(1));
+reporttest('PDFPROPS with Gaussian pdf', bool(2));
+reporttest('PDFPROPS Gaussian skewness=0, kurtosis=3', bool(3));
+
+% %/********************************************************
+% x=(-10:.001:10)';
+% f=simplepdf(x,0,2,'gaussian');
+% f(end/2:end)=2*f(end/2:end);
+% f(1:end/2)=0;
+% f=f./sum(f)./0.001;
+% plot(x,cumsum(f*.001))
+% %********************************************************
+
+function[varargout]=vswap(varargin)
+%VSWAP(X,A,B) replaces A with B in numeric array X
+%
+% VSWAP(X,A,B) replaces A with B in numeric array X. A and B may be
+% numbers, NAN, +/- INF, or NAN+SQRT(-1)*NAN.
+%
+% [Y1,Y2,...YN]=VSWAP(X1,X2,...XN,A,B) also works.
+%
+% VSWAP(X1,X2,...XN,A,B); with no output arguments overwrites the
+% original input variables.
+% __________________________________________________________________
+% This is part of JLAB --- type 'help jlab' for more information
+% (C) 2001, 2004 J.M. Lilly --- type 'help jlab_license' for details
+
+if strcmp(varargin{1}, '--t')
+ vswap_test,return
+end
+
+
+a=varargin{end-1};
+b=varargin{end};
+
+for i=1:length(varargin)-2
+ x=varargin{i};
+ varargout{i}=swapnum1(x,a,b);
+end
+
+eval(to_overwrite(nargin-2))
+
+
+function[x]=swapnum1(x,a,b)
+
+
+if isfinite(a)
+% if a==0
+% if ~isreal(x)
+% a=0+sqrt(-1)*0;
+% end
+% end
+ index=find(x==a);
+else
+ if isnan(a)
+ index=find(isnan(x));
+ elseif isinf(a)
+ if a>0
+ index=find(isinf(x)&x>0);
+ else
+ index=find(isinf(x)&x<0);
+ end
+ elseif isnan(real(a)) && isnan(imag(a))
+ index=find(isnan(real(x))&isnan(imag(x)));
+ end
+end
+
+if ~isempty(index)
+ if allall(x==0|x==1)
+ %Matlab, apparently, won't let you put NANs into a boolean array
+ x=x+1;
+ x(index)=b;
+ x=x-1;
+ else
+ x(index)=b;
+ end
+end
+
+function[]=vswap_test
+x=(1:10);
+ans1=[2 (2:10)];
+reporttest('VSWAP num case', aresame(vswap(x,1,2),ans1))
+
+x=[nan (1:10)];
+ans1=(0:10);
+reporttest('VSWAP nan case', aresame(vswap(x,nan,0),ans1))
+
+x=[nan*(1+sqrt(-1)) (1:10)];
+ans1=(0:10);
+reporttest('VSWAP complex nan case', aresame(vswap(x,nan+sqrt(-1)*nan,0),ans1))
+
+function[b]=jisrow(x)
+%JISROW Tests whether the argument is a row vector.
+% _________________________________________________________________
+% This is part of JLAB --- type 'help jlab' for more information
+% (C) 2002-2011 J.M. Lilly --- type 'help jlab_license' for details
+b=(ndims(x)==2) && size(x,1)==1 && size(x,2)>1;
View
8 doc/matlab.html
@@ -17,6 +17,14 @@
computing the table index (U_hash, a time), the cost of calculating a candidate point's distance (U_check, a time),
and a desired accuracy (delta, a probability of missing the true nearest neighbor). The output from this routine are the optimal LSH parameters.
</P>
+ <p>We are grateful for J. M. Lilly for his permission to include the PDF functions from his JLAB
+ toolbox in this code. His toolbox is wonderful, and more details can be found at:
+ <ul>
+ Lilly, J. M. (2011), <em>JLAB: Matlab freeware for data analysis, </em>
+ Version 0.92, http://www.jmlilly.net/software.html.
+ </ul>
+ </P>
+
<H4>Function Protypes</H4>
<UL>
Please sign in to comment.
Something went wrong with that request. Please try again.