function  [Zcongr,output,W_hist,Zin] = PLM_Zcongr2(arg1,params,chev)

%PLM_ZCONGR2  -- Run PLM_HEBB2 and calculate z-probabilities correct.
%
%  Zcongr = PLM_Zcongr2(Mdata)
%  Zcongr = PLM_Zcongr2(stim,params)
%  Zcongr = PLM_Zcongr2(stim,params,chev)
%  [Zcongr,output,W_hist,Zin] = PLM_Zcongr2(...)
%
%  PLM_ZCONGR2 : PLM_ZCONGR1 :: PLM_HEBB2 : PLM_HEBB1
%  See PLM_ZCONGR1 for more detailed documentation.
%
%  See also PLM_ZCONGR1, PLM_HEBB2, PLM_PBLOCK1, PLM_PARAMSEARCH.

%  Original coding by Alexander Petrov, UC Irvine.
%  $Revision: 2.0 $  $Date: 2005/06/23 19:09 $

%-- Call PLM_HEBB2
if (isstruct(arg1))   % a single structure with subfields
   if (nargin~=1) warning('ARG1 is a struct; I ignore the rest.') ; end
   [output,W_hist] = PLM_Hebb2(arg1) ;
   stim = arg1.stim ;
   params = arg1.params ;
else    % STIM, PARAMS, and perhaps CHEV explicitly supplied
   stim = arg1 ;
   if (nargin==2)
      [output,W_hist] = PLM_Hebb2(stim,params) ;
   else  % nargin must be 3
      [output,W_hist] = PLM_Hebb2(stim,params,chev) ;
   end
end

%-- Bottom-up input to the output unit
bottom_up = output(:,3) ;   % bottom-up input to the output unit
bias = output(:,4) ;        % current boundary b/n "Left" and "Right"

%-- Z(bottom_up - bias + noise > 0) = Z((bottom_up-bias)/sigma > 0)
Zin = (bottom_up - bias) ./ params.out_noise ;

%-- Call PLM_PBLOCK1 to partition into blocks and conditions
Zcongr = PLM_Pblock1(stim,Zin) ; 

%-- Return ZCONGR
%%%%% End of file PLM_ZCONGR2.M
