<commit_before>#ifndef ALEPH_DISTANCES_HAUSDORFF_HH__
#define ALEPH_DISTANCES_HAUSDORFF_HH__

#include "distances/Infinity.hh"
#include "persistenceDiagrams/PersistenceDiagram.hh"

#include <limits>

namespace aleph
{

namespace distances
{

template <
  class DataType,
  class Distance = InfinityDistance<DataType>
> DataType hausdorffDistance( const PersistenceDiagram<DataType>& D1,
                              const PersistenceDiagram<DataType>& D2,
                              Distance d = Distance() )
{
  using PersistenceDiagram = PersistenceDiagram<DataType>;
  using Point              = typename PersistenceDiagram::Point;

  auto&& infimumDistance = [&] ( const Point& p,
                                 const PersistenceDiagram& D,
                                 Distance d )
  {
    DataType infimum = std::numeric_limits<DataType>::max();

    for( auto&& q : D )
      infimum = std::min( infimum, d( p, q ) );

    return infimum;
  };

  DataType supremum1 = std::numeric_limits<DataType>::lowest();

  for( auto&& p : D1 )
    supremum1 = std::max( supremum1, infimumDistance( p, D2, d ) );

  DataType supremum2 = std::numeric_limits<DataType>::lowest();

  for( auto&& p : D2 )
    supremum2 = std::max( supremum2, infimumDistance( p, D1, d ) );

  return std::max( supremum1, supremum2 );
}

}

}

#endif<commit_msg>Documented Hausdorff distance calculations between persistence diagrams<commit_after>#ifndef ALEPH_DISTANCES_HAUSDORFF_HH__
#define ALEPH_DISTANCES_HAUSDORFF_HH__

#include "distances/Infinity.hh"
#include "persistenceDiagrams/PersistenceDiagram.hh"

#include <limits>

namespace aleph
{

namespace distances
{

/**
  Calculates the Hausdorff distance between two persistence diagrams,
  i.e. the Hausdorff distance between their corresponding point sets
  treated as 2D sets.

  By default, the infinity distance ($L_\infty$) is used.
*/

template <
  class DataType,
  class Distance = InfinityDistance<DataType>
> DataType hausdorffDistance( const PersistenceDiagram<DataType>& D1,
                              const PersistenceDiagram<DataType>& D2,
                              Distance d = Distance() )
{
  using PersistenceDiagram = PersistenceDiagram<DataType>;
  using Point              = typename PersistenceDiagram::Point;

  auto&& infimumDistance = [&] ( const Point& p,
                                 const PersistenceDiagram& D,
                                 Distance d )
  {
    DataType infimum = std::numeric_limits<DataType>::max();

    for( auto&& q : D )
      infimum = std::min( infimum, d( p, q ) );

    return infimum;
  };

  DataType supremum1 = std::numeric_limits<DataType>::lowest();

  for( auto&& p : D1 )
    supremum1 = std::max( supremum1, infimumDistance( p, D2, d ) );

  DataType supremum2 = std::numeric_limits<DataType>::lowest();

  for( auto&& p : D2 )
    supremum2 = std::max( supremum2, infimumDistance( p, D1, d ) );

  return std::max( supremum1, supremum2 );
}

} // namespace distances

} // namespace aleph

#endif
{'fraction_non_alphanumeric': 0.10662251655629139, 'fraction_numerical': 0.009602649006622516, 'mean_word_length': 3.033377837116155, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3705007', 'n_tokens_mistral': 981, 'n_tokens_neox': 929, 'n_words': 230}