classdef (ConstructOnLoad) BRMM %#ok<*MCSUP,*PROP>
%BRMM Construct Bayesian robust mixture model
%
% BRMM constructs a Bayesian robust mixture model with a given number of
% classes and real-valued features.
%
% Usage: Obj=BRMM(K,D)
%
% Inputs: K - Number of classes
% D - Number of features
%
% Outputs: Obj - Bayesian robust mixture model
%
% Input arguments K and D should be positive integer scalars.
%
% See also BRMM.SIM and BRMM.ESTIM.
%
% Copyright (c) 2013 Gabriel Agamennoni.
% Number of classes and features.
properties (SetAccess=private)
NumClass
NumFeat
end
% Hyper-parameters.
properties
ProtoWeight
ProtoStren
ProtoLoc
ProtoScale
ProtoDisp
ProtoPrec
end
% Constructor.
methods
function Obj=BRMM(NumClass,NumFeat)
if nargin()>0
% Check number of arguments.
if nargin()<2
error('BRMM:NotEnoughInputs',...
'Not enough inputs.')
end
if nargin()>2
error('BRMM:TooManyInputs',...
'Too many inputs.')
end
if nargout()>1
error('BRMM:TooManyOutputs',...
'Too many outputs.')
end
% Check input arguments.
CheckArg(NumClass,NumFeat)
% Set number of classes and features.
Obj.NumClass=NumClass;
Obj.NumFeat=NumFeat;
% Set default hyper-parameters.
Obj.ProtoWeight=ones(NumClass,1)/NumClass;
Obj.ProtoStren=1;
Obj.ProtoLoc=zeros(NumFeat,NumClass);
Obj.ProtoScale=ones(NumClass,1);
Obj.ProtoDisp=RepVal(eye(NumFeat),3,NumClass);
Obj.ProtoPrec=NumFeat*ones(NumClass,1);
end
end
end
% Access methods.
methods
function Obj=set.ProtoWeight(Obj,ProtoWeight)
% Store number of classes.
NumClass=Obj.NumClass;
% Check prototype weights.
if ~isnumeric(ProtoWeight)
error('BRMM:BadInputClass',...
'Input must be numeric.')
end
if ~isreal(ProtoWeight)
error('BRMM:BadInputClass',...
'Input must be real.')
end
if isempty(ProtoWeight)
error('BRMM:BadInputSize',...
'Input must be non-empty.')
end
if ndims(ProtoWeight)>2||min(size(ProtoWeight))>1
error('BRMM:BadInputSize',...
'Input must be a vector.')
end
if numel(ProtoWeight)~=NumClass
error('BRMM:BadInputSize',...
'Input must have %d element(s).',NumClass)
end
if any(isnan(ProtoWeight)|isinf(ProtoWeight))
error('BRMM:BadInputValue',...
'Input must contain finite numbers.')
end
if any(ProtoWeight<=0)||abs(sum(ProtoWeight)-1)>eps()*NumClass
error('BRMM:BadInputValue',...
'Input must contain numbers on the unit simplex.')
end
% Set prototype weights.
Obj.ProtoWeight=ProtoWeight;
end
function Obj=set.ProtoStren(Obj,ProtoStren)
% Check prototype strength.
if ~isnumeric(ProtoStren)
error('BRMM:BadInputClass',...
'Input must be numeric.')
end
if ~isreal(ProtoStren)
error('BRMM:BadInputClass',...
'Input must be real.')
end
if isempty(ProtoStren)
error('BRMM:BadInputSize',...
'Input must be non-empty.')
end
if ndims(ProtoStren)>2||numel(ProtoStren)>1
error('BRMM:BadInputSize',...
'Input must be a scalar.')
end
if isnan(ProtoStren)||isinf(ProtoStren)||ProtoStren<=0
error('BRMM:BadInputValue',...
'Input must contain a positive finite number.')
end
% Set prototype strength.
Obj.ProtoStren=ProtoStren;
end
function Obj=set.ProtoLoc(Obj,ProtoLoc)
% Store number of classes and features.
NumClass=Obj.NumClass;
NumFeat=Obj.NumFeat;
% Check prototype locations.
if ~isnumeric(ProtoLoc)
error('BRMM:BadInputClass',...
'Input argument must be numeric.')
end
if ~isreal(ProtoLoc)
error('BRMM:BadInputClass',...
'Input must be real.')
end
if isempty(ProtoLoc)
error('BRMM:BadInputSize',...
'Input must be non-empty.')
end
if ndims(ProtoLoc)>2
error('BRMM:BadInputSize',...
'Input must be a matrix.')
end
if size(ProtoLoc,1)~=NumFeat
error('BRMM:BadInputSize',...
'Input must have %d row(s).',NumFeat)
end
if size(ProtoLoc,2)~=NumClass
error('BRMM:BadInputSize',...
'Input must have %d column(s).',NumClass)
end
if any(isnan(ProtoLoc(:))|isinf(ProtoLoc(:)))
error('BRMM:BadInputValue',...
'Input must contain finite numbers.')
end
% Set prototype locations.
Obj.ProtoLoc=ProtoLoc;
end
function Obj=set.ProtoScale(Obj,ProtoScale)
% Store number of classes.
NumClass=Obj.NumClass;
% Check prototype scales.
if ~isnumeric(ProtoScale)
error('BRMM:BadInputClass',...
'Input must be numeric.')
end
if ~isreal(ProtoScale)
error('BRMM:BadInputClass',...
'Input must be real.')
end
if isempty(ProtoScale)
error('BRMM:BadInputSize',...
'Input must be non-empty.')
end
if ndims(ProtoScale)>2||min(size(ProtoScale))>1
error('BRMM:BadInputSize',...
'Input must be a vector.')
end
if numel(ProtoScale)~=NumClass
error('BRMM:BadInputSize',...
'Input must have %d element(s).',NumClass)
end
if any(isnan(ProtoScale)|isinf(ProtoScale)|ProtoScale<=0)
error('BRMM:BadInputValue',...
'Input must contain positive finite numbers.')
end
% Set prototype scales.
Obj.ProtoScale=ProtoScale;
end
function Obj=set.ProtoDisp(Obj,ProtoDisp)
% Store number of classes and features.
NumClass=Obj.NumClass;
NumFeat=Obj.NumFeat;
% Check prototype dispersions.
if ~isnumeric(ProtoDisp)
error('BRMM:BadInputClass',...
'Input must be numeric.')
end
if ~isreal(ProtoDisp)
- 1
- 2
前往页