Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Softwareproject WS2018-19 - Graph Embedding Propagation
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
toyota
Softwareproject WS2018-19 - Graph Embedding Propagation
Commits
56221a75
Commit
56221a75
authored
6 years ago
by
toyota
Browse files
Options
Downloads
Patches
Plain Diff
add splitting nodes for node classification
parent
b8b80e2f
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Cora_Preprocessing/get_nodes.py
+67
-0
67 additions, 0 deletions
Cora_Preprocessing/get_nodes.py
with
67 additions
and
0 deletions
Cora_Preprocessing/get_nodes.py
0 → 100644
+
67
−
0
View file @
56221a75
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
@author: Utaemon Toyota
@project: Software Projekt
@date: 25.12.2018
"""
import
random
import
cora
def
get_graph
(
path_nodes
,
path_edges
):
return
cora
.
get_graph
(
path_nodes
,
path_edges
)
def
dict_of_node_classes
(
path_nodes
,
path_edges
):
cora
=
get_graph
(
path_nodes
,
path_edges
)
class_dict
=
{}
for
node
in
cora
.
node
:
node_class
=
cora
.
node
[
node
][
"
class
"
]
if
not
node_class
in
class_dict
:
class_dict
[
node_class
]
=
set
()
class_dict
[
node_class
].
add
(
node
)
return
class_dict
def
get_random_num_nodes
(
set_elm
,
num
):
return
set
(
random
.
sample
(
set_elm
,
num
))
def
get_num_random_nodes_for_all_classes
(
num
=
3
,
path_nodes
=
"
/home/utaemon/SP/cora/cora.content
"
,
path_edges
=
"
/home/utaemon/SP/cora/cora.cites
"
):
"""
get specific number of nodes per class, same number for all classes
"""
cora_dict
=
dict_of_node_classes
(
path_nodes
,
path_edges
)
sampled_random_id_set
=
set
()
for
key
in
cora_dict
:
for
id
in
get_random_num_nodes
(
cora_dict
[
key
],
num
):
sampled_random_id_set
.
add
(
id
)
# if you want to return dict of class:random_ids
# cora_dict = dict_of_node_classes(path_nodes, path_edges)
# sampled_random_dict = {}
# for key in cora_dict:
# sampled_random_dict[key] = get_random_num_nodes(cora_dict[key], num)
# return sampled_random_dict
return
sampled_random_id_set
#get random nodes
def
get_num_of_random_nodes
(
num
=
3
,
path_nodes
=
"
/home/utaemon/SP/cora/cora.content
"
,
path_edges
=
"
/home/utaemon/SP/cora/cora.cites
"
):
"""
Get random nodes.
"""
cora_nodes
=
set
(
get_graph
(
path_nodes
,
path_edges
).
nodes
)
return
set
(
random
.
sample
(
cora_nodes
,
num
))
#get a dictionary with class: ids
def
get_dict_of_nodes
(
*
args
):
"""
*args: Tuple of Set_name and number of nodes in it, for example (
"
a
"
, 10).
"""
dict_of_sets
=
{}
for
arg
in
args
:
ids
=
get_num_of_random_nodes
(
arg
[
1
])
dict_of_sets
[
arg
[
0
]]
=
ids
return
dict_of_sets
#get features from nodes
def
get_features_for_nodes
(
path_nodes
=
"
/home/utaemon/SP/cora/cora.content
"
,
path_edges
=
"
/home/utaemon/SP/cora/cora.cites
"
):
cora_graph
=
get_graph
(
path_nodes
,
path_edges
)
set_of_cora_nodes
=
get_num_of_random_nodes
()
dict_of_id_and_features
=
{}
for
id
in
set_of_cora_nodes
:
dict_of_id_and_features
[
id
]
=
cora_graph
.
node
[
id
]
return
dict_of_id_and_features
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment