Commit 53933d87 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Fix test_inference.py

parent 62a57e77
Pipeline #128 failed with stage
This diff is collapsed.
#!/bin/env python #!/bin/env python
verbose=False
import os
import sys
if not verbose:
f = open(os.devnull, 'w')
sys.stdout = f
from graph_tool.all import * from graph_tool.all import *
import numpy.random import numpy.random
from numpy.random import randint from numpy.random import randint
...@@ -36,10 +44,11 @@ for directed in [True, False]: ...@@ -36,10 +44,11 @@ for directed in [True, False]:
for dl in [False, True]: for dl in [False, True]:
print("\ndirected:", directed, "overlap:", overlap, print("\ndirected:", directed, "overlap:", overlap,
"layered:", layered, "deg-corr:", deg_corr, "dl:", dl) "layered:", layered, "deg-corr:", deg_corr, "dl:", dl,
file=sys.stdout)
print("\t mcmc (unweighted)") print("\t mcmc (unweighted)", file=sys.stdout)
state = gen_state(directed, deg_corr, layered, overlap) state = gen_state(directed, deg_corr, layered, overlap)
print("\t\t", state.mcmc_sweep(beta=0, allow_empty=True, print("\t\t", state.mcmc_sweep(beta=0, allow_empty=True,
...@@ -49,12 +58,13 @@ for directed in [True, False]: ...@@ -49,12 +58,13 @@ for directed in [True, False]:
print("\t\t", state.mcmc_sweep(beta=0, bundled=True, print("\t\t", state.mcmc_sweep(beta=0, bundled=True,
allow_empty=True, allow_empty=True,
entropy_args=dict(dl=dl)), entropy_args=dict(dl=dl)),
(state.wr.a > 0).sum()) (state.wr.a > 0).sum(),
file=sys.stdout)
state = gen_state(directed, deg_corr, layered, overlap) state = gen_state(directed, deg_corr, layered, overlap)
if not overlap: if not overlap:
print("\t mcmc") print("\t mcmc", file=sys.stdout)
bstate = state.get_block_state(vweight=True, bstate = state.get_block_state(vweight=True,
deg_corr=deg_corr) deg_corr=deg_corr)
...@@ -63,7 +73,7 @@ for directed in [True, False]: ...@@ -63,7 +73,7 @@ for directed in [True, False]:
allow_empty=True, allow_empty=True,
entropy_args=dict(dl=dl, entropy_args=dict(dl=dl,
multigraph=False)), multigraph=False)),
(bstate.wr.a > 0).sum()) (bstate.wr.a > 0).sum(), file=sys.stdout)
print("\t\t", print("\t\t",
bstate.mcmc_sweep(beta=0, allow_empty=True, bstate.mcmc_sweep(beta=0, allow_empty=True,
...@@ -75,9 +85,9 @@ for directed in [True, False]: ...@@ -75,9 +85,9 @@ for directed in [True, False]:
bstate.gibbs_sweep(beta=0, allow_empty=True, bstate.gibbs_sweep(beta=0, allow_empty=True,
entropy_args=dict(dl=dl, entropy_args=dict(dl=dl,
multigraph=False)), multigraph=False)),
(bstate.wr.a > 0).sum()) (bstate.wr.a > 0).sum(), file=sys.stdout)
print("\t merge") print("\t merge", file=sys.stdout)
state = gen_state(directed, deg_corr, layered, overlap) state = gen_state(directed, deg_corr, layered, overlap)
...@@ -88,30 +98,34 @@ for directed in [True, False]: ...@@ -88,30 +98,34 @@ for directed in [True, False]:
print("\t\t", print("\t\t",
bstate.merge_sweep(50, bstate.merge_sweep(50,
entropy_args=dict(dl=dl, entropy_args=dict(dl=dl,
multigraph=False))) multigraph=False)),
file=sys.stdout)
bstate = bstate.copy() bstate = bstate.copy()
print("\t\t", print("\t\t",
bstate.mcmc_sweep(beta=0, allow_empty=True, bstate.mcmc_sweep(beta=0, allow_empty=True,
entropy_args=dict(dl=dl, entropy_args=dict(dl=dl,
multigraph=False))) multigraph=False)),
file=sys.stdout)
print("\t\t", print("\t\t",
bstate.gibbs_sweep(beta=0, allow_empty=True, bstate.gibbs_sweep(beta=0, allow_empty=True,
entropy_args=dict(dl=dl, entropy_args=dict(dl=dl,
multigraph=False))) multigraph=False)),
file=sys.stdout)
else: else:
print("\t\t", print("\t\t",
state.merge_sweep(50, state.merge_sweep(50,
entropy_args=dict(dl=dl, entropy_args=dict(dl=dl,
multigraph=False))) multigraph=False)),
file=sys.stdout)
print("\t shrink") print("\t shrink", file=sys.stdout)
state = gen_state(directed, deg_corr, layered, overlap) state = gen_state(directed, deg_corr, layered, overlap)
state = state.shrink(B=5, entropy_args=dict(dl=dl, state = state.shrink(B=5, entropy_args=dict(dl=dl,
multigraph=False)) multigraph=False))
print("\t\t", state.B) print("\t\t", state.B, file=sys.stdout)
for directed in [True, False]: for directed in [True, False]:
for overlap in [False, True]: for overlap in [False, True]:
...@@ -121,21 +135,23 @@ for directed in [True, False]: ...@@ -121,21 +135,23 @@ for directed in [True, False]:
"layered:", layered, "deg-corr:", deg_corr) "layered:", layered, "deg-corr:", deg_corr)
state = minimize_blockmodel_dl(GraphView(g, directed=directed), state = minimize_blockmodel_dl(GraphView(g, directed=directed),
verbose=(1, "\t"), verbose=(1, "\t") if verbose else False,
deg_corr=deg_corr, deg_corr=deg_corr,
overlap=overlap, overlap=overlap,
layers=layered != False, layers=layered != False,
state_args=dict(ec=ec, state_args=dict(ec=ec,
layers=(layered == True))) layers=(layered == True)))
print(state.B, state.entropy()) print(state.B, state.entropy(), file=sys.stdout)
state = minimize_nested_blockmodel_dl(GraphView(g, directed=directed), state = minimize_nested_blockmodel_dl(GraphView(g, directed=directed),
verbose=(1, "\t"), verbose=(1, "\t") if verbose else False,
deg_corr=deg_corr, deg_corr=deg_corr,
overlap=overlap, overlap=overlap,
layers=layered != False, layers=layered != False,
state_args=dict(ec=ec, state_args=dict(ec=ec,
layers=(layered == True))) layers=(layered == True)))
state.print_summary() if verbose:
print(state.entropy()) state.print_summary()
print(state.entropy(), file=sys.stdout)
print("OK")
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment