GiulioRossetti / cdlib

Community Discovery Library
http://cdlib.readthedocs.io
BSD 2-Clause "Simplified" License
367 stars 71 forks source link

Make use of "weights" parameter while using ensemble.pool #210

Closed udiallo closed 2 years ago

udiallo commented 2 years ago

I want to compare different cd algorithms using the ensemble.pool function. However, as configuration parameter there are only the ensemble.Parameter and ensemble.BoolParameter available.

Is there a way to include the "weights" parameter of algorithms such as leiden? Normally it looks like that:

`partition = algorithms.leiden(G, weights="weight")`

It seems that a string parameter cannot be used when using ensemble.pool.

Thanks in advance.

github-actions[bot] commented 2 years ago

Thanks for submitting your first issue!

GiulioRossetti commented 2 years ago

Hi, thanks for opening this issue. I'll work on it next week, it should be easy to implement.

GiulioRossetti commented 2 years ago

Hi, as promised I updated the implementation to support categorical parameters. Here's a minimal code example:

weight = ensemble.CategoricalParameter(name="weight", values=['weight'])
communities = ensemble.grid_execution(graph=g, method=algorithms.louvain, parameters=[weight])

As you can see - to make the syntax general - I opted for an iterable containing multiple values to instantiate the specific parameter.

The update has been pushed on the main branch of the cdlib repository: it will be officially included in the forthcoming release of the library.

Best, Giulio