function C = sdmaxent(varargin)
% SDMAXENT Spatial displacement maxent constructor
%
% The SDMAXENT class is a special version of a Maxent classifier
% that is designed to be applied via convolution over an entire
% image. Thus, features are not vectors per se, but a stack of feature
% images and the features passed to the "classifier" are values in
% all feature images in a window around each pixel.
%
% C = SDMAXENT(L,M,K) where L is the number of labels, M is the
% number of features, and K is the kernel/window size. K may be one
% entry or two; thus, the kernels may be square or non-square, but
% the kernel for each feature is the same size. Different window
% sizes for each feature could be controlled during training by
% using a feature selection.

% Jerod Weinman
% jerod@acm.org
% (c) 2008

% $Id: sdmaxent.m 1 2009-05-07 13:41:00Z weinman $
 
% Jerod Weinman
% jerod@acm.org
% Copyright 2007, 2008, 2011
 
%    This file is part of Matlab SDMaxEnt.
%
%    Matlab SDMaxEnt is free software: you can redistribute it and/or modify
%    it under the terms of the GNU General Public License as published by
%    the Free Software Foundation, either version 3 of the License, or
%    (at your option) any later version.
%
%    Matlab SDMaxEnt is distributed in the hope that it will be useful,
%    but WITHOUT ANY WARRANTY; without even the implied warranty of
%    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%    GNU General Public License for more details.
%
%    You should have received a copy of the GNU General Public License
%    along with Matlab SDMaxEnt.  If not, see <http://www.gnu.org/licenses/>.
  
% Object fields:
%    numLabels
%    params
  
  if nargin == 0
	% Set default fields
	C.numLabels = 0;
	
	P.weights = [];
	P.bias = [];
	
	C.params = P;
	
	C = class(C,'sdmaxent');
	
  elseif nargin==1 & isa(varargin{1},'sdmaxent')
    % Copy argument
	C = varargin{1};
	
  else
	
	[L,M,K] = varargin{1:3};
	
	if length(K)==1
	  K = [K K]; % Make kernel square
	end;
	


    % Initialize weights -- there is an additional bias feature (a
    % const feature that is implicitly appended to every
    % feature image so that the decision isn't restricted to
    % passing through the origin

	P.weights = zeros([K M L]);
	P.bias = zeros(1,1,L);

	% Set fields	
    C.numLabels = L;
	C.params = P;
	
	C = class(C,'sdmaxent');
  end;
  
