Skip to content

Commit

Permalink
Added test for nearest neighbour distance between persistence diagrams
Browse files Browse the repository at this point in the history
  • Loading branch information
Pseudomanifold committed Jun 29, 2017
1 parent 6dc0084 commit 689597a
Showing 1 changed file with 37 additions and 17 deletions.
54 changes: 37 additions & 17 deletions tests/test_persistence_diagrams.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <tests/Base.hh>

#include <aleph/distances/NearestNeighbour.hh>
#include <aleph/distances/Wasserstein.hh>

#include <aleph/persistenceDiagrams/Mean.hh>
Expand Down Expand Up @@ -36,6 +37,31 @@ template <class T> aleph::PersistenceDiagram<T> createRandomPersistenceDiagram(
return D;
}

template <class T> void testFrechetMean()
{
using PersistenceDiagram = aleph::PersistenceDiagram<T>;

ALEPH_TEST_BEGIN( "Persistence diagram mean");

unsigned n = 10;

std::vector<PersistenceDiagram> diagrams;
diagrams.reserve( n );

for( decltype(n) i = 0; i < n; i++ )
diagrams.emplace_back( createRandomPersistenceDiagram<T>( 25 ) );

auto D = aleph::mean( diagrams.begin(), diagrams.end() );
auto P = aleph::totalPersistence( D );
auto p = std::sqrt(25.0) * std::sqrt(0.50); // simple estimate of the mean value
// for the total persistence

ALEPH_ASSERT_THROW( D.size() > 0 );
ALEPH_ASSERT_THROW( std::abs( P - p ) < 1.0 );

ALEPH_TEST_END();
}

template <class T> void testMultiScaleKernel()
{
ALEPH_TEST_BEGIN( "Multi-scale kernel" );
Expand Down Expand Up @@ -63,31 +89,22 @@ template <class T> void testMultiScaleKernel()
ALEPH_TEST_END();
}

template <class T> void testFrechetMean()
template <class T> void testNearestNeighbourDistance()
{
using PersistenceDiagram = aleph::PersistenceDiagram<T>;

ALEPH_TEST_BEGIN( "Persistence diagram mean");
ALEPH_TEST_BEGIN( "Nearest neighbour distance" );

unsigned n = 10;

std::vector<PersistenceDiagram> diagrams;
diagrams.reserve( n );

for( decltype(n) i = 0; i < n; i++ )
diagrams.emplace_back( createRandomPersistenceDiagram<T>( 25 ) );
auto D1 = createRandomPersistenceDiagram<T>( 50 );
auto D2 = createRandomPersistenceDiagram<T>( 50 );

auto D = aleph::mean( diagrams.begin(), diagrams.end() );
auto P = aleph::totalPersistence( D );
auto p = std::sqrt(25.0) * std::sqrt(0.50); // simple estimate of the mean value
// for the total persistence
auto dNearestNeighbour = aleph::distances::nearestNeighbourDistance( D1, D2 );
auto dWasserstein = aleph::distances::wassersteinDistance( D1, D2, T(1) );

ALEPH_ASSERT_THROW( D.size() > 0 );
ALEPH_ASSERT_THROW( std::abs( P - p ) < 1.0 );
ALEPH_ASSERT_THROW( dNearestNeighbour < dWasserstein );

ALEPH_TEST_END();
}


template <class T> void testWassersteinDistance()
{
using Diagram = aleph::PersistenceDiagram<T>;
Expand Down Expand Up @@ -135,6 +152,9 @@ int main(int, char**)
testMultiScaleKernel<float> ();
testMultiScaleKernel<double>();

testNearestNeighbourDistance<float> ();
testNearestNeighbourDistance<double>();

testWassersteinDistance<float> ();
testWassersteinDistance<double>();
}

0 comments on commit 689597a

Please sign in to comment.