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 visualize_graph
Example
[3]:
graph = karate_club(metadata=True)
adjacency = graph.adjacency
labels = graph.labels
[4]:
forceatlas2 = ForceAtlas()
embedding = forceatlas2.fit_transform(adjacency)
image = visualize_graph(adjacency, embedding, labels=labels)
SVG(image)
[4]:
Options
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 = visualize_graph(adjacency, embedding, labels=labels)
SVG(image)
[5]:
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 = visualize_graph(adjacency, embedding, labels=labels)
SVG(image)
[6]:
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 = visualize_graph(adjacency, embedding, labels=labels)
SVG(image)
[7]:
[8]:
forceatlas2 = ForceAtlas(approx_radius=2)
embedding = forceatlas2.fit_transform(adjacency)
image = visualize_graph(adjacency, embedding, labels=labels)
SVG(image)
[8]: