cdlib icon indicating copy to clipboard operation
cdlib copied to clipboard

NodeClustering methods are failing for "r_spectral_clustering"

Open lior0110 opened this issue 5 months ago • 2 comments

Describe the bug NodeClustering methods are failing for "r_spectral_clustering"

To Reproduce Steps to reproduce the behavior:

  • CDlib version : cdlib 0.4.0
  • Operating System : windows 11
  • Python version : 3.11.11
  • Version(s) of CDlib required libraries

from cdlib import algorithms import networkx as nx G = nx.karate_club_graph() coms = algorithms.r_spectral_clustering(G, n_clusters=2, method="regularized", percentile=20).size()

Expected behavior A clear and concise description of what you expected to happen. before fix: FitnessResult(min=0, max=0, score=0.0, std=0.0) when working: FitnessResult(min=9, max=22, score=14.9, std=4.109744517606903)

Screenshots If applicable, add screenshots to help explain your problem. before fix:

Image

after fix:

Image

Additional context needs to change "g = convert_graph_formats(g_original, nx.Graph)" to "g = convert_graph_formats(g_original.copy(), nx.Graph)" in source code crisp_partition.py to work

lior0110 avatar Aug 13 '25 09:08 lior0110

Hi, thanks for opening the issue. If you have time, please consider opening a PR with the fix.

GiulioRossetti avatar Aug 14 '25 11:08 GiulioRossetti

I did the change one layer deeper in convert_graph_formats to return a copy (not a pointer), and sent a PR of the change. It works in my case and I think this change will be a better fix.

lior0110 avatar Aug 17 '25 11:08 lior0110