Code covered by the BSD License  

Highlights from
Statistical Learning Toolbox

from Statistical Learning Toolbox by Dahua Lin
Functions for statistical learning, pattern recognition and computer vision, covering many topics.

Description of slposteriori
Home > sltoolbox > stat > slposteriori.m

slposteriori

PURPOSE ^

SLPOSTERIORI Computes the posterioris

SYNOPSIS ^

function posteriori = slposteriori(condprops, priori, op)

DESCRIPTION ^

SLPOSTERIORI Computes the posterioris 

 $ Syntax $
   - posteriori = slposteriori(condprops, priori)
   - posteriori = slposteriori(condprops, priori, 'log')

 $ Arguments $
   - condprods:      the conditional probabilities of classes
   - priori:         the prior probabilities of classes
   - posteriori:     the resulting posterior probabilities

 $ Description $
   - posteriori = slposteriori(condprops, priori) Computes the posterior
     probability according to the given conditional probabilities of all
     samples to all classes and the priori of the classes. If the number
     of classes is C and the number of samples is n, then the size of 
     condprops should be k * n, the size of priori should be k-dim vector. 
     And the resultant posteriori matrix will be of size k * n.

   - posteriori = slposteriori(condprops, priori, 'log') where condprops
     are given by its logarithm. And the computation is based on logarithm
     in a stable manner.

 $ Remarks $
   - If priori is not specified, then they are assumed to be equal.

 $ History $
   - Created by Dahua Lin on Dec 21st, 2005
   - Modified by Dahua Lin on Apr 22, 2006
       - fix some header comments
       - fix some places to increase efficiency
   - Modified by Dahua Lin on Sep 10, 2006
       - replace sladd by sladdvec and slmul by slmulvec to increase 
         efficiency.

CROSS-REFERENCE INFORMATION ^

This function calls:
  • sladdvec SLADDVEC adds a vector to columns or rows of a matrix
  • slmulvec SLMULVEC multiplies a vector to columns or rows of a matrix
This function is called by:
  • sllogistreg SLLOGISTREG Performs Multivariate Logistic Regression
  • slfmm SLFMM Learns a Finite Mixture Model (FMM)

SOURCE CODE ^

0001 function posteriori = slposteriori(condprops, priori, op)
0002 %SLPOSTERIORI Computes the posterioris
0003 %
0004 % $ Syntax $
0005 %   - posteriori = slposteriori(condprops, priori)
0006 %   - posteriori = slposteriori(condprops, priori, 'log')
0007 %
0008 % $ Arguments $
0009 %   - condprods:      the conditional probabilities of classes
0010 %   - priori:         the prior probabilities of classes
0011 %   - posteriori:     the resulting posterior probabilities
0012 %
0013 % $ Description $
0014 %   - posteriori = slposteriori(condprops, priori) Computes the posterior
0015 %     probability according to the given conditional probabilities of all
0016 %     samples to all classes and the priori of the classes. If the number
0017 %     of classes is C and the number of samples is n, then the size of
0018 %     condprops should be k * n, the size of priori should be k-dim vector.
0019 %     And the resultant posteriori matrix will be of size k * n.
0020 %
0021 %   - posteriori = slposteriori(condprops, priori, 'log') where condprops
0022 %     are given by its logarithm. And the computation is based on logarithm
0023 %     in a stable manner.
0024 %
0025 % $ Remarks $
0026 %   - If priori is not specified, then they are assumed to be equal.
0027 %
0028 % $ History $
0029 %   - Created by Dahua Lin on Dec 21st, 2005
0030 %   - Modified by Dahua Lin on Apr 22, 2006
0031 %       - fix some header comments
0032 %       - fix some places to increase efficiency
0033 %   - Modified by Dahua Lin on Sep 10, 2006
0034 %       - replace sladd by sladdvec and slmul by slmulvec to increase
0035 %         efficiency.
0036 %
0037 
0038 %% parse and verify
0039 k = size(condprops, 1);
0040 if nargin < 2 || isempty(priori)
0041     priori = ones(k, 1) / k;
0042 else
0043     if numel(priori) ~= k
0044         error('sltoolbox:sizmismatch', ...
0045             'The size of priori is not consisitent with that of condprops');
0046     end
0047     priori = priori(:);
0048 end
0049 if nargin < 3 || isempty(op)
0050     logstyle = false;
0051 else 
0052     if strcmpi(op, 'log')
0053         logstyle = true;
0054     else
0055         error('sltoolbox:invalidoption', ...
0056             'Invalid option %s', op);
0057     end
0058 end
0059 
0060 %% compute
0061 if logstyle
0062     prods = sladdvec(condprops, log(priori), 1);
0063     prods = sladdvec(prods, -max(prods, [], 1), 2);
0064     prods = exp(prods);
0065 else
0066     prods = slmulvec(condprops, priori);
0067 end
0068 
0069 tprods = sum(prods, 1);
0070 posteriori = slmulvec(prods, 1 ./ tprods);
0071 
0072 
0073 
0074

Generated on Wed 20-Sep-2006 12:43:11 by m2html © 2003

Contact us at files@mathworks.com