Changed implementation of WeightedRips to store simplex values (max distance between simplices' vertices) as an invisible layer on top of each simplex object, so that the data() field of WeightedRips has been freed for use by the users again. dev
authorChristos Mantoulidis <cmad@stanford.edu>
Tue, 04 Aug 2009 13:23:16 -0700
branchdev
changeset 156 f75fb57d2831
parent 155 1dde8a05fcd7
child 157 700cbac5b23c
Changed implementation of WeightedRips to store simplex values (max distance between simplices' vertices) as an invisible layer on top of each simplex object, so that the data() field of WeightedRips has been freed for use by the users again.
examples/cohomology/rips-weighted-cohomology.cpp
examples/rips/rips-weighted.cpp
include/topology/simplex.h
include/topology/weighted-rips.h
--- a/examples/cohomology/rips-weighted-cohomology.cpp	Tue Jul 28 15:04:06 2009 -0700
+++ b/examples/cohomology/rips-weighted-cohomology.cpp	Tue Aug 04 13:23:16 2009 -0700
@@ -68,7 +68,7 @@
     
     Timer rips_timer; rips_timer.start();
     rips.generate(skeleton, max_distance, make_push_back_functor(v));
-    std::sort(v.begin(), v.end(), DataDimensionComparison<Smplx>());
+    std::sort(v.begin(), v.end(), cmp);
     rips_timer.stop();
     std::cout << "Simplex vector generated, size: " << v.size() << std::endl;
 
--- a/examples/rips/rips-weighted.cpp	Tue Jul 28 15:04:06 2009 -0700
+++ b/examples/rips/rips-weighted.cpp	Tue Aug 04 13:23:16 2009 -0700
@@ -55,6 +55,7 @@
     PairDistances           distances(points);
     Generator               rips(distances);
     Generator::Evaluator    size(distances);
+    Generator::Comparison   cmp (distances);
     SimplexVector           complex;
     
     // Generate skeleton of the weighted Rips complex for epsilon = 50
@@ -64,7 +65,7 @@
     std::cout << "# Generated complex of size: " << complex.size() << std::endl;
 
     // Generate filtration with respect to distance and compute its persistence
-    Fltr f(complex.begin(), complex.end(), DataDimensionComparison<Smplx>());
+    Fltr f(complex.begin(), complex.end(), cmp);
 
     Timer persistence_timer; persistence_timer.start();
     Persistence p(f);
--- a/include/topology/simplex.h	Tue Jul 28 15:04:06 2009 -0700
+++ b/include/topology/simplex.h	Tue Aug 04 13:23:16 2009 -0700
@@ -127,12 +127,12 @@
         struct DataEvaluator;
         struct DimensionExtractor;
     
-    private:
+    protected:
         VertexContainer&        vertices()                                          { return vdpair_.first(); }
 
         VerticesDataPair        vdpair_;
 
-    private:
+    protected:
         /* Serialization */
         friend class boost::serialization::access;
         
--- a/include/topology/weighted-rips.h	Tue Jul 28 15:04:06 2009 -0700
+++ b/include/topology/weighted-rips.h	Tue Aug 04 13:23:16 2009 -0700
@@ -8,6 +8,33 @@
 #include <boost/iterator/counting_iterator.hpp>
 
 /**
+ * WeightedRipsSimplex class
+ * 
+ * This class sits as an invisible layer between the Simplex datatype passed
+ * to WeightedRips and the class itself. The need for this layer is the need
+ * to store the ``value'' (max inter-vertex distance) of each simplex in the
+ * Weighted Rips complex--something that the user of the class does not need
+ * to be aware of.
+ */
+
+template<class Simplex_, class DistanceType_>
+class WeightedRipsSimplex : public Simplex_
+{
+    public:
+        typedef          typename Simplex_::Vertex                 Vertex;
+        typedef          typename Simplex_::VertexContainer        VertexContainer;
+        typedef          DistanceType_                             DistanceType;
+
+        WeightedRipsSimplex(Simplex_ s) : Simplex_(s)  { }
+
+        void             setSimplexValue(const DistanceType &sv) { simplexValue = sv; }
+        DistanceType     getSimplexValue() const       { return    simplexValue;      }
+
+    protected:
+        DistanceType     simplexValue;
+};
+
+/**
  * WeightedRips class
  *
  * Class providing basic operations to work with Rips complexes. It implements Bron-Kerbosch algorithm, 
@@ -18,7 +45,7 @@
  *               the distance between them. There should be methods begin() and end() 
  *               for iterating over IndexTypes as well as a method size().
  */
-template<class Distances_, class Simplex_ = Simplex<typename Distances_::IndexType, typename Distances_::DistanceType> >
+template<class Distances_, class Simplex_ = Simplex<typename Distances_::IndexType> >
 class WeightedRips : public Rips<Distances_, Simplex_>
 {
     public:
@@ -28,7 +55,7 @@
         typedef             typename Distances::IndexType                   IndexType;
         typedef             typename Distances::DistanceType                DistanceType;
 
-        typedef             Simplex_                                        Simplex;
+        typedef             WeightedRipsSimplex<Simplex_, DistanceType>     Simplex;
         typedef             typename Simplex::Vertex                        Vertex;             // should be the same as IndexType
         typedef             typename Simplex::VertexContainer               VertexContainer;
 
@@ -68,8 +95,8 @@
 		void operator()(const Simplex_ &s) const
 		{
 			Simplex_         s_new(s);
-			s_new.data()   = rips.distance(s_new, s_new);
-			original_functor(s_new);
+			s_new.setSimplexValue (rips.distance(s_new, s_new));
+			original_functor      (s_new);
 		}
 
 	private:
@@ -79,23 +106,23 @@
 
 template<class Distances_, class Simplex_>
 template<class Functor>
-void WeightedRips<Distances_,Simplex_>::generate(Dimension k, DistanceType max, const Functor &f) const
+void WeightedRips<Distances_, Simplex_>::generate(Dimension k, DistanceType max, const Functor &f) const
 {
-	Rips<Distances_,Simplex_>::generate(k, max, DistanceDataStackingFunctor<WeightedRips<Distances_,Simplex_>,Functor>(*this, f));
+	Rips<Distances_,Simplex_>::generate(k, max, DistanceDataStackingFunctor<WeightedRips<Distances_, Simplex_>,Functor>(*this, f));
 }
 
 template<class Distances_, class Simplex_>
-class WeightedRips<Distances_, Simplex_>::Evaluator: public Rips<Distances_, Simplex_>::Evaluator
+class WeightedRips<Distances_, Simplex_>::Evaluator: public Rips<Distances_,Simplex_>::Evaluator
 {
     public:
                             Evaluator(const Distances& distances): 
                                 Rips<Distances_, Simplex_>::Evaluator(distances)                       {}
 
-        DistanceType       operator()(const Simplex& s) const { return s.data(); }
+        DistanceType       operator()(const Simplex& s) const { return s.getSimplexValue(); }
 };
 
 template<class Distances_, class Simplex_>
-class WeightedRips<Distances_, Simplex_>::Comparison: public Rips<Distances_, Simplex_>::Comparison
+class WeightedRips<Distances_, Simplex_>::Comparison: public Rips<Distances_,Simplex_>::Comparison
 {
     public:
                             Comparison(const Distances& distances):
@@ -105,7 +132,7 @@
         { 
                             if (s1.dimension() != s2.dimension())
                                 return s1.dimension() < s2.dimension();
-                            return s1.data() < s2.data();
+                            return s1.getSimplexValue() < s2.getSimplexValue();
         }
 };