Skip to content

networkx.algorithms has no attribute graph_number_of_cliques #3

Description

@strikeoncmputrz

Hello Daniel,

I'm really enjoying your book! Got it from No Starch a while ago and finally have made the time to dive in.

I've encountered an error in Chapter 3 while trying to count the total cliques in the graph. I am running NetworkX version 3.4.1. nx.algorithms.graph_number_of_cliques doesn't appear to be a valid function. Traceback below:

--------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[7], [line 2](vscode-notebook-cell:?execution_count=7&line=2)
      [1](vscode-notebook-cell:?execution_count=7&line=1) clq = nx.algorithms.number_of_cliques(clique_graph)
----> [2](vscode-notebook-cell:?execution_count=7&line=2) tot = nx.algorithms.graph_number_of_cliques(clique_graph)
      [3](vscode-notebook-cell:?execution_count=7&line=3) for m in clq:
      [4](vscode-notebook-cell:?execution_count=7&line=4)     print(m, (clq[m]/tot))

AttributeError: module 'networkx.algorithms' has no attribute 'graph_number_of_cliques'

I think I have a valid work-around but was hoping you could confirm.

clq = nx.algorithms.number_of_cliques(clique_graph)
tot = len(list(nx.algorithms.find_cliques(clique_graph)))
for m in clq:
    print(m, (clq[m]/tot))

find_cliques returns a generator of all maximal cliques. I just return the length of the iterator to get the number of maximal cliques. This seems like it's not a valid solution although it does obtain the expected 3 cliques and produce the expected values for facilitators.

Do you have any recommendations for improving this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions