Skip to main content

A python package containing SPHERA algorithm for efficient Rainbow Clique detection.

Project description

SPHERA

python license

SPHERA (Search Space Limitation Efficient Rainbow Clique Algorithm) is an efficient algorithm to find rainbow cliques using a combination of greedy growth, backtracking, and an efficient minimization of the search space.

Table of Contents

Installation

Use the package manager pip to install sphera.

pip install sphera

Quick tour

To immediately use our package, you only need to run a single function.
For analysis on real-world data, first you have to prepare a csv or txt file which contains the edges of the required graph.

Real-world data (non-colored graph)

The file containing the list of edges should look like this:

FirstID, SecondID
0	1
1	0
1	2
1	3
1	4
1	5
1	6
1	7
1	8
1	9
1	10
1	11
  • FirstID: ID of first vertex in the edge.
  • SecondID: ID of second vertex in the edge.

A few notes:

  • The file is required to have no header.
  • Between vertices could be tab or comma.
  • The input type in each tab should be an integer.

After preparing the files you can run SPHERA throw the command line:

python -m sphera.find_rainbow_clique --graph_type real --edges_file file1 --nodes_per_color 1000 --heuristic True --gate True 

Or use the functions in the package:

from sphera import find_rainbow_clique, process_graph
  • For creating the graph:
graph, node_to_label, label_to_node = process_graph.get_graph_with_properties(graph_type="real",
                                                                              edges=edges_file,
                                                                              colors=nodes_per_color)
  • Then you can run the SPHERA algorithm:
rainbow_clique, _ = find_rainbow_clique.rc_detection(graph,
                                                     node_to_label,
                                                     label_to_node, 
                                                     heuristic, 
                                                     gate)

Where:

  • graph_type: real (for the option of real graphs).
  • edges_file: A path to a csv or txt file with columns: 1) id of first vertex (integer). 2) id of second vertex. Assuming columns are separated with , or tab and no whitespaces in the csv file.
  • nodes_per_color: (optional, default is the average degree) specify the number of vertices in each color (integer).
  • heuristic: True if you want SPHERA to use heuristics, False otherwise.
  • gate: True if you want SPHERA to check the neighbors of clique at each stage, False otherwise.

Returns: the vertices in the maximum rainbow clique.

Real-world data (colored graph)

For colored graphs, 2 files are required. The first file contains the edges as before, the second contains the labels of the vertices. The file containing the labels of vertices should look like this:

VertexID, Label
1,1
2,2
3,1
4,2
5,2
6,2
7,2
8,2
9,2
10,2
  • VertexID: ID of the vertex.
  • Label: label of the vertex.

A few notes:

  • The file is required to have no header.
  • Between the vertex and label could be tab or comma.
  • The input type in each tab should be an integer.

After preparing the files you can run SPHERA throw the command line:

python -m sphera.find_rainbow_clique --graph_type real --edges_file file1 --labels_file file2 --heuristic True --gate True 

Or use the functions in the package:

from sphera import find_rainbow_clique, process_graph
  • For creating the graph:
graph, node_to_label, label_to_node = process_graph.get_graph_with_properties(graph_type="real_colored",
                                                                              edges=edges_file,
                                                                              colors=labels_file)
  • Then you can run the SPHERA algorithm:
rainbow_clique, _ = find_rainbow_clique.rc_detection(graph,
                                                     node_to_label,
                                                     label_to_node, 
                                                     heuristic, 
                                                     gate)

Where:

  • graph_type: real (for the option of real graphs).
  • edges_file: A path to a csv or txt file with columns: 1) id of first vertex (integer). 2) id of second vertex. Assuming columns are separated with , or tab and no whitespaces in the csv file.
  • labels_file: A path to a csv or txt file with columns: 1) id of vertex (integer). 2) label of the vertex (integer). Assuming columns are separated with , or tab and no whitespaces in the csv file.
  • heuristic: True if you want SPHERA to use heuristics, False otherwise.
  • gate: True if you want SPHERA to check the neighbors of clique at each stage, False otherwise.

Returns: the vertices in the maximum rainbow clique.

G(n, p) graphs

Run SPHERA throw the command line:

python -m sphera.find_rainbow_clique --graph_type gnp --k 9 --p 0.3 --nodes_per_color 1000 --heuristic True --gate True 

Or use the functions in the package:

from sphera import find_rainbow_clique, process_graph
  • For creating the graph:
graph, node_to_label, label_to_node = process_graph.get_graph_with_properties(graph_type="gnp",
                                                                              edges=(k, p),
                                                                              colors=nodes_per_color)
  • Then you can run the SPHERA algorithm:
rainbow_clique, _ = find_rainbow_clique.rc_detection(graph,
                                                     node_to_label,
                                                     label_to_node, 
                                                     heuristic, 
                                                     gate)

Where:

  • graph_type: gnp (for the option of G(n,p) graphs).
  • k: The number of colors in the graph.
  • p: The probability of existence of an edge in the graph.
  • nodes_per_color: Specify the number of vertices in each color (integer).
  • heuristic: True if you want SPHERA to use heuristics, False otherwise.
  • gate: True if you want SPHERA to check the neighbors of clique at each stage, False otherwise.

Returns: the vertices in the maximum rainbow clique.

You can find the scripts and the simulated data in:

├───SPHERA
│   ├───plots
│      └───greedy_percentage.py
│      └───natual_threshold.py
│      └───prob_next_vertex.py
│      └───real_graph_plots.py
│   ├───real_graphs
│      └───all_real_graphs_files    └───find_rainbow_clique.py
│   └───process_graph.py

MIT License

Copyright (c) 2024 Devora Siminovsky

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sphera-0.1.1.tar.gz (13.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sphera-0.1.1-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file sphera-0.1.1.tar.gz.

File metadata

  • Download URL: sphera-0.1.1.tar.gz
  • Upload date:
  • Size: 13.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.13

File hashes

Hashes for sphera-0.1.1.tar.gz
Algorithm Hash digest
SHA256 4f816209f98cdaf904a01e7190d7b38fd566cc66d7b02e9e4ec7cf90b9064ecf
MD5 ec8a012a4c2d1189e3b2b10bb8bce290
BLAKE2b-256 18e851195e41db9c8ddfb33dcb6f9e74053fe960413387ed60c3be1fb7e7ab19

See more details on using hashes here.

File details

Details for the file sphera-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: sphera-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 13.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.13

File hashes

Hashes for sphera-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4a4e6f0b19debc2a2d10aeebc639277878903b4ce51b50f76775410eef26f8a0
MD5 0663c6ce6e9b4387e93d91ee10df80f4
BLAKE2b-256 502e25f2c64074a6faba344676e9f14776a2f5ce08dd2422962a5522d6cb34f1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page