function M = messages(F,S,R,T)
%   MESSAGES Calculates messages from the factor to variables
%
% M = MESSAGES(F,S) where F is the factor, S are the variable
% to factor messages for the graph the factor belongs to.
%
% M = MESSAGES(F,S,R) where R=1 indicates that the max-product (rather
% than sum-product) algorithm should be used.
%
% M = MESSAGES(F,S,R,T) where T would contain the pre-calculated
% Cartesian outer product indices for multiplying messages and the
% factor, but this is ignored for the WORDFACTOR class.
  
% Jerod Weinman
% jerod@acm.org
  
% $Id: messages.m 50 2011-07-29 16:01:00Z weinman $
 
% Jerod Weinman
% jerod@acm.org
% Copyright 2006, 2008, 2009, 2011
 
%    This file is part of VIDI.
%
%    VIDI 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.
%
%    VIDI 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 VIDI.  If not, see <http://www.gnu.org/licenses/>.

% WORDFACTOR.MESSAGES
  
  if nargin<3
    R = 0;
  end;
  
  if R
    M = maxprodmessages(F,S);
    %M = scmaxprodmessages(F,S);
  else
    M = sumprodmessages(F,S);
    %M = scsumprodmessages(F,S);
  end;
