[Essays] graft
신록예찬
2023-11-09
Imports
소스코드 다운로드: https://github.com/guebin/graft
! git clone https:// github.com/ guebin/ graft
fatal: destination path 'graft' already exists and is not an empty directory.
! conda install - c conda- forge graph- tool - y
Collecting package metadata (current_repodata.json): done
Solving environment: done
==> WARNING: A newer version of conda exists. <==
current version: 22.9.0
latest version: 23.10.0
Please update conda by running
$ conda update -n base -c defaults conda
# All requested packages already installed.
Retrieving notices: ...working... done
import numpy as np
import torch
import torch_geometric
import warnings
warnings.filterwarnings("ignore" )
ImportError: /home/coco/anaconda3/envs/gt/lib/python3.11/site-packages/torch/lib/libgomp-a34b3233.so.1: version `GOMP_5.0' not found (required by /home/coco/anaconda3/envs/gt/lib/python3.11/site-packages/graph_tool/libgraph_tool_core.so)
links = torch.tensor([[0 , 1 , 2 , 3 , 4 , 3 ],
[1 , 0 , 3 , 2 , 3 , 4 ]], dtype= torch.long )
g = torch_geometric.data.Data(
edge_index = links
)
graft.graph.plot_undirected_unweighted(g)
NameError: name 'graft' is not defined
# Ex
– node_names
graft.graph.plot_undirected_unweighted(
g,
node_names = ['a' ,'b' ,'c' ,'d' ,'e' ],
)
# Ex
– node_color (continuous)
links = torch.tensor([[0 , 1 , 2 , 3 , 4 , 3 ],
[1 , 0 , 3 , 2 , 3 , 4 ]], dtype= torch.long )
g = torch_geometric.data.Data(
edge_index = links,
y = np.random.randn(5 )
)
graft.graph.plot_undirected_unweighted(
g,
node_color= g.y
)
# Ex
– node_color (discrete)
links = torch.tensor([[0 , 1 , 2 , 3 , 4 , 3 ],
[1 , 0 , 3 , 2 , 3 , 4 ]], dtype= torch.long )
g = torch_geometric.data.Data(
edge_index = links,
y = torch.tensor([0 ,1 ,0 ,0 ,1 ])
)
graft.graph.plot_undirected_unweighted(
g,
node_color= g.y
)
# Ex
– node_color (discrete) / node_size
links = torch.tensor([[0 , 1 , 2 , 3 , 4 , 3 ],
[1 , 0 , 3 , 2 , 3 , 4 ]], dtype= torch.long )
g = torch_geometric.data.Data(
edge_index = links,
y = torch.tensor([0 ,1 ,0 ,0 ,1 ]),
x = torch.tensor([10 ,100 ,15 ,20 ,150 ])
)
graft.graph.plot_undirected_unweighted(
g,
node_color= g.y,
node_size= g.x
)
# Ex
– draw options
links = torch.tensor([[0 , 1 , 2 , 3 , 4 , 3 ],
[1 , 0 , 3 , 2 , 3 , 4 ]], dtype= torch.long )
g = torch_geometric.data.Data(
edge_index = links
)
graft.graph.plot_undirected_unweighted(
g,
)
dr_opts = {
'vertex_size' :30
}
graft.graph.plot_undirected_unweighted(
g,
draw_options= dr_opts
)
dr_opts = {
'edge_marker_size' : 200 ,
'output_size' : (300 ,300 )
}
graft.graph.plot_undirected_unweighted(
g,
draw_options= dr_opts
)
Undirected / Weighted
# Ex
links = torch.tensor([[0 , 1 , 2 , 3 , 4 , 3 ],
[1 , 0 , 3 , 2 , 3 , 4 ]], dtype= torch.long )
weights = torch.tensor([5 , 5 , 1.5 , 1.5 , 0.19 , 0.19 ], dtype= torch.float )
g = torch_geometric.data.Data(
edge_index= links,
edge_attr= weights,
)
graft.graph.plot_undirected_weighted(
g,
)
# Ex
links = torch.tensor([[0 , 1 , 2 , 3 , 4 , 3 ],
[1 , 0 , 3 , 2 , 3 , 4 ]], dtype= torch.long )
weights = torch.tensor([5 , 5 , 1.5 , 1.5 , 0.19 , 0.19 ], dtype= torch.float )
g = torch_geometric.data.Data(
edge_index= links,
edge_attr= weights,
)
graft.graph.plot_undirected_weighted(
g,
edge_weight_text= False
)
graft.graph.plot_undirected_weighted(
g,
edge_weight_text= False ,
edge_weight_width= False
)
graft.graph.plot_undirected_weighted(
g,
edge_weight_text= True ,
edge_weight_width= True ,
edge_weight_text_format= '.1f' ,
)
graft.graph.plot_undirected_weighted(
g,
edge_weight_text= True ,
edge_weight_width= True ,
edge_weight_text_format= '.1f' ,
edge_weight_width_scale= 5.0 ,
)
# Ex
links = torch.tensor([[0 , 1 , 2 , 3 , 4 , 3 ],
[1 , 0 , 3 , 2 , 3 , 4 ]], dtype= torch.long )
weights = torch.tensor([5 , 5 , 1.5 , 1.5 , 0.19 , 0.19 ], dtype= torch.float )
g = torch_geometric.data.Data(
edge_index= links,
edge_attr= weights,
y = torch.tensor([1 ,1 ,0 ,0 ,0 ])
)
graft.graph.plot_undirected_weighted(
g,
node_color= g.y
)
# Ex
links = torch.tensor([[0 , 1 , 2 , 3 , 4 , 3 ],
[1 , 0 , 3 , 2 , 3 , 4 ]], dtype= torch.long )
weights = torch.tensor([5 , 5 , 1.5 , 1.5 , 0.19 , 0.19 ], dtype= torch.float )
g = torch_geometric.data.Data(
edge_index = links,
edge_attr = weights,
y = torch.tensor([0 ,1 ,0 ,0 ,1 ]),
x = torch.tensor([1 ,3 ,1 ,2 ,4 ])
)
graft.graph.plot_undirected_weighted(
g,
node_color= g.y,
node_size= g.x,
edge_weight_text= False ,
)