SGTL - Spectral Graph Theory Library

Overview

SGTL - Spectral Graph Theory Library

Documentation Status

SGTL is a python library of spectral graph theory methods. The library is still very new and so there are many features and algorithms missing.

You can install the library with pip install sgtl.

Features

  • Lightweight and flexible graph object which can be extended as needed.
  • Graph matrices including the Laplacian and Normalised Laplacian
  • Spectral clustering method
  • Generate graphs from the stochastic block model

Documentation

The full documentation is available here.

Contributing

Please feel free to contribute to this project by opening issues, reporting bugs, and submitting pull requests.

The library is currently maintained by Peter Macgregor ([email protected]) and you are welcome to get in touch with any questions.

Comments
  • Graph methods should give meaningful errors when vertices out of range

    Graph methods should give meaningful errors when vertices out of range

    Currently, if you ask for the volume of a set of vertices, but the set includes indices which are greater than the number of vertices in the graph, the code throws an IndexError from somewhere inside the graph code.

    This is not totally unreasonable, but it would help debugging this kind of error if it gave a clear error message. Something like: "Vertex set includes indices larger than number of vertices".

    enhancement good first issue 
    opened by pmacg 6
  • Added graph._check_vert_num method and updated class tests accordingly

    Added graph._check_vert_num method and updated class tests accordingly

    @pmacg I've fixed all of your comments. Unfortunately I made a little bit of a mess of my local repository so I've created a new pull request. Hope this isn't too much trouble for you. If you have any more comments please let me know

    opened by yonMaor 5
  • Add tools for visualising the spectrum of a graph.

    Add tools for visualising the spectrum of a graph.

    There should be tools available to visualise the spectrum of a graph - both the eigenvalues themselves and the spectral embedding of the eigenvectors.

    enhancement 
    opened by pmacg 3
  • Construct graph as kronecker product of two existing graphs

    Construct graph as kronecker product of two existing graphs

    It would be useful to construct a graph from the kronecker product of two existing graphs. That is, the adjacency matrix of the new graph is the kronecker product of the adjacency matrices of the input graphs.

    enhancement 
    opened by pmacg 1
  • The weight function on the Graph object should return a float

    The weight function on the Graph object should return a float

    At the moment, the weight function on sgtl.graph.Graph() rounds the weight to the nearest integer and returns an int.

    This should return a float to allow fractionally weighted edges.

    bug good first issue 
    opened by pmacg 1
  • Graph matrices are not symmetric for an undirected graph

    Graph matrices are not symmetric for an undirected graph

    For a large undirected graph generated from the stochastic block model, the generated graph matrices are not always symmetric. For example:

    >>> big_graph = sgtl.random.ssbm(1000, 5, 0.8, 0.2)
    >>> lap_mat = big_graph.normalised_laplacian_matrix()
    >>> lap_mat_dense = lap_mat.toarray()
    >>> np.allclose(lap_mat_dense, lap_mat_dense.T)
    False
    

    I haven't debugged this yet, but we should certainly be able to assume that the graph matrices are symmetric for an undirected graph.

    bug 
    opened by pmacg 1
  • The num_edges member of the Graph object is incorrect when graph is weighted

    The num_edges member of the Graph object is incorrect when graph is weighted

    Given a weighted graph object, the graph.num_edges gives half of the total volume of the graph, rather than the actual number of weighted edges.

    This should be replaced with two methods on the object, a num_edges method which gives the number of non-zero elements of the adjacency matrix (corrected for the symmetry) and a graph_volume method which returns the total weight of all the edges in the graph.

    bug good first issue 
    opened by pmacg 1
  • Combine graphs by adding their edges

    Combine graphs by adding their edges

    Add a method to add two graphs together, equivalent to adding their adjacency matrices.

    If the graphs do not have the same number of vertices, then this method should throw a suitable exception.

    Consider overloading the '+' operator so that you can write graph3 = graph1 + graph2.

    enhancement good first issue 
    opened by pmacg 0
  • Add spectrum method to graph

    Add spectrum method to graph

    Add the methods

    • adjacency_spectrum()
    • laplacian_spectrum()
    • normalised_laplacian_spectrum()

    To the graph object for returning the eigenvalues of the corresponding graph matrices.

    enhancement 
    opened by pmacg 0
  • Typo in return value of bipartiteness method

    Typo in return value of bipartiteness method

    The return value of the Graph.bipartiteness() method should display a beta in math mode in the rendered documentation. See the return value of the conductance method for how to do this.

    documentation good first issue 
    opened by pmacg 0
  • Update to work with sparse arrays

    Update to work with sparse arrays

    The scipy sparse linear algebra library has recently introduced sparse arrays rather than matrices and is encouraging their use over the matrix types.

    This enhancement covers updating SGTL to allow use of either the sparse array or sparse matrix types.

    enhancement 
    opened by pmacg 0
  • Look into behaviour of methods on graphs with negative weights

    Look into behaviour of methods on graphs with negative weights

    It may be sometimes useful to use graphs with negative weights. The library is not currently designed with this in mind, but many things might 'just work'. This issue covers investigating formally the behaviour of the library on graphs with negative weights.

    bug documentation enhancement 
    opened by pmacg 0
  • Add weighted graph example to the Getting Started guide in the documentation

    Add weighted graph example to the Getting Started guide in the documentation

    The 'Getting Started' page of the documentation currently only gives examples of unweighted graphs. It would be nice to also include a weighted example, or at least mention that this is possible.

    documentation enhancement 
    opened by pmacg 0
  • Generating SBM with different cluster sizes can fail

    Generating SBM with different cluster sizes can fail

    The following code for generating a graph from the stochastic block model fails with out-of-bounds errors.

    import sgtl.random
    import numpy as np
    
    
    def main():
        cluster_sizes = [100, 50, 20, 20, 20]
        p = 0.8
        prob_mat_q = np.asarray([[p,   0.2, 0.5, 0.1, 0.1],
                                 [0.2, p,   0.1, 0.6, 0.2],
                                 [0.5, 0.1, p,   0.2, 0.1],
                                 [0.1, 0.6, 0.2, p,   0.5],
                                 [0.1, 0.2, 0.1, 0.5, p]])
        graph = sgtl.random.sbm(cluster_sizes, prob_mat_q)
    
    
    if __name__ == '__main__':
        main()
    
    Traceback (most recent call last):
      File ".../main.py", line 17, in <module>
        main()
      File ".../main.py", line 13, in main
        graph = sgtl.random.sbm(cluster_sizes, prob_mat_q)
      File ".../venv/lib/python3.8/site-packages/sgtl/random.py", line 179, in sbm
        adj_mat[vertex_1, vertex_2] = 1
      File ".../venv/lib/python3.8/site-packages/scipy/sparse/_lil.py", line 330, in __setitem__
        return self._set_intXint(key[0], key[1], x)
      File ".../venv/lib/python3.8/site-packages/scipy/sparse/_lil.py", line 299, in _set_intXint
        _csparsetools.lil_insert(self.shape[0], self.shape[1], self.rows,
      File "_csparsetools.pyx", line 61, in scipy.sparse._csparsetools.lil_insert
      File "_csparsetools.pyx", line 87, in scipy.sparse._csparsetools.lil_insert
    IndexError: column index (240) out of bounds
    
    bug 
    opened by pmacg 0
Releases(v0.4.6)
  • v0.4.6(Jan 11, 2022)

    What's Changed

    • Single efficiency update - computing weight between vertex sets by @pmacg in https://github.com/pmacg/py-sgtl/pull/47

    Full Changelog: https://github.com/pmacg/py-sgtl/compare/v0.4.5...v0.4.6

    Source code(tar.gz)
    Source code(zip)
  • v0.4.5(Jan 9, 2022)

    What's Changed

    • Issue 32 - add tensor product method by @pmacg in https://github.com/pmacg/py-sgtl/pull/43
    • Issue #27 - add option to plot eigenvalues in spectrum methods by @pmacg in https://github.com/pmacg/py-sgtl/pull/44
    • Overload plus operator to add graphs together by @pmacg in https://github.com/pmacg/py-sgtl/pull/45

    Full Changelog: https://github.com/pmacg/py-sgtl/compare/v0.4.4...v0.4.5

    Source code(tar.gz)
    Source code(zip)
  • v0.4.4(Jan 7, 2022)

    What's Changed

    • Issue #41 - Add gaussian kernel graph constructor. by @pmacg in https://github.com/pmacg/py-sgtl/pull/42

    Full Changelog: https://github.com/pmacg/py-sgtl/compare/v0.4.3...v0.4.4

    Source code(tar.gz)
    Source code(zip)
  • v0.4.3(Jan 6, 2022)

    What's Changed

    • Issue #39 - KNN construction with sparse data matrix by @pmacg in https://github.com/pmacg/py-sgtl/pull/40

    Full Changelog: https://github.com/pmacg/py-sgtl/compare/v0.4.2...v0.4.3

    Source code(tar.gz)
    Source code(zip)
  • v0.4.2(Jan 6, 2022)

    What's Changed

    • Add methods for converting to and from edgelist files by @pmacg in https://github.com/pmacg/py-sgtl/pull/38

    Full Changelog: https://github.com/pmacg/py-sgtl/compare/v0.4.1...v0.4.2

    Source code(tar.gz)
    Source code(zip)
  • v0.4.1(Jan 5, 2022)

    What's Changed

    • Iss29 add spectrum methods by @pmacg in https://github.com/pmacg/py-sgtl/pull/34
    • Add method for constructing k-nearest neighbours graph by @pmacg in https://github.com/pmacg/py-sgtl/pull/36

    Full Changelog: https://github.com/pmacg/py-sgtl/compare/v0.4...v0.4.1

    Source code(tar.gz)
    Source code(zip)
  • v0.4(Dec 14, 2021)

    What's Changed

    • Add workflow by @pmacg in https://github.com/pmacg/py-sgtl/pull/7
    • Issue #3 - Fix the num_edges member on the graph object. by @pmacg in https://github.com/pmacg/py-sgtl/pull/11
    • Fix weight function when graph has floating point weights, or self-loops by @pmacg in https://github.com/pmacg/py-sgtl/pull/13
    • Added graph._check_vert_num method and updated class tests accordingly by @yonMaor in https://github.com/pmacg/py-sgtl/pull/12
    • Update bipartiteness documentation by @pmacg in https://github.com/pmacg/py-sgtl/pull/15
    • Add methods to convert to and from networkx graphs by @pmacg in https://github.com/pmacg/py-sgtl/pull/16
    • Return error when computing conductance of empty set by @pmacg in https://github.com/pmacg/py-sgtl/pull/17
    • Add the cheeger cut algorithms by @pmacg in https://github.com/pmacg/py-sgtl/pull/18

    New Contributors

    • @pmacg made their first contribution in https://github.com/pmacg/py-sgtl/pull/7
    • @yonMaor made their first contribution in https://github.com/pmacg/py-sgtl/pull/12

    Full Changelog: https://github.com/pmacg/py-sgtl/compare/v0.3.3...v0.4

    Source code(tar.gz)
    Source code(zip)
Owner
Peter Macgregor
Computer Science PhD Student, University of Edinburgh.
Peter Macgregor
imgAnalyser - Un script pour obtenir la liste des pixels d'une image correspondant à plusieurs couleurs

imgAnalyser - Un script pour obtenir la liste des pixels d'une image correspondant à plusieurs couleurs Ce script à pour but, à partir d'une image, de

Théo Migeat 1 Nov 15, 2021
Photini - A free, easy to use, digital photograph metadata (Exif, IPTC, XMP) editing application for Linux, Windows and MacOS.

A free, easy to use, digital photograph metadata (Exif, IPTC, XMP) editing application for Linux, Windows and MacOS. "Metadata" is said to mea

Jim Easterbrook 120 Dec 20, 2022
sK1 2.0 cross-platform vector graphics editor

sK1 2.0 sK1 2.0 is a cross-platform open source vector graphics editor similar to CorelDRAW, Adobe Illustrator, or Freehand. sK1 is oriented for prepr

sK1 Project 238 Dec 04, 2022
Archive of the image generator stuff from my API

alex_api_archive Archive of the image generator stuff from my API FAQ Q: Why? A: Because I am removing these components from the API Q: How do I run i

AlexFlipnote 26 Nov 17, 2022
Image manipulation package used for EpicBot.

Image manipulation package used for EpicBot.

Nirlep_5252_ 7 May 26, 2022
Raven is a tool written in Python3 allowing you to generate an unique image with some text.

🐦 Raven is a tool written in Python3 allowing you to generate an unique image with some text. It does it by searching the text on Google, do

Billy 39 Dec 20, 2022
Anaglyph 3D Converter - A python script that adds a 3D anaglyph style effect to an image using the Pillow image processing package.

Anaglyph 3D Converter - A python script that adds a 3D anaglyph style effect to an image using the Pillow image processing package.

Kizdude 2 Jan 22, 2022
Generative Art Synthesizer - a python program that generates python programs that generates generative art

GAS - Generative Art Synthesizer Generative Art Synthesizer - a python program that generates python programs that generates generative art. Examples

Alexey Borsky 43 Dec 03, 2022
View images in the terminal using ansi escape codes and python

terminal-photo-viewer view images in the terminal using ansi escape codes and python !! Only tested on Ubuntu 20.04.3 LTS with python version 3.8.10 D

1 Nov 30, 2021
Nudity detection with Python

nude.py About Nudity detection with Python. Port of nude.js to Python. Installation from pip: $ pip install --upgrade nudepy from easy_install: $ eas

Hideo Hattori 881 Jan 06, 2023
Transfers a image file(.png) to an Excel file(.xlsx)

Transfers a image file(.png) to an Excel file(.xlsx)

Junu Kwon 7 Feb 11, 2022
Forza painter app with python

forza-painter Discord: A-Dawg#0001 (AE) Supports: Forza Horizon 5 Offically (OTHER v1.405.2.0, MS STORE v3.414.967.0, STEAM v1.414.967.0) Unofficially

320 Dec 31, 2022
An add to make adding screenshots and copied images to the scene easy

Blender Clipboard to Scene It doesn't work with version 2.93 and higher (I tested it on 2.91 and 2.83) There is an issue with importing the Pillow mod

Mohammad Mehdi Afkhami 3 Dec 29, 2021
A python based library to help you create unique generative images based on Rarity for your next NFT Project

Generative-NFT Generate Unique Images based on Rarity A python based library to help you create unique generative images based on Rarity for your next

Kartikay Bhutani 8 Sep 21, 2022
Python QR Code image generator

Pure python QR Code generator Generate QR codes. For a standard install (which will include pillow for generating images), run: pip install qrcode[pil

Lincoln Loop 3.5k Dec 31, 2022
A suite of useful tools based on 3D interactivity in napari

napari-threedee A suite of useful tools based on 3D interactivity in napari This napari plugin was generated with Cookiecutter using @napari's cookiec

11 Dec 14, 2022
Python Interface of P3D

pyp3d 介绍: pyp3d是一个可在python上使用的工具包,它提供了一种可使用python脚本驱动创建模型的方法,为三维建模提供了全新的思路。 pyp3d中定义了一系列建模相关的必要的数据类型,例如球体、圆锥台、四棱锥台、 拉伸体、圆角管等几何体,pyp3d还提供了许多函数来实现放置集合体、

20 Sep 07, 2022
Generate different types of random avatars.

avatar-generator Generate different types of random avatars. Requirements Python3 pytorch=1.6 cv2=3.4 tqdm 1. Github-like avatars python generate_gi

Ming 11 Apr 02, 2022
This Web App lets you convert your Normal Image to a SKETCHED one within a minute

This Web App lets you convert your Normal Image to a SKETCHED one within a minute

Avinash M 25 Nov 10, 2022
Collection of SVG diagrams about how UTF-8 works

Diagrams Repository of diagrams made for articles on my blog. All diagrams are created using diagrams.net. UTF-8 Licenses Copyright 2022 Seth Michael

Seth Michael Larson 24 Aug 13, 2022