Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
linkprediction_depo
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
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
Jacques Fize
linkprediction_depo
Commits
1bf80ff7
Commit
1bf80ff7
authored
4 years ago
by
Fize Jacques
Browse files
Options
Downloads
Patches
Plain Diff
add theoric graph generation script
parent
d4e8ff00
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
evalNE_script.py
+27
-26
27 additions, 26 deletions
evalNE_script.py
generate_theoric_random_graph.py
+115
-0
115 additions, 0 deletions
generate_theoric_random_graph.py
with
142 additions
and
26 deletions
evalNE_script.py
+
27
−
26
View file @
1bf80ff7
...
...
@@ -10,6 +10,7 @@ import argparse
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
"
edgelist_graph_filename
"
)
parser
.
add_argument
(
"
--ne
"
,
"
--network-embedding
"
,
action
=
"
store_true
"
,
help
=
"
If you want to use neural network embedding for link prediction
"
)
parser
.
add_argument
(
"
-v
"
,
"
--verbose
"
,
action
=
"
store_true
"
)
args
=
parser
.
parse_args
()
#("data/fb_country_country_sample_6_size1000.txt".split())
...
...
@@ -43,34 +44,34 @@ for method in methods:
result
=
nee
.
evaluate_baseline
(
method
=
method
,
)
scoresheet
.
log_results
(
result
)
try
:
# Check if OpenNE is installed
import
openne
a
=
0
/
0
# Set embedding methods from OpenNE
methods
=
"
node2vec hope-opne gf sdne deepWalk line grarep
"
.
split
()
#lap-opne
commands
=
[
"
python -m openne --method node2vec --graph-format edgelist --epochs 100 --number-walks 10 --walk-length 80 --window-size 10
"
,
#
"python -m openne --method
lap
--epochs 100",
"
python -m openne --method
hope
--epochs 100
"
,
"
python -m openne --method
gf
--epochs 100
"
,
"
python -m openne --method
sdne --epochs 100 --encoder-list [1024,128] --beta 5 --bs 50
0
"
,
"
python -m openne --method
deepWalk
--graph-format edgelist --epochs
100 --number-walks 10 --walk-length 80 --window-size
10
"
,
"
python -m openne --method
line --graph-format edgelist
--epochs 10
"
,
"
python -m openne --method
grare
p --epochs 100
"
]
edge_emb
=
[
'
average
'
,
'
hadamard
'
]
if
args
.
network_embedding
:
try
:
# Check if OpenNE is installed
import
openne
# Set embedding methods from OpenNE
methods
=
"
node2vec hope-opne gf sdne deepWalk line grarep
"
.
split
()
#lap-opne
commands
=
[
"
python -m openne --method node2vec --graph-format edgelist --epochs 100 --number-walks 10 --walk-length 80 --window-size 10
"
,
"
python -m openne --method
hope
--epochs 100
"
,
"
python -m openne --method
gf
--epochs 100
"
,
"
python -m openne --method
sdne
--epochs 100
--encoder-list [1024,128] --beta 5 --bs 500
"
,
"
python -m openne --method
deepWalk --graph-format edgelist --epochs 100 --number-walks 10 --walk-length 80 --window-size 1
0
"
,
"
python -m openne --method
line
--graph-format edgelist --epochs 10
"
,
"
python -m openne --method
grarep
--epochs 10
0
"
#
"python -m openne --method
la
p --epochs 100"
,
]
edge_emb
=
[
'
average
'
,
'
hadamard
'
]
# Evaluate embedding methods
for
i
in
range
(
len
(
methods
)):
command
=
commands
[
i
]
+
"
--input {} --output {} --representation-size {}
"
results
=
nee
.
evaluate_cmd
(
method_name
=
methods
[
i
],
method_type
=
'
ne
'
,
command
=
command
,
edge_embedding_methods
=
edge_emb
,
input_delim
=
'
'
,
output_delim
=
'
'
,
verbose
=
args
.
verbose
)
scoresheet
.
log_results
(
results
)
# Evaluate embedding methods
for
i
in
range
(
len
(
methods
)):
command
=
commands
[
i
]
+
"
--input {} --output {} --representation-size {}
"
results
=
nee
.
evaluate_cmd
(
method_name
=
methods
[
i
],
method_type
=
'
ne
'
,
command
=
command
,
edge_embedding_methods
=
edge_emb
,
input_delim
=
'
'
,
output_delim
=
'
'
,
verbose
=
args
.
verbose
)
scoresheet
.
log_results
(
results
)
except
Exception
:
print
(
"
The OpenNE library is not installed. Reporting results only for the baselines...
"
)
pass
except
ImportError
:
print
(
"
The OpenNE library is not installed. Reporting results only for the baselines...
"
)
pass
# Get output
if
args
.
verbose
:
...
...
This diff is collapsed.
Click to expand it.
generate_theoric_random_graph.py
0 → 100644
+
115
−
0
View file @
1bf80ff7
# coding = utf-8
import
networkx
as
nx
import
argparse
import
numpy
as
np
import
pandas
as
pd
import
random
import
copy
from
tqdm
import
tqdm
def
generate_sbm_prob_matrix
(
nb_of_blocks
,
prob_btw_block
=
0.1
):
M
=
np
.
zeros
((
nb_of_blocks
,
nb_of_blocks
))
np
.
fill_diagonal
(
M
,[
random
.
random
()
for
i
in
range
(
nb_of_blocks
)])
for
i
in
range
(
nb_of_blocks
):
for
j
in
range
(
nb_of_blocks
):
if
i
==
j
:
continue
M
[
i
,
j
]
=
prob_btw_block
M
[
j
,
i
]
=
prob_btw_block
return
M
GRAPH_SIZE
=
[
50
,
100
,
200
,
500
]
OUTPUT_DIR
=
"
test_dataset/
"
parameters
=
{
"
planted_partition_graph
"
:
{
"
l
"
:
[
3
,
5
,
8
],
"
k
"
:
[
10
,
20
,
30
],
"
p_in
"
:
[
0.2
,
0.5
,
0.7
],
"
p_out
"
:
[
0.1
,
0.2
,
0.3
]
},
"
stochastic_block_model
"
:
{
"
sizes
"
:
[[
random
.
choice
([
10
,
20
,
30
])
for
k
in
range
(
i
)]
for
i
in
[
3
,
5
,
8
,
10
,
12
]],
"
p
"
:
[]
# Filled later
},
"
fast_gnp_random_graph
"
:
{
"
n
"
:
GRAPH_SIZE
,
"
p
"
:
[
0.1
,
0.4
,
0.6
,
0.8
]
},
"
random_powerlaw_tree_sequence
"
:
{
# configuration_model
"
n
"
:
GRAPH_SIZE
,
"
tries
"
:[
10000
]
},
"
random_geometric_graph
"
:
{
"
n
"
:
GRAPH_SIZE
,
"
radius
"
:
[
0.1
,
0.2
,
0.4
,
0.8
]
},
"
waxman_graph
"
:
{
"
n
"
:
GRAPH_SIZE
,
"
beta
"
:
[
0.1
,
0.4
,
0.8
],
"
alpha
"
:
[
0.1
,
0.4
,
0.8
]
},
"
geographical_threshold_graph
"
:
{
"
n
"
:
GRAPH_SIZE
,
"
theta
"
:
[
0.1
,
0.2
,
0.4
,
0.6
]
},
}
# Generating transition matrices for stochastic block model
parameters
[
"
stochastic_block_model
"
][
"
p
"
]
=
[
generate_sbm_prob_matrix
(
len
(
l
))
for
l
in
parameters
[
"
stochastic_block_model
"
][
"
sizes
"
]]
#getattr(nx,"geographical_threshold_graph")(**dict(n=20,theta=0.4))
def
get_params
(
dict_params
):
nb_of_parameter
=
np
.
prod
([
len
(
a
)
for
_
,
a
in
dict_params
.
items
()])
parameters_dicts
=
[{}
for
i
in
range
(
nb_of_parameter
)]
for
par
,
values
in
dict_params
.
items
():
division
=
nb_of_parameter
/
len
(
values
)
for
ix
in
range
(
nb_of_parameter
):
parameters_dicts
[
ix
][
par
]
=
values
[
int
(
ix
//
division
)]
return
parameters_dicts
pbar
=
tqdm
(
parameters
.
items
(),
total
=
len
(
parameters
))
for
method
,
args
in
pbar
:
pbar
.
set_description
(
"
Generating graphs using :
"
+
method
)
list_of_params
=
get_params
(
parameters
[
method
])
func
=
getattr
(
nx
,
method
)
for
ix
,
params
in
enumerate
(
list_of_params
):
# try:
if
method
==
"
random_powerlaw_tree_sequence
"
:
sequence
=
func
(
**
params
)
G
=
nx
.
configuration_model
(
sequence
)
else
:
G
=
func
(
**
params
)
G
.
graph
.
update
(
params
)
nx
.
write_gml
(
G
,
OUTPUT_DIR
+
"
/graph_{method}_{ix}.gml
"
.
format
(
method
=
method
,
ix
=
ix
),
stringizer
=
str
)
# except Exception as e:
# print(e)
"""
nx.planted_partition_graph(5, 5, 0.8,
0.1) # nb of blocks, nb of vertices in each block, probability of link in block , prob. of link between blocks
nx.stochastic_block_model([5, 3, 6],
[[1, 0.1, 0.1], [0.1, 1, 0.1], [0.1, 0.1, 1]]) # sizes of blocks,probability between blocks
## Random Graph
nx.fast_gnp_random_graph(10, 0.5) # nb of nodes, prob of link
sequence = nx.random_powerlaw_tree_sequence(50, tries=500) # degree sequence
G = nx.configuration_model(sequence) # sequence
## Spatial graph
nx.random_geometric_graph(20, 0.5) # size of graph, max radius between edge connected
dist = lambda x, y: sum(abs(a - b) for a, b in zip(x, y)) # euclidian distance
G = nx.waxman_graph(50, 0.5, 0.1, metric=dist) # nb of nodes, beta, alpha
# beta -> the higher the parameter the higher the density is
# alpha -> the lower the higher the number of short edge is
G = nx.geographical_threshold_graph(20, 1, metric=dist) # nb of node, theta
# theta --> distance thresold
"""
\ No newline at end of file
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