summaryrefslogtreecommitdiff
path: root/networkx/algorithms/centrality
Commit message (Collapse)AuthorAgeFilesLines
* Improve test coverage for reaching.py (#6678)Vanshika Mishra2023-05-021-0/+8
|
* Improve Test Coverage for current_flow_closeness.py (#6677)Vanshika Mishra2023-05-021-0/+6
| | | Improve_test_coverage_cfc.py
* Fix links in eigenvector.py and katz_centrality.py (#6640)Vanshika Mishra2023-04-152-8/+8
| | | Fix links in see also section of docs
* Fix links in laplacian_centrality and laplacian_matrix (#6623)Navya Agarwal2023-04-061-2/+2
| | | Fix links in See Also section
* Fix typos (#6620)Harri Nieminen2023-04-041-1/+1
|
* Start using ruff for pyupgrade and isort (#6441)Mridul Seth2023-02-251-1/+3
|
* Lint using Ruff (#6371)danieleades2023-02-191-2/+2
| | | | | | | | | | | | | | | * lint and fix using ruff * add flake8-pie lints * remove useless import alias * bump version * bump deps --------- Co-authored-by: daniel.eades <daniel.eades@hotmail.com>
* Update developer requirements (#6429)Jarrod Millman2023-02-145-11/+9
| | | | | * Update developer requirements * Run linter
* Remove an instance of random.sample from a set (deprecated in Python 3.9) ↵Erik Welch2023-01-201-1/+1
| | | | (#6380)
* DOC: Minor formatting fixups to get rid of doc build warnings. (#6363)Ross Barnowski2023-01-131-10/+9
| | | Minor formatting fixups to get rid of doc build warnings.
* Laplace centrality for issue 4973 (#5399)Gabor Berei2023-01-093-0/+327
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * first commit, start testing * rename * formatting with black * formating example based on testing failure * deleting example from docstring * rewriting example based on eigenvector.py * rewrite docstring for other supplementary functions * formating with black * deleting custom scipy function * rewriting matrix manipulation * rewriting nbunch iteration based on review * rewriting dictionary update * update directed_laplacian_matrix_args params * rewriting docstring based on comments * update docstring * update docstring with Laplacian energy def * update docstring * bringing package imports into the function * adding laplacian.py to needs_numpy and needs_scipy tests * addig Laplacian centrality to centrality.rst * formatting with black * dictionary update fix * beatify docstring Co-authored-by: Dan Schult <dschult@colgate.edu> * beatify docstring Co-authored-by: Dan Schult <dschult@colgate.edu> * beatify docstring Co-authored-by: Dan Schult <dschult@colgate.edu> * beatify docstring Co-authored-by: Dan Schult <dschult@colgate.edu> * beautify with black * add ** to kwargs in function * add test file for local testing * black test file * black * replace nx.laplacian to direct import * adding pytest importskip and formating with black * adding laplacian centrality to the init file * changing import from direct to nx.laplacian * rewriting output for non-normalized option * rewriting tests using functions instead of class structure * mod with black * formating * formating * directed and undirected laplace and eigen values correction * black formating * adding asfptype for sparse eig solver and format with black * change from sparse solver to dense solver * change back A_2 eigval solver * format with black * black * change back to previous state * change back to previous state * new eigh func * fix eighvals func * adding laplacian matrix parameters * change alpha to None * change back alpha to 0.95 * adding nodeset and ful nodelist objects * adding nodeset and relevant error message * solving directed-undirected issue converting everything to sparse matrix * change line ending * untrack env files * isort test file * adding nodelist and noteset * black * change centrality calculation to nodeset instead of full nodelist * added comment * eigh_f func to one-liner * move eigh value calculation outside if condition * simplify row/column by advanced indexing * simplify row/column by advanced indexing for set diag * format with black * wrap doc_string to 88 chars and reword optional keywords. * handle nodelist and nodeset * remove casting as a csr_matrix * covert to dense since we have to for computing the spectrum anyway. * minor: ease readability * fix normalization * add tests for normalized and weight kwargs * fix black Co-authored-by: Dan Schult <dschult@colgate.edu> Co-authored-by: Gabor Berei <bereig@starschema.net>
* Fix typos in the networkx codebase (#6335)Anurag Bhat2023-01-051-1/+1
| | | | | * Fix_Typos * Commit_Suggestions
* Fix typo in Katz centrality comment (#6310)Anurag Bhat2023-01-031-1/+1
|
* Improve test coverage for Eigenvector centrality (#6227)Alimi Qudirah2022-12-131-0/+7
| | | | | | | Fixes: 6226 * Minor formatting fixups. Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
* PR for issue #6033 Improve test coverage for algorithms in ↵ladykkk2022-11-141-0/+131
| | | | | | | | | | | | | | | | | | | betweenness_subset.py #6033 (#6083) * Updated test_betweenness_centrality_subset.py * add test of normalized in test_betweenness_centrality_subset.py * add test of normalized in test_betweenness_centrality_subset.py * update test of normalized in test_betweenness_centrality_subset.py * update weight of test_betweenness_centrality_subset.py * add docstring * add docstring in test_betweenness_centrality_subset.py * add docstring in test_betweenness_centrality_subset.py
* Improve test coverage for current_flow_betweenness module (#6143)Okite chimaobi Samuel2022-11-081-0/+20
| | | Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
* Undocumented parameters in dispersion (#6183)Alimi Qudirah2022-11-081-0/+7
| | | | | | | | | | | | | | | | | | | | | | | * fixes #6036 * test load centrality * test dispersion * test dispersion * dispersion test * test dispersion * bug-fixes-for-issue-6088 * deleted * bugfix for 6111 * Add suggestion for parameter description. Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
* plugin based backend infrastructure to use multiple computation backends (#6000)Mridul Seth2022-11-084-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Wrappers classes to dispatch to a backend * Rework the backend dispatching - Use __networkx_plugin__=name to find graph-like objects instead of subclassing - Add PluginInfo to smooth over differences in importlib.metadata across python versions - Add dispatch behavior override via environment variable to aid in testing plugins * Dispatch more algorithms and improve auto-test capabilities * Allow dispatcher decorator without a name - Name is taken from the decorated function - Raise error if backend doesn't implement a decorated function which is called - Check for duplicate names for dispatching algorithms * Make sphinx pick up backend docs * make black happy * Rename decorator to _dispatch as it's experimental * A few more dispatched functions * Make convert to and from methods for auto-testing - Rename `convert` to `convert_from_nx` - Add `convert_to_nx` function These will allow backends to return native objects when dispatching, but provide a mechanism to convert the result to the type expected by NetworkX tests for the auto-test plugin mechanism. * More dispatching * Include name with `convert_**_nx` methods * Remove known plugin names This check is not needed, as any plugin can register itself in the entry points section. The dispatching and auto-testing explicitly specify the plugin to use, so there is no need to hardcode the options. These were originally included for security, but any malicious actor would simply use one of the valid names, so having a hardcoded list does not actually provide any meaningful security. * Add `dispatchname` to dispatchable functions Co-authored-by: Jim Kitchen <jim22k@gmail.com> Co-authored-by: Erik Welch <erik.n.welch@gmail.com>
* Improve test coverage for voterank algorithm (#6161)Alimi Qudirah2022-11-081-0/+4
| | | | | | | | | | | | | | | | | | | * fixes #6036 * test load centrality * test dispersion * test dispersion * dispersion test * test dispersion * bug-fixes-for-issue-6088 * deleted * bugfix for 6154
* Improve test coverage for algorithms in dispersion.py (#6100)Alimi Qudirah2022-10-271-0/+7
| | | | | | | | | | | | | | | | | | | * fixes #6036 * test load centrality * test dispersion * test dispersion * dispersion test * test dispersion * bug-fixes-for-issue-6088 * deleted * bug-fix-for-issue-6092
* fixes #6036 (#6080)Alimi Qudirah2022-10-181-0/+8
| | | | | * fixes #6036 * test load centrality
* Use scipy.sparse array datastructure (#6037)Jarrod Millman2022-10-122-3/+0
| | | | | | | | | | | | | | * Use scipy.sparse array datastructure * Add reminder to rm wrapper when scipy adds creation fns. * Rm mention of np matrix from code comment. * Update networkx/algorithms/bipartite/matrix.py Co-authored-by: Stefan van der Walt <sjvdwalt@gmail.com> Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> Co-authored-by: Stefan van der Walt <sjvdwalt@gmail.com>
* added examples to degree_alg.py (#5644)Lukong1232022-07-051-0/+18
| | | | | | | | | * added example on degree centrality * added example on in degree centrality * added example on out degree centrality * added opening braces
* Update distance parameter description. (#5819)Ross Barnowski2022-06-291-1/+3
| | | | | | | | | | | | | | | | | | * Update distance parameter description. Update the description of the parameter in the closeness_centrality function to note that by default, the edge distances (weights) are assumed to be 1, and that no input validation is performed. * Fix styling. * Update networkx/algorithms/centrality/closeness.py Co-authored-by: Dan Schult <dschult@colgate.edu> * Make black happy. Co-authored-by: Dan Schult <dschult@colgate.edu>
* Remove deprecated function edge_betweeness (#5765)Juanita Gomez2022-06-211-9/+1
| | | | | | | | * Remove deprecated function edge_betweeness * [ci skip] remove from release doc validation script. Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> Co-authored-by: Mridul Seth <seth.mridul@gmail.com>
* Remove betweenness_centrality_source (#5786)Dilara Tekinoglu2022-06-162-29/+0
| | | | | | | Remove betweenness_centrality_source in favor of preferred name, betweenness_centrality_subset. Co-authored-by: dtuncturk <dilaramemis@sabanciuniv.edu> Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
* MAINT: Cleanup centrality module, remove unused variables (#5308)Mridul Seth2022-06-0418-82/+70
| | | | | | | | | | | | | | | | | | | | | | * MAINT: Cleanup centrality module, remove unused variables * make isort linter happy * MAINT: make the loop more readable Co-authored-by: Dan Schult <dschult@colgate.edu> * make black happy * Use a different name for internal function variable Co-authored-by: Jarrod Millman <jarrod.millman@gmail.com> * rename closeness_cen to closeness_dict * minor cleanup in current_flow_betweenness and group Co-authored-by: Dan Schult <dschult@colgate.edu> Co-authored-by: Jarrod Millman <jarrod.millman@gmail.com>
* Use isort with pre-commit to enforce import guidelines (#5659)Mridul Seth2022-06-0223-22/+28
| | | | | * Add isort to pre-commit * Run isort on all python files (except __init__.py ones)
* Remove redundant py2 numeric conversions (#5661)Mridul Seth2022-05-316-9/+9
| | | | | | | | | * Remove redundant float conversion * Remove redundant int conversion * Use integer division Co-authored-by: Miroslav Šedivý <6774676+eumiro@users.noreply.github.com>
* added example to closeness.py (#5645)Lukong1232022-05-241-1/+7
| | | | | * added example on closeness * docstring improvement
* Add examples & improve documentation of voterank (#5500)Dilara Tekinoglu2022-05-201-2/+19
| | | | | | | | | | | | | | | | | | | | * Add examples & improve documentation of voterank * Run black for autoformatting * Fix minor typo * Change example (add edges from the list instead of one by one) Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> * Revert to previous wording * Re-format second example * minor formatting nits. Co-authored-by: dtuncturk <dilaramemis@sabanciuniv.edu> Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
* Fix missing backticks (#5381)Matthias Bussonnier2022-03-091-1/+1
| | | | | * Fix missing backticks * one more backticks
* Use scipy.sparse array datastructure (#5139)Ross Barnowski2022-01-181-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Step 1: use sparse arrays in nx.to_scipy_sparse_matrix. Seems like a reasonable place to start. nx.to_scipy_sparse_matrix is one of the primary interfaces to scipy.sparse from within NetworkX. * 1: Use np.outer instead of mult col/row vectors Fix two instances in modularitymatrix where a new 2D array was being created via an outer product of two \"vectors\". In the matrix case, this was a row vector \* a column vector. In the array case this can be disambiguated by being explicit with np.outer. * Update _transition_matrix in laplacianmatrix module - A few instances of matrix multiplication operator - Add np.newaxis + transpose to get shape right for broadcasting - Explicitly convert e.g. sp.sparse.spdiags to a csr_array. * Update directed_combinitorial_laplacian w/ sparse array. - Wrap spdiags in csr_array and update matmul operators. * Rm matrix-specific code from lgc and hmn modules - Replace .A call with appropriate array semantics - wrap sparse.diags in csr_array. * Change hits to use sparse array semantics. - Replace * with @ - Remove superfluous calls to flatten. * Update sparse matrix usage in layout module. - Simplify lil.getrowview call - Wrap spdiags in csr_array. * lil_matrix -> lil_array in graphmatrix.py. * WIP: Start working on algebraic connectivity module. * Incorporate auth mat varname feedback. * Revert 1D slice and comment for 1D sparse future. * Add TODOs: rm csr_array wrapper around spdiags etc. * WIP: cleanup algebraicconn: tracemin_fiedler. * Typo. * Finish reviewing algebraicconnectivity. * Convert bethe_hessian matrix to use sparse arrays. * WIP: update laplacian. Update undirected laplacian functions. * WIP: laplacian - add comment about _transition_matrix return types. * Finish laplacianmatrix review. * Update attrmatrix. * Switch to official laplacian function. * Update pagerank to use sparse array. * Switch bipartite matrix to sparse arrays. * Check from_scipy_sparse_matrix works with arrays. Modifies test suite. * Apply changes from review. * Fix failing docstring tests. * Fix missing axis for in-place multiplication. * Use scipy==1.8rc2 * Use matrix multiplication * Fix PyPy CI * [MRG] Create plot_subgraphs.py example (#5165) * Create plot_subgraphs.py https://github.com/networkx/networkx/issues/4220 * Update plot_subgraphs.py black * Update plot_subgraphs.py lint plus font_size * Update plot_subgraphs.py added more plots * Update plot_subgraphs.py removed plots from the unit test and added comments * Update plot_subgraphs.py lint * Update plot_subgraphs.py typos fixed * Update plot_subgraphs.py added nodes to the plot of the edges removed that was commented out for whatever reason * Update plot_subgraphs.py revert the latest commit - the line was commented out for a reason - it's broken * Update plot_subgraphs.py fixed node color issue * Update plot_subgraphs.py format fix * Update plot_subgraphs.py forgot to draw the nodes... now fixed * Fix sphinx warnings about heading length. * Update examples/algorithms/plot_subgraphs.py * Update examples/algorithms/plot_subgraphs.py Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> Co-authored-by: Dan Schult <dschult@colgate.edu> * Add traveling salesman problem to example gallery (#4874) Adds an example of the using Christofides to solve the TSP problem to the example galery. Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> * Fixed inconsistent documentation for nbunch parameter in DiGraph.edges() (#5037) * Fixed inconsistent documentation for nbunch parameter in DiGraph.edges() * Resolved Requested Changes * Revert changes to degree docstrings. * Update comments in example. * Apply wording to edges method in all graph classes. Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> * Compatibility updates from testing with numpy/scipy/pytest rc's (#5226) * Rm deprecated scipy subpkg access. * Use recwarn fixture in place of deprecated pytest pattern. * Rm unnecessary try/except from tests. * Replace internal `close` fn with `math.isclose`. (#5224) * Replace internal close fn with math.isclose. * Fix lines in docstring examples. * Fix Python 3.10 deprecation warning w/ int div. (#5231) * Touchups and suggestions for subgraph gallery example (#5225) * Simplify construction of G with edges rm'd * Rm unused graph attribute. * Shorten categorization by node type. * Simplify node coloring. * Simplify isomorphism check. * Rm unit test. * Rm redundant plotting of each subgraph. * Use new package name (#5234) * Allowing None edges in weight function of bidirectional Dijkstra (#5232) * added following feature also to bidirectional dijkstra: The weight function can be used to hide edges by returning None. * changed syntax for better readability and code duplicate avoidance Co-authored-by: Hohmann, Nikolas <nikolas.hohmann@tu-darmstadt.de> * Add an FAQ about assigning issues. (#5182) * Add FAQ about assigning issues. * Add note about linking issues from new PRs. * Update dev deps (#5243) * Update minor doc issues with tex notation (#5244) * Add FutureWarnings to fns that return sparse matrices - biadjacency_matrix. - bethe_hessian_matrix. - incidence_matrix. - laplacian functions. - modularity_matrix functions. - adjacency_matrix. * Add to_scipy_sparse_array and use it everywhere. Add a new conversion function to preserve array semantics internally while not altering behavior for users. Also adds FutureWarning to to_scipy_sparse_matrix. * Add from_scipy_sparse_array. Supercedes from_scipy_sparse_matrix. * Handle deprecations in separate PR. * Fix docstring examples. Co-authored-by: Mridul Seth <mail@mriduls.com> Co-authored-by: Jarrod Millman <jarrod.millman@gmail.com> Co-authored-by: Andrew Knyazev <andrew.knyazev@ucdenver.edu> Co-authored-by: Dan Schult <dschult@colgate.edu> Co-authored-by: eskountis <56514439+eskountis@users.noreply.github.com> Co-authored-by: Anutosh Bhat <87052487+anutosh491@users.noreply.github.com> Co-authored-by: NikHoh <nikhoh@web.de> Co-authored-by: Hohmann, Nikolas <nikolas.hohmann@tu-darmstadt.de> Co-authored-by: Sultan Orazbayev <contact@econpoint.com> Co-authored-by: Mridul Seth <mail@mriduls.com>
* Rm internal laplacian in favor of laplacian_matrix. (#5196)Ross Barnowski2021-12-093-26/+6
|
* used queue instead of ordinary list (#5217)Ryuki2021-12-091-2/+3
| | | | | * used queue instead of ordinary list * use deque instead of queue
* Add Mypy type checking infrastructure (#5127)Ross Barnowski2021-11-171-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Add minimal mypy configuration file. * Add mypy workflow to GH. * Properly import sentinels from traversal.edgedfs. * mypy doesn't like variables named \"e\". * Rm annotations from single function. * Fix name collisions in test suite. Make sure all tests have unique names. * Rm unused random seed in test setup. * Rm redundant __all__ specification. * Silence mypy error from sum(). Mypy bug? * Fix tsp test instantiation nit. * \"type: ignore\" to suppress conditional fn sigature errors. * Remaining \"type: ignore\" to appease mypy. * Configure mypy to ignore inheritance issues. * Update exclude conf for CI. - Add yaml - Reformat regex containing reportviews * Rm partial annotations from lukes.py. Fixes mypy errors due to unannotated code. * Reorg defaultdict to reduce type: ignore cruft. * Homogenize signatures for fns defined in conditionals. * err as varname only in exception catching. * Fix name collision in Bellman-Ford test suite.
* Use math.hypot (#5145)Jarrod Millman2021-10-242-5/+4
|
* Drop Py37 (#5143)Jarrod Millman2021-10-231-1/+1
| | | | | | | | | | | | | | | | | | | * Drop Py37 * XML serialization issue * Use math.comb Co-authored-by: Simone Gasperini <simone.gasperini2@studio.unibo.it> * Run pyupgrade --py38-plus * Run black * More documentation * Deprecate euclidean Co-authored-by: Simone Gasperini <simone.gasperini2@studio.unibo.it>
* Change exception varname e to err (#5130)Dan Schult2021-10-151-4/+4
| | | | A more descriptive variable name for exceptions. This reduces local var naming conflicts when \`e\` is used e.g. to represent edges as a loop variable.
* Fix small typo in `trophic_levels` documentation (#5087)Will Badart2021-09-161-1/+1
| | | In return value description: "vale" -> "value"
* Add multigraph betweenness (#4976)pinselimo2021-08-313-4/+166
| | | | | | | | | | | | | | | * Betweenness: Use lowest weight of parallel edges * Betweenness: Add edge keys for edge betweenness centrality * betweenness: Test multigraph edge betweenness centrality * betweenness: Add missing test docstrings * betweenness: Test distinct weighted shortest paths * betweenness: Create dict with edge keys for multigraphs * betweenness: Fix reference in docstring for weight
* Page number for Katz centrality reference (#4932)Chris McBride2021-06-261-1/+1
|
* DOC: Fix links, use DOI links, wayback machine where required (#4868)Mridul Seth2021-06-089-17/+17
| | | | | | | | | | | * Fix links, use DOI links, wayback machine where required * Add nx-guides to intersphinx mapping. * Replace external mpl link w/ intersphinx. * Update mpl intersphinx mapping. Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
* Add dtype argument to adjacency_matrix (#4850)Jarrod Millman2021-05-271-1/+1
| | | and deprecate adj_matrix
* Remove unused `normalized` parameter from ↵Dan Schult2021-05-272-15/+24
| | | | | | | | | communicability_betweenness_centrality (#4843) * Remove unued `normalized` parameter from communicability_betweenness_centrality * dd API change to release_dev.rst * add tests for small graphs
* Use pytest.approx (#4827)Jarrod Millman2021-05-2116-215/+204
| | | | | * Use pytest.approx * Deprecate almost_equal
* Update black (#4814)Jarrod Millman2021-05-183-3/+3
|
* Remove instances of random.sample from sets (deprecated in Python 3.9) (#4602)Ross Barnowski2021-03-251-1/+1
| | | | | | | | | | | | | | | * Fix random.sample warnings in maxcut tests. * Fix random.sample warnings in betweenness. * Add sorted to sampling in triads + tests. * Add sorted to random_uniform_k_out_graph gen. * add sorted to random.sample in internet_as_graphs. * No sorted on nodes of graphs in general. * No sorted in random_uniform graph generator.
* Fix link for Katz centrality definition (#4655)Ludovic Stephan2021-03-051-2/+2
| | | Co-authored-by: Ludovic Stephan <ludovic.stephan@ens.fr>
* adding weight description to centrality metrices (#4610)guy rozenberg2021-02-1710-1/+30
| | | | | Fixes #3921 * weight description