0001 function posteriori = slposterioritrue(condprops, nums, priori, op)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
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
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