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 slposterioritrue
Home > sltoolbox > stat > slposterioritrue.m

slposterioritrue

PURPOSE ^

SLPOSTERIORITRUE Computes the posteriori that samples belong to true class

SYNOPSIS ^

function posteriori = slposterioritrue(condprops, nums, priori, op)

DESCRIPTION ^

SLPOSTERIORITRUE Computes the posteriori that samples belong to true class

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

 $ Arguments $
   - condprods:      the conditional probabilities of classes: C x n
   - nums:           the number of samples belong to the classes: 1 x C
   - priori:         the prior probabilities of classes: 1 x C
   - posteriori:     the resulting posterior probabilities: 1 x n

 $ Description $
   - posteriori = slposteriori(condprops, nums, priori) Computes the 
     posterior probability that the samples belong to the true class 
     according to the given conditional probabilities of all samples 
     to all classes and the priori of the classes. 
     In the input argument, each column in condprops represent the 
     conditional probabilities of that sample belong to all the 
     C classes. The samples from the same underlying classes should be
     put together and the ownership is given by nums.
     The priori can be given by an 1 x C row vector or [], which 
     means that all classes have equal prior.

   - posteriori = slposterioritrue(condprops, nums, priori, 'log') means
     that the input condprops are given by its logarithm.

 $ History $
   - Created by Dahua Lin, on Sep 16th, 2006

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
  • raise_lackinput RAISE_LACKINPUT Raises an error indicating lack of input argument
  • slnums2bounds SLNUMS2BOUNDS Compute the index-boundaries from section sizes
This function is called by:
  • sllogistreg SLLOGISTREG Performs Multivariate Logistic Regression

SOURCE CODE ^

0001 function posteriori = slposterioritrue(condprops, nums, priori, op)
0002 %SLPOSTERIORITRUE Computes the posteriori that samples belong to true class
0003 %
0004 % $ Syntax $
0005 %   - posteriori = slposterioritrue(condprops, nums, priori)
0006 %   - posteriori = slposterioritrue(condprops, nums, priori, 'log')
0007 %
0008 % $ Arguments $
0009 %   - condprods:      the conditional probabilities of classes: C x n
0010 %   - nums:           the number of samples belong to the classes: 1 x C
0011 %   - priori:         the prior probabilities of classes: 1 x C
0012 %   - posteriori:     the resulting posterior probabilities: 1 x n
0013 %
0014 % $ Description $
0015 %   - posteriori = slposteriori(condprops, nums, priori) Computes the
0016 %     posterior probability that the samples belong to the true class
0017 %     according to the given conditional probabilities of all samples
0018 %     to all classes and the priori of the classes.
0019 %     In the input argument, each column in condprops represent the
0020 %     conditional probabilities of that sample belong to all the
0021 %     C classes. The samples from the same underlying classes should be
0022 %     put together and the ownership is given by nums.
0023 %     The priori can be given by an 1 x C row vector or [], which
0024 %     means that all classes have equal prior.
0025 %
0026 %   - posteriori = slposterioritrue(condprops, nums, priori, 'log') means
0027 %     that the input condprops are given by its logarithm.
0028 %
0029 % $ History $
0030 %   - Created by Dahua Lin, on Sep 16th, 2006
0031 %
0032 
0033 %% parse and verify input arguments
0034 
0035 if nargin < 2
0036     raise_lackinput('slposterioritrue', 2);
0037 end
0038 
0039 if ~isnumeric(condprops) || ndims(condprops) ~= 2
0040     error('sltoolbox:invalidarg', ...
0041         'The condprops should be a 2D numeric matrix');
0042 end
0043 [C, n] = size(condprops);
0044 
0045 if ~isequal(size(nums), [1, C])
0046     error('sltoolbox:sizmismatch', ...
0047         'The nums should be an 1 x C row vector');
0048 end
0049 if nargin < 3 || isempty(priori)
0050     priori = [];
0051 else
0052     if ~isequal(size(priori), [1, C])
0053         error('sltoolbox:sizmismatch', ...
0054             'The priori should be a an 1 x C row vector');
0055     end
0056 end
0057 
0058 if nargin >= 4 && strcmpi(op, 'log')
0059     is_log = true;
0060 else
0061     is_log = false;
0062 end
0063 
0064 %% compute
0065 
0066 if is_log
0067     if isempty(priori)
0068         P = sladdvec(condprops, -max(condprops, [], 1), 2);
0069     else
0070         P = sladdvec(condprops, log(priori)', 1);
0071         P = sladdvec(P, -max(condprops, [], 1), 2);
0072     end
0073     P = exp(P);
0074 else
0075     if isempty(priori)
0076         P = condprops;
0077     else
0078         P = slmulvec(condprops, priori', 1);
0079     end
0080 end
0081 
0082 tP = sum(P, 1);
0083 [sp, ep] = slnums2bounds(nums);
0084 posteriori = zeros(1, n);
0085 
0086 for k = 1 : C
0087     sk = sp(k);
0088     ek = ep(k);
0089     posteriori(sk:ek) = P(k, sk:ek);
0090 end
0091 posteriori = posteriori ./ tP;
0092

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

Contact us at files@mathworks.com