r"""
Edge lifetime decides which links survive
=========================================

All topology learners delete links that have not been refreshed for a given
number of steps. A long lifetime keeps transient links created while the
nodes were still moving and links that jump between neighboring windings of
the swiss roll; a short lifetime keeps only the links supported by the data.
The suggestion of the WINN paper, a maximal age of N/10, is far too large
for a curved manifold.
"""

import matplotlib.pyplot as plt

from graphclust import WeightedIncrementalNetwork
from graphclust.datasets import make_swiss_roll, minmax_scale
from graphclust.plotting import plot_graph

X = minmax_scale(make_swiss_roll(2000, random_state=0)[0])
fig = plt.figure(figsize=(9, 4))
for i, age in enumerate([len(X) / 10, 3]):
    # [snippet:age]
    winn = WeightedIncrementalNetwork(n_nodes=200, max_age=age, random_state=0).fit(X)
    # [/snippet:age]
    ax = fig.add_subplot(1, 2, i + 1, projection="3d")
    plot_graph(winn.nodes_, winn.adjacency_, ax=ax, node_size=5, lw=0.5)
    ax.set_title(f"WINN, maximal edge age {age:g}: {winn.n_edges_} edges", fontsize=10)
    ax.view_init(10, -70)
    ax.set_xticks([])
    ax.set_yticks([])
    ax.set_zticks([])
plt.tight_layout()
