项目作者: benmaier

项目描述 :
Provides classes around biased random walks on networks.
高级语言: Python
项目地址: git://github.com/benmaier/BiasedRandomWalks.git
创建时间: 2018-07-02T23:24:56Z
项目社区:https://github.com/benmaier/BiasedRandomWalks

开源协议:

下载


BiasedRandomWalks

Provides classes around biased random walks on networks.

Install

  1. $ git clone git@github.com:benmaier/BiasedRandomWalks.git
  2. $ pip install ./BiasedRandomWalks

Examples

  1. import numpy as np
  2. import matplotlib.pyplot as pl
  3. import networkx as nx
  4. from BiasedRandomWalks import BiasedRandomWalk
  5. # Create a test Graph with weighted edges where weights are distances
  6. G = nx.Graph()
  7. N = 4
  8. G.add_nodes_from(range(N))
  9. G.add_edge(0,1,weight=1)
  10. G.add_edge(0,2,weight=1)
  11. G.add_edge(1,2,weight=1)
  12. G.add_edge(1,3,weight=0.1)
  13. G.add_edge(2,3,weight=0.2)
  14. # define sink nodes
  15. sink_nodes = [2,]
  16. # define bias
  17. gamma = 1
  18. # initial distribution on transient
  19. p0 = np.array([1,0,0])
  20. # initial distribution on all
  21. p0_all = np.array([1,0,0,0])
  22. # initial base class (choose 'exponential' or 'scale free')
  23. RW = BiasedRandomWalk(G, gamma, sink_nodes, bias_kind = 'exponential')
  24. fig, ax = pl.subplots(2,2,figsize=(9,7))
  25. # integrate up to this time step
  26. tmax = 10
  27. # ========== prob density on sinks =========
  28. t, rho = RW.get_amount_of_walkers_arriving_at_sink_nodes(p0,tmax)
  29. for i_s, s in enumerate(sink_nodes):
  30. ax[0,0].plot(t, rho[:,i_s], label='sink node '+ str(s))
  31. ax[0,0].legend()
  32. ax[0,0].set_xlabel('time')
  33. ax[0,0].set_ylabel('amount of walkers arriving')
  34. # ========== cdf on sinks =========
  35. t, rho = RW.get_amount_of_walkers_arrived_at_sink_nodes(p0,tmax)
  36. for i_s, s in enumerate(sink_nodes):
  37. ax[0,1].plot(t, rho[:,i_s], label='sink node '+ str(s))
  38. ax[0,1].legend()
  39. ax[0,1].set_xlabel('time')
  40. ax[0,1].set_ylabel('total amount of walkers arrived')
  41. # ========== prob density on all =========
  42. t, rho = RW.get_amount_of_walkers_on_nodes(p0_all,tmax)
  43. for s in G.nodes():
  44. ax[1,0].plot(t, rho[:,s], label='node '+ str(s))
  45. ax[1,0].legend()
  46. ax[1,0].set_xlabel('time')
  47. ax[1,0].set_ylabel('amount of walkers on each node')
  48. pl.show()