ForceAtlas2

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 ForceAtlas2
from sknetwork.visualization import svg_graph

Graphs

[3]:
graph = karate_club(metadata=True)
adjacency = graph.adjacency
labels = graph.labels

Embedding

[4]:
forceatlas2 = ForceAtlas2()
embedding = forceatlas2.fit_transform(adjacency)
image = svg_graph(adjacency, embedding, labels=labels)
SVG(image)
[4]:
../../_images/tutorials_embedding_forceatlas2_6_0.svg

Settings

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

LinLog

Replace the linear attraction force with a logarithmic attraction force.

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

Scalling : repulsive and gravity force

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 = ForceAtlas2(gravity_factor = 0.1)
embedding = forceatlas2.fit_transform(adjacency)
image = svg_graph(adjacency, embedding, labels=labels)
SVG(image)
[6]:
../../_images/tutorials_embedding_forceatlas2_11_0.svg

Tolerance

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

[7]:
forceatlas2 = ForceAtlas2(tolerance=1.5)
embedding = forceatlas2.fit_transform(adjacency)
image = svg_graph(adjacency, embedding, labels=labels)
SVG(image)
[7]:
../../_images/tutorials_embedding_forceatlas2_13_0.svg

KDTree Approximation

[8]:
forceatlas2 = ForceAtlas2(approx_radius=2)
embedding = forceatlas2.fit_transform(adjacency)
image = svg_graph(adjacency, embedding, labels=labels)
SVG(image)
[8]:
../../_images/tutorials_embedding_forceatlas2_15_0.svg