summaryrefslogtreecommitdiff
path: root/src/Gudhi_stat/include/gudhi/concretizations
diff options
context:
space:
mode:
authorpdlotko <pdlotko@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2016-12-05 13:07:14 +0000
committerpdlotko <pdlotko@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2016-12-05 13:07:14 +0000
commit28fd0e09e42425b12929990542f739f8334c13f0 (patch)
tree0b25f86267a7f0e80f2049c4ea5e7a3674fafb68 /src/Gudhi_stat/include/gudhi/concretizations
parenta29bef76572ff6fde8f982a81f317d1d3dd74c04 (diff)
adding arytmetic operations to heat maps and persistence vectors. Now any representation for which arythmetic operations make sense have them defined. This can be used for interpolation and extrapolation (among many others).
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/gudhi_stat@1818 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 257abd97dfdb7725dabd7d04558268ceec389004
Diffstat (limited to 'src/Gudhi_stat/include/gudhi/concretizations')
-rw-r--r--src/Gudhi_stat/include/gudhi/concretizations/Persistence_heat_maps.h116
-rw-r--r--src/Gudhi_stat/include/gudhi/concretizations/Vector_distances_in_diagram.h128
2 files changed, 241 insertions, 3 deletions
diff --git a/src/Gudhi_stat/include/gudhi/concretizations/Persistence_heat_maps.h b/src/Gudhi_stat/include/gudhi/concretizations/Persistence_heat_maps.h
index df7c97af..83583a57 100644
--- a/src/Gudhi_stat/include/gudhi/concretizations/Persistence_heat_maps.h
+++ b/src/Gudhi_stat/include/gudhi/concretizations/Persistence_heat_maps.h
@@ -329,6 +329,122 @@ public:
void plot( const char* filename )const;
+ //implementation of arythmetic operations:
+
+ friend Persistence_heat_maps operation_on_pair_of_heat_maps( const Persistence_heat_maps& first , const Persistence_heat_maps& second , double (*opertion)( double,double ) )
+ {
+ //first check if the heat maps are compatible
+ if ( !first.check_if_the_same( second ) )
+ {
+ std::cerr << "Sizes of the heat maps are not compatible. The program will now terminate \n";
+ throw "Sizes of the heat maps are not compatible. The program will now terminate \n";
+ }
+ Persistence_heat_maps result;
+ result.min_ = first.min_;
+ result.max_ = first.max_;
+ result.heat_map.reserve( first.heat_map.size() );
+ for ( size_t i = 0 ; i != first.heat_map.size() ; ++i )
+ {
+ std::vector< double > v;
+ v.reserve( first.heat_map[i].size() );
+ for ( size_t j = 0 ; j != first.heat_map[i].size() ; ++j )
+ {
+ v.push_back( opertion( first.heat_map[i][j] , second.heat_map[i][j] ) );
+ }
+ result.heat_map.push_back( v );
+ }
+ return result;
+ }//operation_on_pair_of_heat_maps
+
+ Persistence_heat_maps multiply_by_scalar( double scalar )const
+ {
+ Persistence_heat_maps result;
+ result.min_ = this->min_;
+ result.max_ = this->max_;
+ result.heat_map.reserve( this->heat_map.size() );
+ for ( size_t i = 0 ; i != this->heat_map.size() ; ++i )
+ {
+ std::vector< double > v;
+ v.reserve( this->heat_map[i].size() );
+ for ( size_t j = 0 ; j != this->heat_map[i].size() ; ++j )
+ {
+ v.push_back( this->heat_map[i][j] * scalar );
+ }
+ result.heat_map.push_back( v );
+ }
+ return result;
+ }
+
+ /**
+ * This function computes a sum of two objects of a type Vector_distances_in_diagram.
+ **/
+ friend Persistence_heat_maps operator+( const Persistence_heat_maps& first , const Persistence_heat_maps& second )
+ {
+ return operation_on_pair_of_heat_maps( first , second , plus_ );
+ }
+ /**
+ * This function computes a difference of two objects of a type Vector_distances_in_diagram.
+ **/
+ friend Persistence_heat_maps operator-( const Persistence_heat_maps& first , const Persistence_heat_maps& second )
+ {
+ return operation_on_pair_of_heat_maps( first , second , minus_ );
+ }
+ /**
+ * This function computes a product of an object of a type Vector_distances_in_diagram with real number.
+ **/
+ friend Persistence_heat_maps operator*( double scalar , const Persistence_heat_maps& A )
+ {
+ return A.multiply_by_scalar( scalar );
+ }
+ /**
+ * This function computes a product of an object of a type Vector_distances_in_diagram with real number.
+ **/
+ friend Persistence_heat_maps operator*( const Persistence_heat_maps& A , double scalar )
+ {
+ return A.multiply_by_scalar( scalar );
+ }
+ /**
+ * This function computes a product of an object of a type Vector_distances_in_diagram with real number.
+ **/
+ Persistence_heat_maps operator*( double scalar )
+ {
+ return this->multiply_by_scalar( scalar );
+ }
+ /**
+ * += operator for Vector_distances_in_diagram.
+ **/
+ Persistence_heat_maps operator += ( const Persistence_heat_maps& rhs )
+ {
+ *this = *this + rhs;
+ return *this;
+ }
+ /**
+ * -= operator for Vector_distances_in_diagram.
+ **/
+ Persistence_heat_maps operator -= ( const Persistence_heat_maps& rhs )
+ {
+ *this = *this - rhs;
+ return *this;
+ }
+ /**
+ * *= operator for Vector_distances_in_diagram.
+ **/
+ Persistence_heat_maps operator *= ( double x )
+ {
+ *this = *this*x;
+ return *this;
+ }
+ /**
+ * /= operator for Vector_distances_in_diagram.
+ **/
+ Persistence_heat_maps operator /= ( double x )
+ {
+ if ( x == 0 )throw( "In operator /=, division by 0. Program terminated." );
+ *this = *this * (1/x);
+ return *this;
+ }
+
+
//Implementations of functions for various concepts.
/**
diff --git a/src/Gudhi_stat/include/gudhi/concretizations/Vector_distances_in_diagram.h b/src/Gudhi_stat/include/gudhi/concretizations/Vector_distances_in_diagram.h
index 9d02e917..11e4b163 100644
--- a/src/Gudhi_stat/include/gudhi/concretizations/Vector_distances_in_diagram.h
+++ b/src/Gudhi_stat/include/gudhi/concretizations/Vector_distances_in_diagram.h
@@ -76,6 +76,8 @@ struct Maximum_distance
};
+
+
/**
* This is an implementation of idea presented in the paper by Steve, Matthew and Max. The parameter of the class is the class that computes distance used to construct the vectors. The typical function is
* either Eucludean of maximum (Manhattan) distance.
@@ -284,6 +286,124 @@ public:
if ( this->sorted_vector_of_distances.size() == 0 )return std::make_pair(0,0);
return std::make_pair( this->sorted_vector_of_distances[0] , 0);
}
+
+ //arythmetic operations:
+ /**
+ * This is a generic function that allows to perform binary operations on two Vector_distances_in_diagram. It will be used later to defien sums and differences of Vector_distances_in_diagram.
+ **/
+ //template < typename Operation_type >
+ friend Vector_distances_in_diagram operation_on_pair_of_vectors( const Vector_distances_in_diagram& first , const Vector_distances_in_diagram& second , double (*opertion)( double,double ) )
+ {
+ Vector_distances_in_diagram result;
+ //Operation_type operation;
+ result.sorted_vector_of_distances.reserve(std::max( first.sorted_vector_of_distances.size() , second.sorted_vector_of_distances.size() ) );
+ for ( size_t i = 0 ; i != std::min( first.sorted_vector_of_distances.size() , second.sorted_vector_of_distances.size() ) ; ++i )
+ {
+ result.sorted_vector_of_distances.push_back( opertion( first.sorted_vector_of_distances[i] , second.sorted_vector_of_distances[i]) );
+ }
+ if ( first.sorted_vector_of_distances.size() == std::min( first.sorted_vector_of_distances.size() , second.sorted_vector_of_distances.size() ) )
+ {
+ for ( size_t i = std::min( first.sorted_vector_of_distances.size() , second.sorted_vector_of_distances.size() ) ;
+ i != std::max( first.sorted_vector_of_distances.size() , second.sorted_vector_of_distances.size() ) ; ++i )
+ {
+ result.sorted_vector_of_distances.push_back( opertion(0,second.sorted_vector_of_distances[i]) );
+ }
+ }
+ else
+ {
+ for ( size_t i = std::min( first.sorted_vector_of_distances.size() , second.sorted_vector_of_distances.size() ) ;
+ i != std::max( first.sorted_vector_of_distances.size() , second.sorted_vector_of_distances.size() ) ; ++i )
+ {
+ result.sorted_vector_of_distances.push_back( opertion(first.sorted_vector_of_distances[i],0) );
+ }
+ }
+ return result;
+ }//operation_on_pair_of_vectors
+
+ /**
+ * This function implements an operation of multiplying Vector_distances_in_diagram by a scalar.
+ **/
+ Vector_distances_in_diagram multiply_by_scalar( double scalar )const
+ {
+ Vector_distances_in_diagram result;
+ result.sorted_vector_of_distances.reserve( this->sorted_vector_of_distances.size() );
+ for ( size_t i = 0 ; i != this->sorted_vector_of_distances.size() ; ++i )
+ {
+ result.sorted_vector_of_distances.push_back( scalar * this->sorted_vector_of_distances[i] );
+ }
+ return result;
+ }//multiply_by_scalar
+
+
+
+ /**
+ * This function computes a sum of two objects of a type Vector_distances_in_diagram.
+ **/
+ friend Vector_distances_in_diagram operator+( const Vector_distances_in_diagram& first , const Vector_distances_in_diagram& second )
+ {
+ return operation_on_pair_of_vectors( first , second , plus_ );
+ }
+ /**
+ * This function computes a difference of two objects of a type Vector_distances_in_diagram.
+ **/
+ friend Vector_distances_in_diagram operator-( const Vector_distances_in_diagram& first , const Vector_distances_in_diagram& second )
+ {
+ return operation_on_pair_of_vectors( first , second , minus_ );
+ }
+ /**
+ * This function computes a product of an object of a type Vector_distances_in_diagram with real number.
+ **/
+ friend Vector_distances_in_diagram operator*( double scalar , const Vector_distances_in_diagram& A )
+ {
+ return A.multiply_by_scalar( scalar );
+ }
+ /**
+ * This function computes a product of an object of a type Vector_distances_in_diagram with real number.
+ **/
+ friend Vector_distances_in_diagram operator*( const Vector_distances_in_diagram& A , double scalar )
+ {
+ return A.multiply_by_scalar( scalar );
+ }
+ /**
+ * This function computes a product of an object of a type Vector_distances_in_diagram with real number.
+ **/
+ Vector_distances_in_diagram operator*( double scalar )
+ {
+ return this->multiply_by_scalar( scalar );
+ }
+ /**
+ * += operator for Vector_distances_in_diagram.
+ **/
+ Vector_distances_in_diagram operator += ( const Vector_distances_in_diagram& rhs )
+ {
+ *this = *this + rhs;
+ return *this;
+ }
+ /**
+ * -= operator for Vector_distances_in_diagram.
+ **/
+ Vector_distances_in_diagram operator -= ( const Vector_distances_in_diagram& rhs )
+ {
+ *this = *this - rhs;
+ return *this;
+ }
+ /**
+ * *= operator for Vector_distances_in_diagram.
+ **/
+ Vector_distances_in_diagram operator *= ( double x )
+ {
+ *this = *this*x;
+ return *this;
+ }
+ /**
+ * /= operator for Vector_distances_in_diagram.
+ **/
+ Vector_distances_in_diagram operator /= ( double x )
+ {
+ if ( x == 0 )throw( "In operator /=, division by 0. Program terminated." );
+ *this = *this * (1/x);
+ return *this;
+ }
private:
@@ -493,11 +613,11 @@ void Vector_distances_in_diagram<F>::compute_sorted_vector_of_distances_via_vect
template <typename F>
double Vector_distances_in_diagram<F>::project_to_R( int number_of_function )const
{
- if ( number_of_function > this->number_of_functions_for_projections_to_reals )throw "Wrong index of a function in a method Vector_distances_in_diagram<F>::project_to_R";
+ if ( (size_t)number_of_function > this->number_of_functions_for_projections_to_reals )throw "Wrong index of a function in a method Vector_distances_in_diagram<F>::project_to_R";
if ( number_of_function < 0 )throw "Wrong index of a function in a method Vector_distances_in_diagram<F>::project_to_R";
double result = 0;
- for ( size_t i = 0 ; i != number_of_function ; ++i )
+ for ( size_t i = 0 ; i != (size_t)number_of_function ; ++i )
{
result += sorted_vector_of_distances[i];
}
@@ -604,7 +724,7 @@ double Vector_distances_in_diagram<F>::distance( const Vector_distances_in_diagr
template < typename F>
std::vector<double> Vector_distances_in_diagram<F>::vectorize( int number_of_function )const
{
- if ( number_of_function > this->number_of_functions_for_vectorization )throw "Wrong index of a function in a method Vector_distances_in_diagram<F>::vectorize";
+ if ( (size_t)number_of_function > this->number_of_functions_for_vectorization )throw "Wrong index of a function in a method Vector_distances_in_diagram<F>::vectorize";
if ( number_of_function < 0 )throw "Wrong index of a function in a method Vector_distances_in_diagram<F>::vectorize";
std::vector< double > result( std::min( (size_t)number_of_function , this->sorted_vector_of_distances.size() ) );
@@ -665,6 +785,8 @@ double Vector_distances_in_diagram<F>::compute_scalar_product( const Vector_dist
+
+
}//namespace Gudhi_stat
}//namespace Gudhi