Institut de Robòtica i Informàtica Industrial

Gaussian

PURPOSE ^

Defines a Gaussian.

SYNOPSIS ^

function G=Gaussian(varargin)

DESCRIPTION ^

 Defines 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 INFORMATION ^

This function calls:
  • size Number of poses in a trajectory.
  • size Size of the state estimated in the filter
  • Gaussian Defines a Gaussian.
  • diag Extracts the diagonal of an interval matrix.
  • size Size (rows/columns) of an interval matrix.
  • sqrt Element-wise square root of an interval matrix (operator: .^0.5).
  • size Number of parameters of the pose.
  • size Number of readings stored in the Sensor.
This function is called by:

SOURCE CODE ^

0001 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


Institut de Robòtica i Informàtica Industrial

Generated on Fri 24-Jul-2009 12:32:50 by m2html © 2003