diff options
Diffstat (limited to 'examples/gromov')
-rw-r--r-- | examples/gromov/plot_barycenter_fgw.py | 12 | ||||
-rw-r--r-- | examples/gromov/plot_fgw.py | 2 | ||||
-rw-r--r-- | examples/gromov/plot_gromov.py | 2 | ||||
-rwxr-xr-x | examples/gromov/plot_gromov_barycenter.py | 2 | ||||
-rwxr-xr-x | examples/gromov/plot_gromov_wasserstein_dictionary_learning.py | 24 | ||||
-rw-r--r-- | examples/gromov/plot_semirelaxed_fgw.py | 16 |
6 files changed, 29 insertions, 29 deletions
diff --git a/examples/gromov/plot_barycenter_fgw.py b/examples/gromov/plot_barycenter_fgw.py index dc3c6aa..3b5db8b 100644 --- a/examples/gromov/plot_barycenter_fgw.py +++ b/examples/gromov/plot_barycenter_fgw.py @@ -34,8 +34,8 @@ from ot.gromov import fgw_barycenters def find_thresh(C, inf=0.5, sup=3, step=10): """ Trick to find the adequate thresholds from where value of the C matrix are considered close enough to say that nodes are connected - Tthe threshold is found by a linesearch between values "inf" and "sup" with "step" thresholds tested. - The optimal threshold is the one which minimizes the reconstruction error between the shortest_path matrix coming from the thresholded adjency matrix + The threshold is found by a linesearch between values "inf" and "sup" with "step" thresholds tested. + The optimal threshold is the one which minimizes the reconstruction error between the shortest_path matrix coming from the thresholded adjacency matrix and the original matrix. Parameters ---------- @@ -51,15 +51,15 @@ def find_thresh(C, inf=0.5, sup=3, step=10): dist = [] search = np.linspace(inf, sup, step) for thresh in search: - Cprime = sp_to_adjency(C, 0, thresh) + Cprime = sp_to_adjacency(C, 0, thresh) SC = shortest_path(Cprime, method='D') SC[SC == float('inf')] = 100 dist.append(np.linalg.norm(SC - C)) return search[np.argmin(dist)], dist -def sp_to_adjency(C, threshinf=0.2, threshsup=1.8): - """ Thresholds the structure matrix in order to compute an adjency matrix. +def sp_to_adjacency(C, threshinf=0.2, threshsup=1.8): + """ Thresholds the structure matrix in order to compute an adjacency matrix. All values between threshinf and threshsup are considered representing connected nodes and set to 1. Else are set to 0 Parameters ---------- @@ -174,7 +174,7 @@ A, C, log = fgw_barycenters(sizebary, Ys, Cs, ps, lambdas, alpha=0.95, log=True) # ------------------------- #%% Create the barycenter -bary = nx.from_numpy_array(sp_to_adjency(C, threshinf=0, threshsup=find_thresh(C, sup=100, step=100)[0])) +bary = nx.from_numpy_array(sp_to_adjacency(C, threshinf=0, threshsup=find_thresh(C, sup=100, step=100)[0])) for i, v in enumerate(A.ravel()): bary.add_node(i, attr_name=v) diff --git a/examples/gromov/plot_fgw.py b/examples/gromov/plot_fgw.py index 5475fb3..bf10de6 100644 --- a/examples/gromov/plot_fgw.py +++ b/examples/gromov/plot_fgw.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """ ============================== -Plot Fused-gromov-Wasserstein +Plot Fused-Gromov-Wasserstein ============================== This example illustrates the computation of FGW for 1D measures [18]. diff --git a/examples/gromov/plot_gromov.py b/examples/gromov/plot_gromov.py index 05074dc..afb5bdc 100644 --- a/examples/gromov/plot_gromov.py +++ b/examples/gromov/plot_gromov.py @@ -3,7 +3,7 @@ ==========================
Gromov-Wasserstein example
==========================
-This example is designed to show how to use the Gromov-Wassertsein distance
+This example is designed to show how to use the Gromov-Wasserstein distance
computation in POT.
"""
diff --git a/examples/gromov/plot_gromov_barycenter.py b/examples/gromov/plot_gromov_barycenter.py index 08ec610..1b9abbf 100755 --- a/examples/gromov/plot_gromov_barycenter.py +++ b/examples/gromov/plot_gromov_barycenter.py @@ -36,7 +36,7 @@ import ot def smacof_mds(C, dim, max_iter=3000, eps=1e-9):
"""
Returns an interpolated point cloud following the dissimilarity matrix C
- using SMACOF multidimensional scaling (MDS) in specific dimensionned
+ using SMACOF multidimensional scaling (MDS) in specific dimensioned
target space
Parameters
diff --git a/examples/gromov/plot_gromov_wasserstein_dictionary_learning.py b/examples/gromov/plot_gromov_wasserstein_dictionary_learning.py index 7585944..8cccf88 100755 --- a/examples/gromov/plot_gromov_wasserstein_dictionary_learning.py +++ b/examples/gromov/plot_gromov_wasserstein_dictionary_learning.py @@ -1,11 +1,11 @@ # -*- coding: utf-8 -*- r""" -================================= +===================================================== (Fused) Gromov-Wasserstein Linear Dictionary Learning -================================= +===================================================== -In this exemple, we illustrate how to learn a Gromov-Wasserstein dictionary on +In this example, we illustrate how to learn a Gromov-Wasserstein dictionary on a dataset of structured data such as graphs, denoted :math:`\{ \mathbf{C_s} \}_{s \in [S]}` where every nodes have uniform weights. Given a dictionary :math:`\mathbf{C_{dict}}` composed of D structures of a fixed @@ -49,7 +49,7 @@ from networkx.generators.community import stochastic_block_model as sbm ############################################################################# # # Generate a dataset composed of graphs following Stochastic Block models of 1, 2 and 3 clusters. -# --------------------------------------------- +# ----------------------------------------------------------------------------------------------- np.random.seed(42) @@ -112,8 +112,8 @@ pl.show() ############################################################################# # -# Estimate the gromov-wasserstein dictionary from the dataset -# --------------------------------------------- +# Estimate the Gromov-Wasserstein dictionary from the dataset +# ----------------------------------------------------------- np.random.seed(0) @@ -144,7 +144,7 @@ pl.show() ############################################################################# # # Visualization of the estimated dictionary atoms -# --------------------------------------------- +# ----------------------------------------------- # Continuous connections between nodes of the atoms are colored in shades of grey (1: dark / 2: white) @@ -169,7 +169,7 @@ pl.show() ############################################################################# # # Visualization of the embedding space -# --------------------------------------------- +# ------------------------------------ unmixings = [] reconstruction_errors = [] @@ -217,7 +217,7 @@ pl.show() ############################################################################# # # Endow the dataset with node features -# --------------------------------------------- +# ------------------------------------ # We follow this feature assignment on all nodes of a graph depending on its label/number of clusters # 1 cluster --> 0 as nodes feature # 2 clusters --> 1 as nodes feature @@ -257,7 +257,7 @@ pl.show() ############################################################################# # # Estimate a Fused Gromov-Wasserstein dictionary from the dataset of attributed graphs -# --------------------------------------------- +# ------------------------------------------------------------------------------------ np.random.seed(0) ps = [ot.unif(C.shape[0]) for C in dataset] D = 3 # 6 atoms instead of 3 @@ -286,7 +286,7 @@ pl.show() ############################################################################# # # Visualization of the estimated dictionary atoms -# --------------------------------------------- +# ----------------------------------------------- pl.figure(7, (12, 8)) pl.clf() @@ -313,7 +313,7 @@ pl.show() ############################################################################# # # Visualization of the embedding space -# --------------------------------------------- +# ------------------------------------ unmixings = [] reconstruction_errors = [] diff --git a/examples/gromov/plot_semirelaxed_fgw.py b/examples/gromov/plot_semirelaxed_fgw.py index ef4b286..579f23d 100644 --- a/examples/gromov/plot_semirelaxed_fgw.py +++ b/examples/gromov/plot_semirelaxed_fgw.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- """ -========================== +=============================================== Semi-relaxed (Fused) Gromov-Wasserstein example -========================== +=============================================== This example is designed to show how to use the semi-relaxed Gromov-Wasserstein and the semi-relaxed Fused Gromov-Wasserstein divergences. @@ -34,7 +34,7 @@ from networkx.generators.community import stochastic_block_model as sbm ############################################################################# # # Generate two graphs following Stochastic Block models of 2 and 3 clusters. -# --------------------------------------------- +# -------------------------------------------------------------------------- N2 = 20 # 2 communities @@ -85,7 +85,7 @@ for i, j in G3.edges(): ############################################################################# # # Compute their semi-relaxed Gromov-Wasserstein divergences -# --------------------------------------------- +# --------------------------------------------------------- # 0) GW(C2, h2, C3, h3) for reference OT, log = gromov_wasserstein(C2, C3, h2, h3, symmetric=True, log=True) @@ -110,7 +110,7 @@ print('srGW(C3, h3, C2) = ', srgw_32) ############################################################################# # # Visualization of the semi-relaxed Gromov-Wasserstein matchings -# --------------------------------------------- +# -------------------------------------------------------------- # # We color nodes of the graph on the right - then project its node colors # based on the optimal transport plan from the srGW matching @@ -226,7 +226,7 @@ pl.show() ############################################################################# # # Add node features -# --------------------------------------------- +# ----------------- # We add node features with given mean - by clusters # and inversely proportional to clusters' intra-connectivity @@ -242,7 +242,7 @@ for i, c in enumerate(part_G3): ############################################################################# # # Compute their semi-relaxed Fused Gromov-Wasserstein divergences -# --------------------------------------------- +# --------------------------------------------------------------- alpha = 0.5 # Compute pairwise euclidean distance between node features @@ -272,7 +272,7 @@ print('srGW(C3, F3, h3, C2, F2) = ', srfgw_32) ############################################################################# # # Visualization of the semi-relaxed Fused Gromov-Wasserstein matchings -# --------------------------------------------- +# -------------------------------------------------------------------- # # We color nodes of the graph on the right - then project its node colors # based on the optimal transport plan from the srFGW matching |