#!git clone https://github.com/guebin/graft
[Essays] graft
신록예찬
2023-11-09
Imports
소스코드 다운로드: https://github.com/guebin/graft
- 계속 업데이트할 예정
#!conda install -c conda-forge graph-tool -y
import numpy as np
import torch
import torch_geometric
import warnings
"ignore") warnings.filterwarnings(
import graft
= torch.tensor([[0, 1, 2, 3, 4, 3],
links 1, 0, 3, 2, 3, 4]], dtype=torch.long)
[= torch_geometric.data.Data(
g = links
edge_index )
graft.graph.plot_undirected_unweighted(g)
# Ex
– node_names
graft.graph.plot_undirected_unweighted(
g, = ['a','b','c','d','e'],
node_names )
# Ex
– node_color (continuous)
= torch.tensor([[0, 1, 2, 3, 4, 3],
links 1, 0, 3, 2, 3, 4]], dtype=torch.long)
[= torch_geometric.data.Data(
g = links,
edge_index = np.random.randn(5)
y )
graft.graph.plot_undirected_unweighted(
g,=g.y
node_color )
# Ex
– node_color (discrete)
= torch.tensor([[0, 1, 2, 3, 4, 3],
links 1, 0, 3, 2, 3, 4]], dtype=torch.long)
[= torch_geometric.data.Data(
g = links,
edge_index = torch.tensor([0,1,0,0,1])
y )
graft.graph.plot_undirected_unweighted(
g,=g.y
node_color )
# Ex
– node_color (discrete) / node_size
= torch.tensor([[0, 1, 2, 3, 4, 3],
links 1, 0, 3, 2, 3, 4]], dtype=torch.long)
[= torch_geometric.data.Data(
g = links,
edge_index = torch.tensor([0,1,0,0,1]),
y = torch.tensor([10,100,15,20,150])
x )
graft.graph.plot_undirected_unweighted(
g,=g.y,
node_color=g.x
node_size )
# Ex
– draw options
= torch.tensor([[0, 1, 2, 3, 4, 3],
links 1, 0, 3, 2, 3, 4]], dtype=torch.long)
[= torch_geometric.data.Data(
g = links
edge_index )
graft.graph.plot_undirected_unweighted(
g, )
= {
dr_opts 'vertex_size':30
}
graft.graph.plot_undirected_unweighted(
g,= dr_opts
draw_options )
= {
dr_opts 'edge_marker_size': 200,
'output_size': (300,300)
}
graft.graph.plot_undirected_unweighted(
g,= dr_opts
draw_options )
Undirected / Weighted
# Ex
= torch.tensor([[0, 1, 2, 3, 4, 3],
links 1, 0, 3, 2, 3, 4]], dtype=torch.long)
[= torch.tensor([5, 5, 1.5, 1.5, 0.19, 0.19], dtype=torch.float)
weights
= torch_geometric.data.Data(
g =links,
edge_index=weights,
edge_attr )
graft.graph.plot_undirected_weighted(
g, )
# Ex
= torch.tensor([[0, 1, 2, 3, 4, 3],
links 1, 0, 3, 2, 3, 4]], dtype=torch.long)
[= torch.tensor([5, 5, 1.5, 1.5, 0.19, 0.19], dtype=torch.float)
weights
= torch_geometric.data.Data(
g =links,
edge_index=weights,
edge_attr )
graft.graph.plot_undirected_weighted(
g,=False
edge_weight_text )
graft.graph.plot_undirected_weighted(
g,=False,
edge_weight_text=False
edge_weight_width )
graft.graph.plot_undirected_weighted(
g,=True,
edge_weight_text=True,
edge_weight_width='.1f',
edge_weight_text_format )
graft.graph.plot_undirected_weighted(
g,=True,
edge_weight_text=True,
edge_weight_width='.1f',
edge_weight_text_format=5.0,
edge_weight_width_scale )
# Ex
= torch.tensor([[0, 1, 2, 3, 4, 3],
links 1, 0, 3, 2, 3, 4]], dtype=torch.long)
[= torch.tensor([5, 5, 1.5, 1.5, 0.19, 0.19], dtype=torch.float)
weights
= torch_geometric.data.Data(
g =links,
edge_index=weights,
edge_attr= torch.tensor([1,1,0,0,0])
y )
graft.graph.plot_undirected_weighted(
g,=g.y
node_color )
# Ex
= torch.tensor([[0, 1, 2, 3, 4, 3],
links 1, 0, 3, 2, 3, 4]], dtype=torch.long)
[= torch.tensor([5, 5, 1.5, 1.5, 0.19, 0.19], dtype=torch.float)
weights = torch_geometric.data.Data(
g = links,
edge_index = weights,
edge_attr = torch.tensor([0,1,0,0,1]),
y = torch.tensor([1,3,1,2,4])
x )
graft.graph.plot_undirected_weighted(
g,=g.y,
node_color=g.x,
node_size=False,
edge_weight_text )