{"id":31320666,"url":"https://github.com/chengjun/flownetwork","last_synced_at":"2025-09-25T16:54:32.942Z","repository":{"id":52882003,"uuid":"92515424","full_name":"chengjun/flownetwork","owner":"chengjun","description":"A python package for flow network analysis","archived":false,"fork":false,"pushed_at":"2025-08-13T11:31:59.000Z","size":3320,"stargazers_count":30,"open_issues_count":1,"forks_count":8,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-09-15T18:51:54.266Z","etag":null,"topics":["network-analysis","networkx","python"],"latest_commit_sha":null,"homepage":"https://pypi.python.org/pypi/flownetwork","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chengjun.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-26T13:52:14.000Z","updated_at":"2025-08-13T11:32:02.000Z","dependencies_parsed_at":"2022-09-02T11:01:06.782Z","dependency_job_id":null,"html_url":"https://github.com/chengjun/flownetwork","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/chengjun/flownetwork","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chengjun%2Fflownetwork","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chengjun%2Fflownetwork/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chengjun%2Fflownetwork/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chengjun%2Fflownetwork/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chengjun","download_url":"https://codeload.github.com/chengjun/flownetwork/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chengjun%2Fflownetwork/sbom","scorecard":{"id":276122,"data":{"date":"2025-08-11","repo":{"name":"github.com/chengjun/flownetwork","commit":"517e676bff8e9a6b68cb35fdb84ab603bb4fb8dd"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":5.2,"checks":[{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Token-Permissions","score":10,"reason":"GitHub workflow tokens follow principle of least privilege","details":["Info: topLevel 'contents' permission set to 'read': .github/workflows/python-publish.yml:16","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Binary-Artifacts","score":9,"reason":"binaries present in source code","details":["Warn: binary detected: dist/flownetwork-3.12-py2.py3-none-any.whl:1"],"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Maintained","score":10,"reason":"28 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/python-publish.yml:62: update your workflow using https://app.stepsecurity.io/secureworkflow/chengjun/flownetwork/python-publish.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/python-publish.yml:68: update your workflow using https://app.stepsecurity.io/secureworkflow/chengjun/flownetwork/python-publish.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/python-publish.yml:23: update your workflow using https://app.stepsecurity.io/secureworkflow/chengjun/flownetwork/python-publish.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/python-publish.yml:25: update your workflow using https://app.stepsecurity.io/secureworkflow/chengjun/flownetwork/python-publish.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/python-publish.yml:36: update your workflow using https://app.stepsecurity.io/secureworkflow/chengjun/flownetwork/python-publish.yml/master?enable=pin","Warn: pipCommand not pinned by hash: .github/workflows/python-publish.yml:32","Info:   0 out of   4 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   1 third-party GitHubAction dependencies pinned","Info:   0 out of   1 pipCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE.txt:0","Info: FSF or OSI recognized license: MIT License: LICENSE.txt:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}}]},"last_synced_at":"2025-08-17T14:26:03.193Z","repository_id":52882003,"created_at":"2025-08-17T14:26:03.193Z","updated_at":"2025-08-17T14:26:03.193Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":276913452,"owners_count":25727127,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-25T02:00:09.612Z","response_time":80,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["network-analysis","networkx","python"],"created_at":"2025-09-25T16:54:31.321Z","updated_at":"2025-09-25T16:54:32.929Z","avatar_url":"https://github.com/chengjun.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# flownetwork\n\nA python package for flow network analysis https://pypi.python.org/pypi/flownetwork\n\n## install the most updated github version\n\n```python\npip install -U git+https://github.com/chengjun/flownetwork.git\n```\n\n## install and upgrade\n\nOpen a terminal, and input:\n\n\n```python\npip install flownetwork\n```\n\nif your want to ungrade to a new version, just input:\n\n```python\npip install --upgrade flownetwork\n```\n\nif your want to uninstall, please input:\n\n```python\npip uninstall flownetwork\n```\n\n## import\n\n```python\n# import packages\nimport flownetwork.flownetwork as fn\nimport networkx as nx\nimport matplotlib.pyplot as plt\n\nprint(fn.__version__)\n\n```\n\n    $version = 3.2.0$\n\n\n\n## flow network analysis\n\n```python\nhelp(fn.constructFlowNetwork)\n```\n\n    Help on function constructFlowNetwork in module flownetwork.flownetwork:\n\n    constructFlowNetwork(C)\n        C is an array of two dimentions, e.g.,\n        C = np.array([[user1, item1],\n                      [user1, item2],\n                      [user2, item1],\n                      [user2, item3]])\n        Return a balanced flow network\n\n\n\n\n```python\n# constructing a flow network\ndemo = fn.attention_data\ngd = fn.constructFlowNetwork(demo)\n```\n\n```python\n# drawing a demo network\nfig = plt.figure(figsize=(12, 8),facecolor='white')\npos={0: np.array([ 0.2 ,  0.8]),\n 2: np.array([ 0.2,  0.2]),\n 1: np.array([ 0.4,  0.6]),\n 6: np.array([ 0.4,  0.4]),\n 4: np.array([ 0.7,  0.8]),\n 5: np.array([ 0.7,  0.5]),\n 3: np.array([ 0.7,  0.2 ]),\n 'sink': np.array([ 1,  0.5]),\n 'source': np.array([ 0,  0.5])}\nwidth=[float(d['weight']*1.2) for (u,v,d) in gd.edges(data=True)]\nedge_labels=dict([((u,v,),d['weight']) for u,v,d in gd.edges(data=True)])\nnx.draw_networkx_edge_labels(gd,pos,edge_labels=edge_labels, font_size = 15, alpha = .5)\nnx.draw(gd, pos, node_size = 3000, node_color = 'orange',\n        alpha = 0.2, width = width, edge_color='orange',style='solid')\nnx.draw_networkx_labels(gd,pos,font_size=18)\nplt.show()\n```\n\n![](img/flownetwork_demo.png)\n\n\n```python\nnx.info(gd)\n```\n\n\n\n\n    'Name: \\nType: DiGraph\\nNumber of nodes: 9\\nNumber of edges: 15\\nAverage in degree:   1.6667\\nAverage out degree:   1.6667'\n\n\n\n\n```python\n# balancing the network\n# if it is not balanced\ngh = fn.flowBalancing(gd)\nnx.info(gh)\n```\n\n\n\n\n    'Name: \\nType: DiGraph\\nNumber of nodes: 9\\nNumber of edges: 15\\nAverage in degree:   1.6667\\nAverage out degree:   1.6667'\n\n\n\n\n\n\n```python\n# flow matrix\nm = fn.getFlowMatrix(gd)\nm\n```\n\n\n\n\n    matrix([[ 0.,  1.,  0.,  0.,  3.,  1.,  0.,  0.,  0.],\n            [ 0.,  0.,  3.,  0.,  0.,  0.,  0.,  0.,  0.],\n            [ 0.,  0.,  0.,  2.,  0.,  0.,  0.,  0.,  2.],\n            [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  2.],\n            [ 0.,  0.,  0.,  0.,  0.,  1.,  0.,  0.,  2.],\n            [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  2.],\n            [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  1.],\n            [ 5.,  2.,  1.,  0.,  0.,  0.,  1.,  0.,  0.],\n            [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.]])\n\n\n\n\n```python\nfn.getMarkovMatrix(m)\n```\n\n\n\n\n    array([[ 0.        ,  0.2       ,  0.        ,  0.        ,  0.6       ,\n             0.2       ,  0.        ,  0.        ,  0.        ],\n           [ 0.        ,  0.        ,  1.        ,  0.        ,  0.        ,\n             0.        ,  0.        ,  0.        ,  0.        ],\n           [ 0.        ,  0.        ,  0.        ,  0.5       ,  0.        ,\n             0.        ,  0.        ,  0.        ,  0.5       ],\n           [ 0.        ,  0.        ,  0.        ,  0.        ,  0.        ,\n             0.        ,  0.        ,  0.        ,  1.        ],\n           [ 0.        ,  0.        ,  0.        ,  0.        ,  0.        ,\n             0.33333333,  0.        ,  0.        ,  0.66666667],\n           [ 0.        ,  0.        ,  0.        ,  0.        ,  0.        ,\n             0.        ,  0.        ,  0.        ,  1.        ],\n           [ 0.        ,  0.        ,  0.        ,  0.        ,  0.        ,\n             0.        ,  0.        ,  0.        ,  1.        ],\n           [ 0.55555556,  0.22222222,  0.11111111,  0.        ,  0.        ,\n             0.        ,  0.11111111,  0.        ,  0.        ],\n           [ 0.        ,  0.        ,  0.        ,  0.        ,  0.        ,\n             0.        ,  0.        ,  0.        ,  0.        ]])\n\n\n\n\n```python\nfn.getUmatrix(gd)\n```\n\n\n\n\n    matrix([[ 1.        ,  0.2       ,  0.2       ,  0.1       ,  0.6       ,\n              0.4       ,  0.        ],\n            [ 0.        ,  1.        ,  1.        ,  0.5       ,  0.        ,\n              0.        ,  0.        ],\n            [ 0.        ,  0.        ,  1.        ,  0.5       ,  0.        ,\n              0.        ,  0.        ],\n            [ 0.        ,  0.        ,  0.        ,  1.        ,  0.        ,\n              0.        ,  0.        ],\n            [ 0.        ,  0.        ,  0.        ,  0.        ,  1.        ,\n              0.33333333,  0.        ],\n            [ 0.        ,  0.        ,  0.        ,  0.        ,  0.        ,\n              1.        ,  0.        ],\n            [ 0.        ,  0.        ,  0.        ,  0.        ,  0.        ,\n              0.        ,  1.        ]])\n\n\n\n\n```python\n# return dissipationToSink,totalFlow,flowFromSource\n\nfn.networkDissipate(gd)\n```\n\n\n\n\n    defaultdict(\u003cfunction flownetwork.flownetwork.\u003clambda\u003e\u003e,\n                {0: [0, 5, 5],\n                 1: [0, 3, 2],\n                 2: [2, 4, 1],\n                 3: [2, 2, 0],\n                 4: [2, 3, 0],\n                 5: [2, 2, 0],\n                 6: [1, 1, 1]})\n\n\n\n\n```python\n# flow distance\nfn.flowDistanceFromSource(gd)\n```\n\n\n\n\n    {0: 1.0,\n     1: 1.333333333333333,\n     2: 2.0,\n     3: 3.0,\n     4: 2.0,\n     5: 2.5,\n     6: 1.0,\n     'sink': 3.2222222222222214}\n\n\n\n\n```python\nfn.outflow(gd, 1)\n```\n\n\n\n\n    3\n\n\n\n\n```python\nfn.inflow(gd, 1)\n```\n\n\n\n\n    3\n\n\n\n\n```python\nfn.averageFlowLength(gd)\n```\n\n\n\n\n    3.2222222222222223\n\n\n\n\n```python\n# fn.getAverageTimeMatrix(gd)\n```\n\n\n## Plot\n\n```python\nfig = plt.figure(figsize=(9, 9),facecolor='white')\nax = fig.add_subplot(111)\nfn.plotTree(gd,ax)\nplt.show()\n```\n\n\n\n```python\nfrom random import random\nx = np.array(range(1, 100))\ny = (x+random()*x)**3\n\nplt.plot(x, y)\nplt.xscale('log');plt.yscale('log')\nplt.show()\n```\n\n\n![png](img/output_109_0.png)\n\n\n\n```python\nfn.alloRegressPlot(x,y,'r','s','$x$','$y$', loglog=True)\n```\n\n\n![png](img/output_110_0.png)\n\n\n\n```python\nrg = np.array([ 20.7863444 ,   9.40547933,   8.70934714,   8.62690145,\n     7.16978087,   7.02575052,   6.45280959,   6.44755478,\n     5.16630287,   5.16092884,   5.15618737,   5.05610068,\n     4.87023561,   4.66753197,   4.41807645,   4.2635671 ,\n     3.54454372,   2.7087178 ,   2.39016885,   1.9483156 ,\n     1.78393238,   1.75432688,   1.12789787,   1.02098332,\n     0.92653501,   0.32586582,   0.1514813 ,   0.09722761])\nfn.powerLawExponentialCutOffPlot(rg, '$x$', '$p(x)$')\n```\n\n\n\n\n    [-0.0099301962503268171,\n     -0.064764460567964449,\n     -0.17705123513352666,\n     0.89999847894045781]\n\n\n\n\n![png](img/output_111_1.png)\n\n\n\n```python\nfn.DGBDPlot(rg)\n```\n\n\n![png](img/output_112_0.png)\n\n\n\n```python\nfrom networkx.utils import powerlaw_sequence\npl_sequence = powerlaw_sequence(1000,exponent=2.5)\n\nfig = plt.figure(figsize=(4, 4),facecolor='white')\nax = fig.add_subplot(111)\nfn.plotPowerlaw(pl_sequence,ax,'r','$x$')\n\n```\n\n    Calculating best minimal value for power law fit\n\n\n\n![png](img/output_113_1.png)\n\n\n\n```python\nfig = plt.figure(figsize=(4, 4),facecolor='white')\nax = fig.add_subplot(111)\nfn.plotCCDF(pl_sequence,ax,'b','$x$')\n\n```\n\n    Calculating best minimal value for power law fit\n\n\n\n![png](img/output_114_1.png)\n\n\n\n```python\nbins, result, gini_val = fn.gini_coefficient(np.array(pl_sequence))\n\nplt.plot(bins, bins, '--', label=\"perfect\")\nplt.plot(bins, result, label=\"observed\")\nplt.title(\"$GINI: %.4f$\" %(gini_val))\n\nplt.legend(loc = 0, frameon = False)\nplt.show()\n```\n\n\n![png](img/output_115_0.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchengjun%2Fflownetwork","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchengjun%2Fflownetwork","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchengjun%2Fflownetwork/lists"}