ForceAtlasΒΆ

This notebook illustrates the embedding of a graph through the force-directed algorithm Force Atlas 2.

[1]:
from IPython.display import SVG
[2]:
from sknetwork.data import karate_club
from sknetwork.embedding.force_atlas import ForceAtlas
from sknetwork.visualization import svg_graph
[3]:
graph = karate_club(metadata=True)
adjacency = graph.adjacency
labels = graph.labels
[4]:
forceatlas2 = ForceAtlas()
embedding = forceatlas2.fit_transform(adjacency)
image = svg_graph(adjacency, embedding, labels=labels)
SVG(image)
[4]:
../../_images/tutorials_embedding_forceatlas_4_0.svg

Here we illustrate the influences of the different settings offered to the user.

Replace the linear attraction force with a logarithmic attraction force.

[5]:
forceatlas2 = ForceAtlas(lin_log = True)
embedding = forceatlas2.fit_transform(adjacency)
image = svg_graph(adjacency, embedding, labels=labels)
SVG(image)
[5]:
../../_images/tutorials_embedding_forceatlas_7_0.svg

Set the gravity and repulsion force constants (gravity_factor and repulsion_factor) to set the importance of each force in the layout. Keep values between 0.01 and 0.1.

[6]:
forceatlas2 = ForceAtlas(gravity_factor = 0.1)
embedding = forceatlas2.fit_transform(adjacency)
image = svg_graph(adjacency, embedding, labels=labels)
SVG(image)
[6]:
../../_images/tutorials_embedding_forceatlas_9_0.svg

Set the amount of swinging tolerated. Lower swinging yields less speed and more precision.

[7]:
forceatlas2 = ForceAtlas(tolerance=1.5)
embedding = forceatlas2.fit_transform(adjacency)
image = svg_graph(adjacency, embedding, labels=labels)
SVG(image)
[7]:
../../_images/tutorials_embedding_forceatlas_11_0.svg
[8]:
forceatlas2 = ForceAtlas(approx_radius=2)
embedding = forceatlas2.fit_transform(adjacency)
image = svg_graph(adjacency, embedding, labels=labels)
SVG(image)
[8]:
../../_images/tutorials_embedding_forceatlas_12_0.svg