Institut de Robòtica i Informàtica Industrial

Gaussian

PURPOSE ^

Gaussian construtor.

SYNOPSIS ^

function g=Gaussian(varargin)

DESCRIPTION ^

   Gaussian construtor.

   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 Returns the size of a policy.
  • Gaussian Gaussian construtor.
  • max Upper bound of a CSpace
This function is called by:

SOURCE CODE ^

0001 function g=Gaussian(varargin)
0002 %   Gaussian construtor.
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           n=size(varargin{1},2); % number of data
0017           m=mean(varargin{1},2);
0018           Pz=(varargin{1}-repmat(m,1,n)); % zero centered points
0019           C=(Pz*Pz')/(n-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             g.S=varargin{2};
0030       
0031       if (g.dim~=size(g.S,1)) || (g.dim~=size(g.S,2))
0032         error('Non-coherent size of mean an covariance in Gaussian creation');
0033       end
0034 
0035       m=max(max(g.S));
0036       if m==0
0037         g.d=0;
0038         g.iS=inf*eye(g.dim);
0039         g.ct=0;
0040       else
0041         if g.dim==1
0042           g.d=g.S;
0043           g.iS=1/g.S;
0044           g.ct=1/sqrt(2*pi*g.d);
0045         else
0046           R=chol(g.S);
0047           g.d=prod(diag(R))^2;
0048           iR=R\eye(g.dim);
0049           g.iS=iR*iR';
0050           %The normalization factor (in multiplicative form)
0051           g.ct=1/sqrt(((2*pi)^g.dim)*g.d);
0052         end
0053       end
0054       g=class(g,'Gaussian');
0055     otherwise
0056             error('Wrong number of parameters in Gaussian constructor');
0057     end
0058


Institut de Robòtica i Informàtica Industrial

Generated on Wed 05-Aug-2009 15:05:21 by m2html © 2003