GaussianPURPOSEDefines a Gaussian.
SYNOPSISfunction G=Gaussian(varargin)
DESCRIPTIONDefines a Gaussian. Multi-dimensional Gaussian constructor. The input parameters can be another Gaussian, from a collection of points of from the mean and covariance matrix. CROSS-REFERENCE INFORMATIONThis function calls:
SOURCE CODE0001 function G=Gaussian(varargin) 0002 % Defines a Gaussian. 0003 % 0004 % Multi-dimensional Gaussian constructor. The input parameters can be 0005 % another Gaussian, from a collection of points of from the mean and 0006 % covariance matrix. 0007 0008 switch nargin 0009 case 1 0010 if isa(varargin{1},'Gaussian') 0011 G=varargin{1}; 0012 else 0013 if isa(varargin{1},'double') 0014 % assuming we have to define the Gaussian from samples (arranged 0015 % in columns) 0016 M=size(varargin{1},2); % number of data 0017 m=mean(varargin{1},2); 0018 Pz=(varargin{1}-repmat(m,1,M)); % zero centered points 0019 C=(Pz*Pz')/(M-1); % unbiased covariance 0020 G=Gaussian(m,C); 0021 else 0022 error('Gaussian copy constructor from not a Guassian and not a raw data'); 0023 end 0024 end 0025 0026 case 2 0027 G.m=varargin{1}; 0028 G.dim=size(G.m,1); 0029 % add a small amount of noise to the covariance to avoid 0030 % it to become semidefinite negative due to numerical issues 0031 G.S=varargin{2}+1e-6*eye(G.dim); 0032 0033 if (G.dim~=size(G.S,1)) || (G.dim~=size(G.S,2)) 0034 error('Non-coherent size of mean an covariance in Gaussian creation'); 0035 end 0036 0037 m=max(max(G.S)); 0038 if m==0 0039 G.S=zeros(G.dim); 0040 G.d=0; 0041 G.iS=inf*eye(G.dim); 0042 G.ct=0; 0043 else 0044 R=chol(G.S); 0045 G.d=prod(diag(R))^2; 0046 iR=R\eye(G.dim); 0047 G.iS=iR*iR'; 0048 G.ct=1/sqrt(((2*pi)^G.dim)*G.d); 0049 end 0050 G=class(G,'Gaussian'); 0051 otherwise 0052 error('Wrong number of parameters in Gaussian constructor'); 0053 end |