function hits_test ( )

%*****************************************************************************80
%
%% hits_test() tests hits().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    05 March 2019
%
%  Author:
%
%    John Burkardt
%
  addpath ( '../hits' );

  timestamp ( );
  fprintf ( 1, '\n' );
  fprintf ( 1, 'hits_test():\n' );
  fprintf ( 1, '  MATLAB/Octave version %s\n', version ( ) );
  fprintf ( 1, '  hits() computes the hub and authority scores for nodes\n' );
  fprintf ( 1, '  in a directed network.\n' );
%
%  N=4 example.
%
  hits_iteration_test01 ( );
  hits_svd_test01 ( );
%
%  N=5 example.
%
  hits_iteration_test02 ( );
  hits_svd_test02 ( );
%
%  "Small" example.
%
  filename = 'small_sparse.txt';
  hits_iteration_test03 ( filename );
  hits_svd_test03 ( filename );
%
%  "Medium" example.
%
  filename = 'medium_sparse.txt';
  hits_iteration_test03 ( filename );
  hits_svd_test03 ( filename );
%
%  "Large" example.
%
  filename = 'large_sparse.txt';
  hits_iteration_test03 ( filename );
  hits_svd_test03 ( filename );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'hits_test():\n' );
  fprintf ( 1, '  Normal end of execution.\n' );
  fprintf ( 1, '\n' );
  timestamp ( );

  rmpath ( '../hits' );

  return
end
function hits_iteration_test01 ( )

%*****************************************************************************80
%
%% hits_iteration_test01() applies the HITS iteration to the 4x4 example.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    04 March 2019
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'hits_iteration_test01():\n' );
  fprintf ( 1, '  4x4 directed adjacency matrix example\n' );
  fprintf ( 1, '  Compute authority and hub rankings using HITS iterative algorithm.\n' );
%
%  Set the adjacency matrix:
%
  A = [ ...
    0, 1, 1, 1;
    0, 0, 1, 1;
    0, 1, 0, 0;
    0, 0, 0, 0 ];

  n = 4;

  matrix_print ( n, n, A, '  The adjacency matrix' );
%
%  Apply iterative algorithm.
%
  steps = 10;
  fprintf ( 1, '\n' );
  fprintf ( 1, '  The HITS iterative algorithm will use %d steps\n', steps );
  [ auth, hub ] = hits_iteration ( A, steps );

  r8vec2_print ( n, auth, hub, '  Computed authority and hub vectors' );

  auth2 = [ 0.0000, 0.4597, 0.6280, 0.6280 ];
  hub2 =  [ 0.7887, 0.5774, 0.2113, 0.0000 ];

  r8vec2_print ( n, auth2, hub2, '  Expected authority and Hub vectors' );

  return
end
function hits_svd_test01 ( )

%*****************************************************************************80
%
%% hits_svd_test01() applies the HITS SVD algorithm to the 4x4 example.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    04 March 2019
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'hits_svd_test01():\n' );
  fprintf ( 1, '  4x4 directed adjacency matrix example\n' );
  fprintf ( 1, '  Compute authority and hub rankings using HITS SVD algorithm.\n' );
%
%  Set the adjacency matrix:
%
  A = [ ...
    0, 1, 1, 1;
    0, 0, 1, 1;
    0, 1, 0, 0;
    0, 0, 0, 0 ];

  n = 4;

  matrix_print ( n, n, A, '  The adjacency matrix' );
%
%  Apply the SVD algorithm.
%
  [ auth, hub ] = hits_svd ( A );

  r8vec2_print ( n, auth, hub, '  Computed authority and hub vectors' );

  auth2 = [ 0.0000, 0.4597, 0.6280, 0.6280 ];
  hub2 =  [ 0.7887, 0.5774, 0.2113, 0.0000 ];

  r8vec2_print ( n, auth2, hub2, '  Expected authority and Hub vectors' );

  return
end
function hits_iteration_test02 ( )

%*****************************************************************************80
%
%% hits_iteration_test02() applies the HITS iteration to the 5x5 example.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    04 March 2019
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'hits_iteration_test02():\n' );
  fprintf ( 1, '  5x5 directed adjacency matrix example\n' );
  fprintf ( 1, '  Compute authority and hub rankings using HITS iterative algorithm.\n' );
