Skip to content

Commit

Permalink
First attempt at specifying how to build coface generating simplex st…
Browse files Browse the repository at this point in the history
…reams, and an implementation of approximately what Ripser does for the dense metric matrix case.
  • Loading branch information
Mikael Vejdemo-Johansson committed Sep 30, 2024
1 parent 0c0a404 commit a623867
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions src/main/scala/org/appliedtopology/tda4j/SimplexStream.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.appliedtopology.tda4j

import org.apache.commons.numbers.combinatorics.BinomialCoefficient

import scala.collection.mutable
import scala.collection.immutable.{Map, Seq, SortedSet}
import math.Ordering.Implicits.*
Expand Down Expand Up @@ -198,3 +200,64 @@ trait StratifiedCellStream[CellT: OrderedCell, FiltrationT: Filterable] extends

trait StratifiedSimplexStream[VertexT: Ordering, FiltrationT: Filterable]
extends StratifiedCellStream[Simplex[VertexT], FiltrationT] {}

trait CofaceSimplexStream[VertexT: Ordering, FiltrationT: Filterable]
extends StratifiedSimplexStream[VertexT, FiltrationT] {

def currentDimension : Int

def lastDimensionCache : Seq[Simplex[VertexT]]

def currentDimensionCache : Seq[Simplex[VertexT]]

def pruneAllCofaces : Boolean

def keepCriterion : PartialFunction[Simplex[VertexT], Boolean]
}

case class RipserCofaceSimplexStream[VertexT : Ordering](
metricSpace: FiniteMetricSpace[VertexT],
keepCriterion : PartialFunction[Simplex[VertexT], Boolean] = {case _ => True}
) extends CofaceSimplexStream[VertexT, Double] with DoubleFiltration[Simplex[VertexT]]() {

lazy val edges = for
i <- metricSpace.elements
j <- metricSpace.elements
if(i < j)
yield
Simplex(i,j)

override var currentDimension: Int = 0

override var lastDimensionCache: IndexedSeq[Simplex[VertexT]] = IndexedSeq()

override var currentDimensionCache: IndexedSeq[Simplex[VertexT]] = IndexedSeq()

override def pruneAllCofaces: Boolean = False

override val filtrationValue: PartialFunction[Simplex[VertexT], Double] =
FiniteMetricSpace.MaximumDistanceFiltrationValue[VertexT](metricSpace)

override val filtrationOrdering: Ordering[Simplex[VertexT]] =
Ordering.by(filtrationValue)

var finishedCurrent : Boolean = false

lazy val simplexIndexing : SimplexIndexing = SimplexIndexing(metricSpace.size)

override def iterateDimension: PartialFunction[Int, Iterator[Simplex[VertexT]]] = {
case 0 => metricSpace.elements.map(Simplex.apply).iterator
case 1 => edges.toSeq.sortBy(filtrationValue).iterator
case d => {
// first, generate all simplices of this dimension
(0 to BinomialCoefficient.value(metricSpace.size, d + 1))
.toSeq
.map { (ix) =>
simplexIndexing(ix, d)
}
.filter(keepCriterion.applyOrElse(_, _ => true))
.sortBy(filtrationValue)
.iterator
}
}
}

0 comments on commit a623867

Please sign in to comment.