function show_ml( T_short, N_future )

% function show_ml( T_short, N_future )
%
% Show graphically the clusters produced by "do_ml".
%
% Input files: "DATA/do_ml-synth*.mat"
% Output: figures.
%
% This is a wrapper around the "plot_multi_cluster.m" function
%
% This code can be useful to demonstrate short-term clustering.
% See IDIAP RR 04-14 (2004) or Lathoud's PhD thesis (2006).
%
% By Guillaume Lathoud, 2006 - lathoud@idiap.ch

  if nargin < 2
    error( [ mfilename ' needs 2 input arguments.' ] );
  end
  
  a_dir = 'DATA';

  d = dir( fullfile( a_dir, sprintf( 'do_ml-Tshort_%d-Nfuture_%d-synth*.mat', T_short, N_future ) ) );

  d = d( find( ~[ d.isdir ] ) );
  d = d( find( [ d.bytes ] ) );

  n = numel( d );

  for a = 1:n
    
    infilename = fullfile( a_dir, d( a ).name );

    disp( ' ' );
    disp( sprintf( [ mfilename ': loading file %d/%d: "%s"...' ], a, n, infilename ) );
    
    % Load location estimates and tags
    % "r" is a structure array with three fields:
    %   r( i ).theta is the azimuth in radians.
    %   r( i ).T     is the integer time frame index.
    %   r( i ).tag   is the integer cluster tag
    %
    % Two location estimates r( i ) and r( j ) belong to the same cluster
    % iff their tags are equal

    load( infilename, 'r' );

    % Show the result

    hfig = figure;

    plot_multi_cluster( [ r.T ], [ r.theta ] / pi * 180, [ r.tag ] );

    set( gca, 'fontsize', 20 )

    a_title = strrep( [ d( a ).name ], '_', '\_' );
    title( a_title );
    ylabel('\theta_i (degrees)'); xlabel( 'T_i (frame index)' );
    
    % Write out .eps and .jpg files

    [ fp, fn, fe ] = fileparts( d( a ).name );

    epsout_filename = fullfile( a_dir, fp, [ fn '.eps' ] );
    print( hfig, '-depsc2', epsout_filename );
    disp( sprintf( [ mfilename ' wrote out figure %d to picture file "%s"' ], a, epsout_filename ) );
        
    jpgout_filename = fullfile( a_dir, fp, [ fn '.jpg' ] );
    print( hfig, '-djpeg95', jpgout_filename );
    disp( sprintf( [ mfilename ' wrote out figure %d to picture file "%s"' ], a, jpgout_filename ) );
    
  end
  
  if n > 1
    disp( ' ' );
    disp( [ '>>>>>>>>>> ' mfilename ': my advice: use the zoom, particularly where trajectories cross. <<<<<<<<<<' ] );
    disp( ' ' );
  end
  