%
%  Set the adjacency matrix:
%
  n = 5;
  A = zeros(n,n);
  A(2,1) = 1;
  A(2,3) = 1;
  A(3,4) = 1;
  A(4,1) = 1;
  A(4,2) = 1;
  A(4,3) = 1;
  A(5,4) = 1;

  matrix_print ( n, n, A, '  The adjacency matrix' );
%
%  Apply the iterative algorithm.
%
  steps = 10;
  fprintf ( 1, '\n' );
  fprintf ( 1, '  The HITS iterative algorithm will use %d steps\n', steps );
  [ auth, hub ] = hits_iteration ( A, steps );

  r8vec2_print ( n, auth, hub, '  Computed authority and hub vectors' );

  return
end
function hits_svd_test02 ( )

%*****************************************************************************80
%
%% hits_svd_test02() applies the HITS SVD algorithm to the 5x5 example.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    04 March 2019
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'hits_svd_test02():\n' );
  fprintf ( 1, '  5x5 directed adjacency matrix example\n' );
  fprintf ( 1, '  Compute authority and hub rankings using HITS SVD algorithm.\n' );
%
%  Set the adjacency matrix:
%
  n = 5;
  A = zeros(n,n);
  A(2,1) = 1;
  A(2,3) = 1;
  A(3,4) = 1;
  A(4,1) = 1;
  A(4,2) = 1;
  A(4,3) = 1;
  A(5,4) = 1;

  matrix_print ( n, n, A, '  The adjacency matrix' );
%
%  Apply the SVD algorithm.
%
  [ auth, hub ] = hits_svd ( A );

  r8vec2_print ( n, auth, hub, '  Computed authority and hub vectors' );

  return
end
function hits_iteration_test03 ( filename )

%*****************************************************************************80
%
%% hits_iteration_test03() applies the HITS iteration to a sparse matrix.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    04 March 2019
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'hits_iteration_test03():\n' );
  fprintf ( 1, '  Data read from sparse matrix file "%s"\n', filename );
  fprintf ( 1, '  Compute authority and hub rankings using HITS iterative algorithm.\n' );
%
%  Get the adjacency matrix:
%
  data = load ( filename );
  A = spconvert ( data );
  nonzeros = nnz ( A );
  fprintf ( 1, '  Number of nonzero elements = %d\n', nonzeros );
  A = full ( A );
  [ m, n ] = size ( A );
  fprintf ( 1, '  Number of nodes = %d\n', n );  
%
%  Apply iterative algorithm.
%
  steps = 30;
  fprintf ( 1, '\n' );
  fprintf ( 1, '  The HITS iterative algorithm will use %d steps\n', steps );
  [ auth, hub ] = hits_iteration ( A, steps );

  r8vec2_print ( n, auth, hub, '  Computed authority and hub vectors' );

  return
end
function hits_svd_test03 ( filename )

%*****************************************************************************80
%
%% hits_svd_test03() applies the HITS SVD algorithm to a sparse matrix.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    04 March 2019
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'hits_svd_test03():\n' );
  fprintf ( 1, '  Data read from sparse matrix file "%s"\n', filename );
  fprintf ( 1, '  Compute authority and hub rankings using HITS SVD algorithm.\n' );
%
%  Get the adjacency matrix:
%
  data = load ( filename );
  A = spconvert ( data );
  nonzeros = nnz ( A );
  fprintf ( 1, '  Number of nonzero elements = %d\n', nonzeros );
  A = full ( A );
  [ m, n ] = size ( A );
  fprintf ( 1, '  Number of nodes = %d\n', n );  
%
%  Apply the SVD algorithm.
%
  [ auth, hub ] = hits_svd ( A );

  r8vec2_print ( n, auth, hub, '  Computed authority and hub vectors' );

  return
end
function timestamp ( )

%*****************************************************************************80
%
%% timestamp() prints the current YMDHMS date as a timestamp.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    14 February 2003
%
%  Author:
%
%    John Burkardt
%
  t = now;
  c = datevec ( t );
  s = datestr ( c, 0 );
  fprintf ( 1, '%s\n', s );

  return
end

