0001 function GS = slgausscomb(varargin)
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
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059 args.means = [];
0060 args.vars = [];
0061 args.covs = [];
0062 args.compinv = true;
0063 args.invparams = {};
0064 args.mixweights = [];
0065 args = slparseprops(args, varargin{:});
0066
0067
0068 if isempty(args.means)
0069 error('sltoolbox:invalidarg', ...
0070 'The means should be specified');
0071 end
0072
0073 if isempty(args.vars) && isempty(args.covs)
0074 error('sltoolbox:invalidarg', ...
0075 'You should specify either vars or covs');
0076 end
0077
0078 if ~isempty(args.vars) && ~isempty(args.covs)
0079 error('sltoolbox:invalidarg', ...
0080 'You should specify both vars and covs');
0081 end
0082
0083
0084
0085
0086 means = take_arrayform('means', args.means, 2);
0087 [d, k] = size(means);
0088
0089 GS.dim = d;
0090 GS.nmodels = k;
0091 GS.means = means;
0092
0093
0094
0095
0096 if ~isempty(args.vars)
0097
0098 vars = take_arrayform('vars', args.vars, 2);
0099 [dv, kv] = size(vars);
0100
0101 if dv ~= 1 && dv ~= d
0102 error('sltoolbox:sizmismatch', ...
0103 'The size of vars is illegal');
0104 end
0105 if kv ~= 1 && kv ~= k
0106 error('sltoobox:sizmismatch', ...
0107 'The size of vars is illegal');
0108 end
0109
0110 GS.vars = vars;
0111 if args.compinv
0112 GS.invvars = slgaussinv(GS, 'vars', args.invparams);
0113 end
0114
0115 else
0116
0117 covs = take_arrayform('covs', args.covs, 3);
0118 [dcv, dcv2, kcv] = size(covs);
0119
0120 if dcv ~= d || dcv2 ~= d
0121 error('sltoolbox:sizmismatch', ...
0122 'The size of covs is illegal');
0123 end
0124
0125 if kcv ~= 1 && kcv ~= k
0126 error('sltoolbox:sizmismatch', ...
0127 'The size of covs is illegal');
0128 end
0129
0130 GS.covs = covs;
0131 if args.compinv
0132 GS.invcovs = slgaussinv(GS, 'covs', args.invparams);
0133 end
0134
0135 end
0136
0137
0138
0139 if ~isempty(args.mixweights)
0140
0141 mixweights = args.mixweights(:);
0142 if length(mixweights) ~= k
0143 error('sltoolbox:sizmismatch', ...
0144 'The length of mix weights is illegal');
0145 end
0146
0147 GS.mixweights = mixweights;
0148
0149 end
0150
0151
0152
0153
0154
0155
0156 function V = take_arrayform(name, v, dmax)
0157
0158 if isnumeric(v)
0159 V = v;
0160 elseif iscell(v)
0161 V = v(:)';
0162 if dmax == 2
0163 V = horzcat(V{:});
0164 elseif dmax == 3
0165 V = cat(3, V{:});
0166 end
0167 else
0168 error('sltoolbox:invalidarg', ...
0169 'The %s should be either an numeric array or a cell array', name);
0170 end
0171
0172 if ndims(V) > dmax
0173 error('sltoolbox:invalidarg', ...
0174 'The dimension of means should not exceed %d', dmax);
0175 end
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186