ForceAtlas
此笔记本演示了通过力导向算法 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
示例
[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]:
选项
这里我们说明了提供给用户的不同设置的影响。
将线性吸引力替换为对数吸引力。
[5]:
forceatlas2 = ForceAtlas(lin_log = True)
embedding = forceatlas2.fit_transform(adjacency)
image = visualize_graph(adjacency, embedding, labels=labels)
SVG(image)
[5]:
设置重力和排斥力常数(gravity_factor
和 repulsion_factor
)以设置布局中每个力的重要性。保持值在 0.01 到 0.1 之间。
[6]:
forceatlas2 = ForceAtlas(gravity_factor = 0.1)
embedding = forceatlas2.fit_transform(adjacency)
image = visualize_graph(adjacency, embedding, labels=labels)
SVG(image)
[6]:
设置允许的摆动量。较低的摆动幅度导致速度降低,精度提高。
[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]: