All Projects → chengjun → flownetwork

chengjun / flownetwork

Licence: MIT License
A python package for flow network analysis

Programming Languages

Jupyter Notebook
11667 projects
python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to flownetwork

LNTopology
A tool to analyze the topology of Bitcoin's Lightning Network
Stars: ✭ 19 (-13.64%)
Mutual labels:  networkx, network-analysis
Awesome Community Detection
A curated list of community detection research papers with implementations.
Stars: ✭ 1,874 (+8418.18%)
Mutual labels:  networkx, network-analysis
Final Project
Using Twitter Ego Network Analysis to Detect Sources of Fake News
Stars: ✭ 44 (+100%)
Mutual labels:  networkx, network-analysis
Junet.jl
Julia package for network research
Stars: ✭ 37 (+68.18%)
Mutual labels:  network-analysis
Friends-Recommender-In-Social-Network
Friends Recommendation and Link Prediction in Social Netowork
Stars: ✭ 33 (+50%)
Mutual labels:  networkx
netdiff
Python library for parsing network topology data (eg: dynamic routing protocols, OpenVPN, NetJSON, CNML) and detect changes.
Stars: ✭ 66 (+200%)
Mutual labels:  networkx
arpwitch
A modern arpwatch replacement with JSON formatted outputs and easy options to exec commands when network changes are observed.
Stars: ✭ 20 (-9.09%)
Mutual labels:  network-analysis
networkx-neo4j
NetworkX API for Neo4j Graph Algorithms.
Stars: ✭ 98 (+345.45%)
Mutual labels:  networkx
network-pipeline
Network traffic data pipeline for real-time predictions and building datasets for deep neural networks
Stars: ✭ 36 (+63.64%)
Mutual labels:  network-analysis
infomap ecology package
Package with functions to handle network data and run Infomap, inspired by ecological networks
Stars: ✭ 14 (-36.36%)
Mutual labels:  network-analysis
sflow-collector
A Python class for parsing sFlow packets.
Stars: ✭ 16 (-27.27%)
Mutual labels:  network-analysis
DEMON
DEMON: a local-first discovery method for overlapping communities.
Stars: ✭ 26 (+18.18%)
Mutual labels:  network-analysis
opensnitch
OpenSnitch is a GNU/Linux application firewall
Stars: ✭ 398 (+1709.09%)
Mutual labels:  network-analysis
f1-communities
A novel approach to evaluate community detection algorithms on ground truth
Stars: ✭ 20 (-9.09%)
Mutual labels:  network-analysis
signnet
R package for signed networks
Stars: ✭ 19 (-13.64%)
Mutual labels:  network-analysis
NetBID
Data-driven Network-based Bayesian Inference of Drivers
Stars: ✭ 21 (-4.55%)
Mutual labels:  network-analysis
kubernetes-iperf3
Simple wrapper around iperf3 to measure network bandwidth from all nodes of a Kubernetes cluster
Stars: ✭ 80 (+263.64%)
Mutual labels:  network-analysis
awesome-networking
A curated inexhaustive list of network utilities
Stars: ✭ 36 (+63.64%)
Mutual labels:  network-analysis
Causal-Deconvolution-of-Networks
Causal Deconvolution of Networks by Algorithmic Generative Models
Stars: ✭ 25 (+13.64%)
Mutual labels:  network-analysis
aera-workshop
This workshop introduces participants to the Learning Analytics (LA), and provides a brief overview of LA methodologies, literature, applications, and ethical issues as they relate to STEM education.
Stars: ✭ 14 (-36.36%)
Mutual labels:  network-analysis

flownetwork

A python package for flow network analysis https://pypi.python.org/pypi/flownetwork

install the most updated github version

pip install -U git+https://github.com/chengjun/flownetwork.git

install and upgrade

Open a terminal, and input:

pip install flownetwork

if your want to ungrade to a new version, just input:

pip install --upgrade flownetwork

if your want to uninstall, please input:

pip uninstall flownetwork

import

# import packages
import flownetwork.flownetwork as fn
import networkx as nx
import matplotlib.pyplot as plt

print(fn.__version__)
$version = 3.0.9$

flow network analysis

help(fn.constructFlowNetwork)
Help on function constructFlowNetwork in module flownetwork.flownetwork:

constructFlowNetwork(C)
    C is an array of two dimentions, e.g.,
    C = np.array([[user1, item1],
                  [user1, item2],
                  [user2, item1],
                  [user2, item3]])
    Return a balanced flow network
# constructing a flow network
demo = fn.attention_data
gd = fn.constructFlowNetwork(demo)
# drawing a demo network
fig = plt.figure(figsize=(12, 8),facecolor='white')
pos={0: np.array([ 0.2 ,  0.8]),
 2: np.array([ 0.2,  0.2]),
 1: np.array([ 0.4,  0.6]),
 6: np.array([ 0.4,  0.4]),
 4: np.array([ 0.7,  0.8]),
 5: np.array([ 0.7,  0.5]),
 3: np.array([ 0.7,  0.2 ]),
 'sink': np.array([ 1,  0.5]),
 'source': np.array([ 0,  0.5])}
width=[float(d['weight']*1.2) for (u,v,d) in gd.edges(data=True)]
edge_labels=dict([((u,v,),d['weight']) for u,v,d in gd.edges(data=True)])
nx.draw_networkx_edge_labels(gd,pos,edge_labels=edge_labels, font_size = 15, alpha = .5)
nx.draw(gd, pos, node_size = 3000, node_color = 'orange',
        alpha = 0.2, width = width, edge_color='orange',style='solid')
nx.draw_networkx_labels(gd,pos,font_size=18)
plt.show()

nx.info(gd)
'Name: \nType: DiGraph\nNumber of nodes: 9\nNumber of edges: 15\nAverage in degree:   1.6667\nAverage out degree:   1.6667'
# balancing the network
# if it is not balanced
gh = fn.flowBalancing(gd)
nx.info(gh)
'Name: \nType: DiGraph\nNumber of nodes: 9\nNumber of edges: 15\nAverage in degree:   1.6667\nAverage out degree:   1.6667'
# flow matrix
m = fn.getFlowMatrix(gd)
m
matrix([[ 0.,  1.,  0.,  0.,  3.,  1.,  0.,  0.,  0.],
        [ 0.,  0.,  3.,  0.,  0.,  0.,  0.,  0.,  0.],
        [ 0.,  0.,  0.,  2.,  0.,  0.,  0.,  0.,  2.],
        [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  2.],
        [ 0.,  0.,  0.,  0.,  0.,  1.,  0.,  0.,  2.],
        [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  2.],
        [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  1.],
        [ 5.,  2.,  1.,  0.,  0.,  0.,  1.,  0.,  0.],
        [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.]])
fn.getMarkovMatrix(m)
array([[ 0.        ,  0.2       ,  0.        ,  0.        ,  0.6       ,
         0.2       ,  0.        ,  0.        ,  0.        ],
       [ 0.        ,  0.        ,  1.        ,  0.        ,  0.        ,
         0.        ,  0.        ,  0.        ,  0.        ],
       [ 0.        ,  0.        ,  0.        ,  0.5       ,  0.        ,
         0.        ,  0.        ,  0.        ,  0.5       ],
       [ 0.        ,  0.        ,  0.        ,  0.        ,  0.        ,
         0.        ,  0.        ,  0.        ,  1.        ],
       [ 0.        ,  0.        ,  0.        ,  0.        ,  0.        ,
         0.33333333,  0.        ,  0.        ,  0.66666667],
       [ 0.        ,  0.        ,  0.        ,  0.        ,  0.        ,
         0.        ,  0.        ,  0.        ,  1.        ],
       [ 0.        ,  0.        ,  0.        ,  0.        ,  0.        ,
         0.        ,  0.        ,  0.        ,  1.        ],
       [ 0.55555556,  0.22222222,  0.11111111,  0.        ,  0.        ,
         0.        ,  0.11111111,  0.        ,  0.        ],
       [ 0.        ,  0.        ,  0.        ,  0.        ,  0.        ,
         0.        ,  0.        ,  0.        ,  0.        ]])
