Skip to content

Use scipy to compute eigenvalues - #4847

Merged
jarrodmillman merged 5 commits into
networkx:mainfrom
jarrodmillman:hits
May 31, 2021
Merged

jarrodmillman merged 5 commits into
networkx:mainfrom
jarrodmillman:hits

Conversation

@jarrodmillman

@jarrodmillman jarrodmillman commented May 27, 2021 •

Copy link
Copy Markdown
Member

hits

@jarrodmillman

jarrodmillman commented May 28, 2021 •

Copy link
Copy Markdown
Member Author

The SVD version is fastest.
finalhits

import timeit
import numpy as np
import matplotlib.pyplot as plt
import networkx as nx

samples = 60
num_nodes = 10 * np.arange(samples)


def benchmarkit(G, func, number=20):
    return timeit.timeit(
        f"nx.{func}(G)",
        globals={"nx": nx, "G": G},
        number=number,
    )


def plot_benchmarks(func, num_nodes, samples, seed=20160):
    time_sparse = np.zeros(samples)
    time_dense = np.zeros(samples)
    time_complete = np.zeros(samples)
    for i, n in enumerate(num_nodes):
        G_sparse = nx.gnp_random_graph(n, 0.1, seed=seed)
        G_dense = nx.gnp_random_graph(n, 0.9, seed=seed)
        G_complete = nx.complete_graph(n)
        time_sparse[i] = benchmarkit(G_sparse, func)
        time_dense[i] = benchmarkit(G_dense, func)
        time_complete[i] = benchmarkit(G_complete, func)
    return time_sparse, time_dense, time_complete


dict_of_funcs = {"hits": ["hits_scipy", "hits_scipy3"]}

for name, funcs in dict_of_funcs.items():
    fig, axs = plt.subplots(1, len(funcs), sharey=True)
    for i, func in enumerate(funcs):
        tsparse, tdense, tcomplete = plot_benchmarks(func, num_nodes, samples)
        axs[i].plot(num_nodes, tsparse, label="sparse")
        axs[i].plot(num_nodes, tdense, label="dense")
        axs[i].plot(num_nodes, tcomplete, label="complete")
        axs[i].set_title(func)
        axs[i].set_xlabel("Number of Nodes")
        axs[i].set_ylabel("Time")
        axs[i].legend()

    plt.savefig(name + ".png", dpi=600)

@jarrodmillman
jarrodmillman marked this pull request as ready for review May 30, 2021 22:17

@dschult dschult left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! :}

@jarrodmillman
jarrodmillman merged commit d989f68 into networkx:main May 31, 2021
@jarrodmillman
jarrodmillman deleted the hits branch May 31, 2021 00:55
MridulS pushed a commit to MridulS/networkx that referenced this pull request Feb 4, 2023
* Use scipy to compute eigenvalues

* Compute svd instead

* Clean up

* Document changes

* Update test_hits to look at convergence failing

Co-authored-by: Dan Schult <[email protected]>
cvanelteren pushed a commit to cvanelteren/networkx that referenced this pull request Apr 22, 2024
* Use scipy to compute eigenvalues

* Compute svd instead

* Clean up

* Document changes

* Update test_hits to look at convergence failing

Co-authored-by: Dan Schult <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants