# ForceAtlas¶

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

:

from IPython.display import SVG

:

from sknetwork.data import karate_club
from sknetwork.embedding.force_atlas import ForceAtlas
from sknetwork.visualization import svg_graph

:

graph = karate_club(metadata=True)
adjacency = graph.adjacency
labels = graph.labels

:

forceatlas2 = ForceAtlas()
embedding = forceatlas2.fit_transform(adjacency)
image = svg_graph(adjacency, embedding, labels=labels)
SVG(image)

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

Replace the linear attraction force with a logarithmic attraction force.

:

forceatlas2 = ForceAtlas(lin_log = True)
embedding = forceatlas2.fit_transform(adjacency)
image = svg_graph(adjacency, embedding, labels=labels)
SVG(image)

: 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.

:

forceatlas2 = ForceAtlas(gravity_factor = 0.1)
embedding = forceatlas2.fit_transform(adjacency)
image = svg_graph(adjacency, embedding, labels=labels)
SVG(image)

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

:

forceatlas2 = ForceAtlas(tolerance=1.5)
embedding = forceatlas2.fit_transform(adjacency)
image = svg_graph(adjacency, embedding, labels=labels)
SVG(image)

: :

forceatlas2 = ForceAtlas(approx_radius=2)
embedding = forceatlas2.fit_transform(adjacency)
image = svg_graph(adjacency, embedding, labels=labels)
SVG(image)

: 