%MOGC Trainable classifier based on Mixture of Gaussians
%
% W = MOGC(A,N)
% W = A*MOGC([],N,R,S);
% W = A*MOGC(N,R,S);
%
% INPUT
% A Dataset
% N Number of mixtures (optional; default 2)
% R,S Regularization parameters, 0 <= R,S <= 1, see QDC
% OUTPUT
%
% DESCRIPTION
% For each class j in A a density estimate is made by GAUSSM, using N(j)
% mixture components. Using the class prior probabilities they are combined
% into a single classifier W. If N is a scalar, this number is applied to
% each class. The relative size of the components is stored in W.DATA.PRIOR.
%
% EXAMPLES
% PREX_DENSITY
%
% SEE ALSO (PRTools Guide)
% DATASETS, MAPPINGS, QDC, PLOTM, TESTC
% Copyright: R.P.W. Duin, r.p.w.duin@37steps.com
% Faculty EWI, Delft University of Technology
% P.O. Box 5031, 2600 GA Delft, The Netherlands
% $Id: mogc.m,v 1.6 2009/11/23 09:22:28 davidt Exp $
function w = mogc(varargin)
mapname = 'Mog';
argin = shiftargin(varargin,'integer');
argin = setdefaults(argin,[],2,0,0);
if mapping_task(argin,'definition')
w = define_mapping(argin,'untrained',mapname);
elseif mapping_task(argin,'training') % Train a mapping.
[a,n,r,s] = deal(argin{:});
islabtype(a,'crisp','soft');
isvaldfile(a,n,2); % at least n objects per class, 2 classes
% Initialize all the parameters:
a = testdatasize(a);
a = testdatasize(a,'features');
[m,k,c] = getsize(a);
p = getprior(a);
a = setprior(a,p);
if length(n) == 1
n = repmat(n,1,c);
end
if length(n) ~= c
error('Numbers of components does not match number of classes')
end
w = [];
d.mean = zeros(sum(n),k);
d.cov = zeros(k,k,sum(n));
d.prior = zeros(1,sum(n));
d.nlab = zeros(1,sum(n));
d.det = zeros(1,sum(n));
if(any(classsizes(a)