fn.getUmatrix(gd)
matrix([[ 1.        ,  0.2       ,  0.2       ,  0.1       ,  0.6       ,
          0.4       ,  0.        ],
        [ 0.        ,  1.        ,  1.        ,  0.5       ,  0.        ,
          0.        ,  0.        ],
        [ 0.        ,  0.        ,  1.        ,  0.5       ,  0.        ,
          0.        ,  0.        ],
        [ 0.        ,  0.        ,  0.        ,  1.        ,  0.        ,
          0.        ,  0.        ],
        [ 0.        ,  0.        ,  0.        ,  0.        ,  1.        ,
          0.33333333,  0.        ],
        [ 0.        ,  0.        ,  0.        ,  0.        ,  0.        ,
          1.        ,  0.        ],
        [ 0.        ,  0.        ,  0.        ,  0.        ,  0.        ,
          0.        ,  1.        ]])
# return dissipationToSink,totalFlow,flowFromSource

fn.networkDissipate(gd)
defaultdict(<function flownetwork.flownetwork.<lambda>>,
            {0: [0, 5, 5],
             1: [0, 3, 2],
             2: [2, 4, 1],
             3: [2, 2, 0],
             4: [2, 3, 0],
             5: [2, 2, 0],
             6: [1, 1, 1]})
# flow distance
fn.flowDistanceFromSource(gd)
{0: 1.0,
 1: 1.333333333333333,
 2: 2.0,
 3: 3.0,
 4: 2.0,
 5: 2.5,
 6: 1.0,
 'sink': 3.2222222222222214}
fn.outflow(gd, 1)
3
fn.inflow(gd, 1)
3
fn.averageFlowLength(gd)
3.2222222222222223
# fn.getAverageTimeMatrix(gd)

Plot

fig = plt.figure(figsize=(9, 9),facecolor='white')
ax = fig.add_subplot(111)
fn.plotTree(gd,ax)
plt.show()
from random import random
x = np.array(range(1, 100))
y = (x+random()*x)**3

plt.plot(x, y)
plt.xscale('log');plt.yscale('log')
plt.show()

png

fn.alloRegressPlot(x,y,'r','s','$x$','$y$', loglog=True)

png

rg = np.array([ 20.7863444 ,   9.40547933,   8.70934714,   8.62690145,
     7.16978087,   7.02575052,   6.45280959,   6.44755478,
     5.16630287,   5.16092884,   5.15618737,   5.05610068,
     4.87023561,   4.66753197,   4.41807645,   4.2635671 ,
     3.54454372,   2.7087178 ,   2.39016885,   1.9483156 ,
     1.78393238,   1.75432688,   1.12789787,   1.02098332,
     0.92653501,   0.32586582,   0.1514813 ,   0.09722761])
fn.powerLawExponentialCutOffPlot(rg, '$x$', '$p(x)$')
[-0.0099301962503268171,
 -0.064764460567964449,
 -0.17705123513352666,
 0.89999847894045781]

png

fn.DGBDPlot(rg)

png

from networkx.utils import powerlaw_sequence
pl_sequence = powerlaw_sequence(1000,exponent=2.5)

fig = plt.figure(figsize=(4, 4),facecolor='white')
ax = fig.add_subplot(111)
fn.plotPowerlaw(pl_sequence,ax,'r','$x$')
Calculating best minimal value for power law fit

png

fig = plt.figure(figsize=(4, 4),facecolor='white')
ax = fig.add_subplot(111)
fn.plotCCDF(pl_sequence,ax,'b','$x$')
Calculating best minimal value for power law fit

png

bins, result, gini_val = fn.gini_coefficient(np.array(pl_sequence))

plt.plot(bins, bins, '--', label="perfect")
plt.plot(bins, result, label="observed")
plt.title("$GINI: %.4f$" %(gini_val))

plt.legend(loc = 0, frameon = False)
plt.show()

png

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].