diff options
author | Vincent Rouvreau <10407034+VincentRouvreau@users.noreply.github.com> | 2020-05-15 14:34:03 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-15 14:34:03 +0200 |
commit | db10582cb0f8fecba654153d248142489ab6b883 (patch) | |
tree | 30e6e8918c4fb4a6afc9dd36261c952abb618a21 /src/python/gudhi | |
parent | 9fb4015f9ccd394146bc436d7011d7855d919837 (diff) | |
parent | 4d27d32308f94e63d76bbd5564b8837b94b24339 (diff) |
Merge pull request #295 from yuichi-ike/weighted_rips
Weighted rips
Diffstat (limited to 'src/python/gudhi')
-rw-r--r-- | src/python/gudhi/weighted_rips_complex.py | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/python/gudhi/weighted_rips_complex.py b/src/python/gudhi/weighted_rips_complex.py new file mode 100644 index 00000000..0541572b --- /dev/null +++ b/src/python/gudhi/weighted_rips_complex.py @@ -0,0 +1,59 @@ +# This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT. +# See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details. +# Author(s): Raphaƫl Tinarrage, Yuichi Ike, Masatoshi Takenouchi +# +# Copyright (C) 2020 Inria, Copyright (C) 2020 FUjitsu Laboratories Ltd. +# +# Modification(s): +# - YYYY/MM Author: Description of the modification + +from gudhi import SimplexTree + +class WeightedRipsComplex: + """ + Class to generate a weighted Rips complex from a distance matrix and weights on vertices, + in the way described in :cite:`dtmfiltrations`. + Remark that all the filtration values are doubled compared to the definition in the paper + for the consistency with RipsComplex. + """ + def __init__(self, + distance_matrix, + weights=None, + max_filtration=float('inf')): + """ + Args: + distance_matrix (Sequence[Sequence[float]]): distance matrix (full square or lower triangular). + weights (Sequence[float]): (one half of) weight for each vertex. + max_filtration (float): specifies the maximal filtration value to be considered. + """ + self.distance_matrix = distance_matrix + if weights is not None: + self.weights = weights + else: + self.weights = [0] * len(distance_matrix) + self.max_filtration = max_filtration + + def create_simplex_tree(self, max_dimension): + """ + Args: + max_dimension (int): graph expansion until this given dimension. + """ + dist = self.distance_matrix + F = self.weights + num_pts = len(dist) + + st = SimplexTree() + + for i in range(num_pts): + if 2*F[i] <= self.max_filtration: + st.insert([i], 2*F[i]) + for i in range(num_pts): + for j in range(i): + value = max(2*F[i], 2*F[j], dist[i][j] + F[i] + F[j]) + # max is needed when F is not 1-Lipschitz + if value <= self.max_filtration: + st.insert([i,j], filtration=value) + + st.expansion(max_dimension) + return st + |