Hello,
I am trying to spread an infection over a random graph where the beta is an
edge property. I want to implement something that could simulate the
lockdown, this is what I wrote:
import matplotlib.pyplot as plt
from graph_tool.all import *
import numpy as np
import random
# graph parameters
N = 6000 # number of vertices
max_count = 100 # time_stamp
beta = 0.01
time_cut = 10
def deg_sample(k):
return np.random.poisson(k)
def evolution(G, beta, counts, perc):
eprop = G.new_edge_property("double")
eprop.a = beta
state = SIState(G, beta=eprop, constant_beta=False)
infected = [state.get_state().fa.sum()]
time = range(counts)
for i in time:
state.iterate_sync()
infected.append(state.get_state().fa.sum())
if (i == time_cut) & (perc != 0):
n = np.array(random.sample(range(len(list(G.edges()))),
int(G.num_edges() * perc/100)))
eprop.a[n] = 0
else:
pass
return infected
G = random_graph(N, lambda: deg_sample(5), directed=False)
G = extract_largest_component(G)
graph_draw(G, output='network_layout.pdf')
x = evolution(G, beta, max_count, 100)
plt.plot(x)
plt.xlabel(r"Time")
plt.ylabel(r"Infectious nodes")
plt.title('infected vs time with all edges cutted at time=%d' % time_cut)
plt.tight_layout()
plt.show()
In evolution I change the beta of all the edges of the graph at a given
timestamp, and I would expect that the infection will stop to spread after I
change the edge property map. But it doesn't happen and the infenction
continue to spread in the network.
I want to understand better what's happening in the SIState fuction.
Regards,
BH.
--
Sent from: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/
Hi, everyone!
I met a problem when I'm learning how to use graph-tool. I read the paper,
network reconstruction and community detection from dynamics, and I am
trying to achieve the same result. When I followed the same settings for
real networks with synthetic dynamics, their similarities were just about
0.2. I have a question about how to control the number of infection events
per node,a, for the first model and the number of micro-state, M, for the
second model. The whole process is shown as following.
import graph_tool.all as gt
from matplotlib import cm
g = gt.collection.konect_data["openflights"] ## airport network with SIS
dynamics
gt.remove_parallel_edges(g)
g = gt.extract_largest_component(g, prune=False)
#simulation of an empirical dynamic model
# The algorithm accepts multiple independent time-series for the
# reconstruction. We will generate 100 SIS cascades starting from a
# random node each time, and uniform infection probability beta=0.2.
ss = []
for i in range(100):
si_state = gt.SISState(g, beta=.2)
s = [si_state.get_state().copy()]
for j in range(10):
si_state.iterate_sync()
s.append(si_state.get_state().copy())
# Each time series should be represented as a single vector-valued
# vertex property map with the states for each note at each time.
s = gt.group_vector_property(s)
ss.append(s)
# Prepare the initial state of the reconstruction as an empty graph
u = g.copy()
u.clear_edges()
ss = [u.own_property(s) for s in ss] # time series properties need to be
'owned' by graph u
# Create reconstruction state
rstate = gt.EpidemicsBlockState(u, s=ss, beta = None, r=1e-6,
global_beta=.2,
state_args=dict(B=20), nested=False,
aE=g.num_edges())
# Now we collect the marginals for exactly 10,000 sweeps, at
# intervals of 10 sweeps:
gm = None
bm = None
betas = []
def collect_marginals(s):
global gm, bm
gm = s.collect_marginal(gm)
b = gt.perfect_prop_hash([s.bstate.b])[0]
bm = s.bstate.collect_vertex_marginals(bm, b=b)
betas.append(s.params["global_beta"])
gt.mcmc_equilibrate(rstate, force_niter=1000, mcmc_args=dict(niter=10,
xstep=0),
callback=collect_marginals)
print("Posterior similarity: ", gt.similarity(g, gm, g.new_ep("double", 1),
gm.ep.eprob))
print("Inferred infection probability: %g ± %g" % (mean(betas), std(betas)))
##########################################################
g = gt.GraphView(gt.collection.konect_data["maayan-foodweb"],
directed=True)##a food web network with Ising dynamic
gt.remove_parallel_edges(g)
# The algorithm accepts multiple independent time-series for the
# reconstruction. We will generate 1000 Ising cascades starting from a
# random node each time, and the uniform inverse temperature beta=0.2.
ss = []
for i in range(1000):
si_state = gt.IsingGlauberState(g, beta=.1)
s = [si_state.get_state().copy()]
si_state.iterate_async(niter=1000)
s.append(si_state.get_state().copy())
# Each time series should be represented as a single vector-valued
# vertex property map with the states for each note at each time.
s = gt.group_vector_property(s)
ss.append(s)
u = g.copy()
u.clear_edges()
ss = [u.own_property(s) for s in ss]
rstate = gt.PseudoIsingBlockState(g,s=ss,beta=0.1,state_args=dict(B=1),
nested=False, aE=g.num_edges())
gm = None
bm = None
betas = []
def collect_marginals(s):
global gm, bm
gm = s.collect_marginal(gm)
b = gt.perfect_prop_hash([s.bstate.b])[0]
bm = s.bstate.collect_vertex_marginals(bm, b=b)
betas.append(s.params["beta"])
gt.mcmc_equilibrate(rstate, force_niter=1000, mcmc_args=dict(niter=10,
xstep=0),
callback=collect_marginals)
print("Posterior similarity: ", gt.similarity(g, gm, g.new_ep("double", 1),
gm.ep.eprob))
print("Inversed temperature: %g ± %g" % (mean(betas), std(betas)))
Moreover, I also wonder how to do a nested version for the same network.
Please let me know if you need more information on the question. otherwise,
I hope to hear how this can be achieved using graph-tool?
Thanks,
Gege Hou
--
Sent from: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/
Hello,
The function graph_tool.draw.interactive_window is great for exploring a
graph interactively. Often I just need some part of a graph, for which I
can easily define a filter (or view). My question is: Is it possible to
switch between the full graph and a filtered subset of the graph
interactively? I tried something like the code below but it didn't work:
def my_key_press_callback(self, g, keyval, picked, pos, vprops, eprops):
if (chr(keyval)=='1'):
self.g = g1
self.queue_draw()
if (chr(keyval)=='2'):
self.g = g2
self.queue_draw()
g1 = gt.load_graph("mygraph.xml.gz")
g2 = gt.GraphView(g1, vfilt=SOMEFILTER)
gt.interactive_window(g1, key_press_callback=my_key_press_callback)
Any suggestions are appreciated.
Best regards
Rolf
ps: Sorry if you receive this email twice; my previous post somehow
ended up hidden in an old thread.
--
-----------------------------------------------------------------------
Rolf Sander phone: [+49] 6131/305-4610
Max-Planck Institute of Chemistry email: rolf.sander(a)mpic.de
PO Box 3060, 55020 Mainz, Germany homepage: www.rolf-sander.net
-----------------------------------------------------------------------
https://www.encyclopedia-of-geosciences.nethttps://www.geoscientific-model-development.net
-----------------------------------------------------------------------
Hi,
I am trying to set a property (my_prop) for all the edges of a graph, where
the property values for all edges are stored in an array A.
My plan is to use my_prop.get_array()[:] = A.
Now, in what order do the values need to be in A to make sure each value
goes to the correct edge? In other words, in what order are the properties
of edges returned by get_array() ?
I initially thought the order would be the same as the one returned by
calling g.get_edges(), but that does not set them correctly. When I tried
with g.edge_index, it seems to work. Can I rely on setting the value of an
edge E in A at position A[g.edge_index[E]] ?
Thanks a lot,
Ioana
--
Sent from: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/
I followed the installation instructions in the website:
https://git.skewed.de/count0/graph-tool/-/wikis/installation-instructions
for installing graph-tool on Ubuntu 18.04, but when I write "sudo apt-get
install python3-graph-tool" in the terminal, it gives me the following
error:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
python3-graph-tool : Depends: libboost-context1.67.0 but it is not
installable
Depends: libboost-iostreams1.67.0 but it is not
installable
Depends: libboost-python1.67.0 but it is not
installable
Depends: libboost-python1.67.0-py38 but it is not
installable
Depends: libboost-regex1.67.0-icu63 but it is not
installable
Depends: libc6 (>= 2.29) but 2.27-3ubuntu1 is to be
installed
Depends: libgcc-s1 (>= 3.4) but it is not installable
Depends: libgomp1 (>= 9) but 8.4.0-1ubuntu1~18.04 is
to be installed
Depends: libstdc++6 (>= 9) but 8.4.0-1ubuntu1~18.04 is
to be installed
E: Unable to correct problems, you have held broken packages.
Does anyone know how I can fix it?
--
Sent from: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/