function small_page_test ( )

%*****************************************************************************80
%
%% small_page_test carries out the page rank algorithm for the "small" dataset.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    03 March 2019
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'small_page_test:\n' );
  fprintf ( 1, '  Pagerank algorithm for the "small" dataset.\n' );
%
%  Get the labels.
%
  label_file = 'small_label.txt';
  labels = labels_extract ( label_file );
%
%  Create a file in which labels have been replaced by indices.
%
  index_file = 'small_index.txt';
  file_labels_to_indices ( label_file, index_file, labels );
%
%  Open the index file, and count the number of nodes ( = rows ).
%
  n = file_row_count ( index_file );
  fprintf ( 1, '  Number of nodes = %d\n', n );
%
%  Create some sparse matrices.
%  A is "adjacency":  A(I,J) = 1 means there is a link from I to J.
%
  A = sparse_from_index_file ( index_file );
  nonzeros = nnz ( A );
  fprintf ( 1, '  Adjacency matrix:\n' );
  fprintf ( 1, '  Number of nonzero elements = %d\n', nonzeros );
%
%  Write the sparse matrix to a sparse matrix file.
%
  [ i, j, s ] = find ( A );
  Adata = [ i, j, s ];
  if ( A(n,n) == 0 )
    Adata = [ Adata; n, n, 0.0 ];
  end
  save ( 'small_sparse.txt', 'Adata', '-ascii' );
%
%  G: The transition matrix modified by the random jump probability.
%  A random walk with G will never get stuck.
%
  p = 0.85;

  G = A';

  for j = 1 : n
    csum = sum ( G(:,j) );
    if ( csum == 0.0 )
      G(:,j) = 1.0 / n;
    else
      G(:,j) = p * G(:,j) / csum;
      i = find ( G(:,j) == 0.0 );
      zsum = length ( i );
      if ( 0 < zsum )
        G(i,j) = ( 1.0 - p ) / zsum;
      end
    end
  end
%
%  Solve G*x = x.
%  x is the eigenvector corresponding to eigenvalue 1.
%  1 is the maximal eigenvalue.
%  eigs will return in column 1 of V the eigenvector corresponding to 
%  the largest eigenvalue.
%
  [ V, D ] = eigs ( G );

  ranking = abs ( V(:,1) ) / norm ( V(:,1), 1 );

  label = 1 : n;
  r8vec2_print ( label, ranking, '  Page rankings:' );

% [ ranking, ndx ] = sort ( ranking, 'descend' )

  return
end
