Skip to content

Commit

Permalink
Improved persistence diagram processing
Browse files Browse the repository at this point in the history
The diagrams are now returned and extended to the desired
dimensionality. While the code does not yet ensure that a
sequence of contiguous diagrams is returned, it *will* do
a small check to alert users if that is not the case.
  • Loading branch information
Pseudomanifold committed Jan 3, 2020
1 parent 124b692 commit d3cec7e
Showing 1 changed file with 32 additions and 26 deletions.
58 changes: 32 additions & 26 deletions src/tools/ephemeral.cc
Expand Up @@ -22,6 +22,7 @@

#include <aleph/utilities/Filesystem.hh>

#include <cassert>
#include <cmath>

#include <algorithm>
Expand Down Expand Up @@ -101,11 +102,12 @@ void usage()
<< "\n";
}

void processFilename( const std::string& filename,
double infinity,
bool keepUnpaired,
bool verbose,
aleph::topology::io::AdjacencyMatrixReader reader )
std::vector<PersistenceDiagram> processFilename( const std::string& filename,
double infinity,
bool keepUnpaired,
bool verbose,
unsigned numDiagrams,
aleph::topology::io::AdjacencyMatrixReader reader )
{
if( verbose )
std::cerr << "* Processing " << filename << "...";
Expand All @@ -123,6 +125,20 @@ void processFilename( const std::string& filename,
dualize,
includeAllUnpairedCreators );

diagrams.resize( numDiagrams );

// Ensures that non-empty diagrams follow the indexing of the vector.
// For example, if we have data for dimensions 0 and 1, the diagrams
// should be stored at index 0 and 1, respectively. This is a sanity
// check that will fail if the data behaves weirdly.
for( std::size_t i = 0; i < diagrams.size(); i++ )
{
auto&& D = diagrams[i];

if( !D.empty() )
assert( D.dimension() == i );
}

if( verbose )
std::cerr << "finished\n";

Expand All @@ -143,16 +159,9 @@ void processFilename( const std::string& filename,
}
);
}

// Stores additional data about each persistence diagram in order
// to make it easier to keep track of information.
std::map<std::string, std::string> kvs;

kvs["total_persistence_1"] = std::to_string( aleph::totalPersistence( diagram, 1.0 ) );
kvs["total_persistence_2"] = std::to_string( aleph::totalPersistence( diagram, 2.0 ) );

aleph::io::writeJSON( std::cout, diagram, basename, kvs );
}

return diagrams;
}

int main( int argc, char** argv )
Expand Down Expand Up @@ -223,20 +232,17 @@ int main( int argc, char** argv )
aleph::topology::io::AdjacencyMatrixReader::VertexWeightAssignmentStrategy::AssignGlobalMinimum
);

std::cout << "{\n"
<< "\"diagrams\": [\n";

for( auto&& filename : filenames )
{
processFilename( filename,
infinity,
keepUnpaired,
verbose,
reader
auto diagrams = processFilename( filename,
infinity,
keepUnpaired,
verbose,
numDiagrams,
reader
);
}

std::cout << "\n"
<< "]\n"
<< "}\n";
for( auto&& D : diagrams )
std::cout << D << "\n";
}
}

0 comments on commit d3cec7e

Please sign in to comment.