sgtsnepi 0.5.0__cp313-cp313-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
sgtsnepi/__init__.py ADDED
@@ -0,0 +1,2 @@
1
+ from . import sgtsne
2
+ from .sgtsne import sgtsnepi
Binary file
Binary file
sgtsnepi/sgtsne.py ADDED
@@ -0,0 +1,92 @@
1
+ from math import inf
2
+
3
+ import numpy
4
+ from scipy.sparse import csc_matrix
5
+
6
+ from nextprod import nextprod
7
+
8
+ from . import _sgtsnepi
9
+
10
+ def sgtsnepi(
11
+ input_graph, y0=None, d=2, max_iter=1000, early_exag=250,
12
+ lambda_par=1, h=1.0, bb=-1.0, eta=200.0, run_exact=False,
13
+ fftw_single=False, alpha=12, drop_leaf=False,
14
+ grid_threshold=None, silent=False
15
+ ):
16
+
17
+ # Import input_graph as CSC matrix
18
+ try:
19
+ input_graph = csc_matrix(input_graph)
20
+ except ValueError as e:
21
+ raise TypeError("input_graph must be an adjacency matrix") from e
22
+
23
+ if not input_graph.shape[0] == input_graph.shape[1]:
24
+ raise ValueError("input_graph must be square")
25
+
26
+ n = input_graph.shape[0]
27
+
28
+ # Eliminate self-loops for input_matrix
29
+ if any(input_graph.diagonal() != 0):
30
+ print("Warning: input_graph has self-loops; setting distances to 0")
31
+
32
+ input_graph.setdiag(numpy.zeros(n))
33
+ input_graph.eliminate_zeros()
34
+
35
+ nnz = input_graph.nnz
36
+
37
+ if input_graph.data.size > 0 and numpy.min(input_graph.data) < 0:
38
+ raise ValueError("Negative edge weights are not supported")
39
+
40
+ if y0 is not None:
41
+ try:
42
+ y0 = numpy.array(y0)
43
+ except Exception as e:
44
+ raise TypeError("y0 must be array-like or None.") from e
45
+
46
+ if y0.shape != (d, n):
47
+ raise ValueError("y0 must be of shape (d, n)")
48
+
49
+ y0 = numpy.transpose(y0)
50
+
51
+ # Setting parameters correctly
52
+ list_grid_sizes = [nextprod((2, 3, 5), x) for x in range(16, 512)]
53
+
54
+ if grid_threshold is None:
55
+ grid_threshold = 1e6 ** (1/d)
56
+
57
+ grid_threshold = int(grid_threshold)
58
+
59
+ bb = inf if run_exact else bb
60
+ bb = h * (n ** (1/d)) / 2 if bb <= 0 else bb
61
+
62
+ h = 1.0 if h == 0 else h
63
+ h = [max_iter + 1, h]
64
+
65
+ y = _sgtsnepi.sgtsnepi_c(
66
+ numpy.array(input_graph.indices, dtype=numpy.uint32),
67
+ numpy.array(input_graph.indptr, dtype=numpy.uint32),
68
+ numpy.array(input_graph.data, dtype=numpy.float64),
69
+ y0,
70
+ nnz,
71
+ d,
72
+ lambda_par,
73
+ max_iter,
74
+ early_exag,
75
+ alpha,
76
+ fftw_single,
77
+ numpy.array(h, dtype=numpy.float64),
78
+ bb,
79
+ eta,
80
+ numpy.array(list_grid_sizes, dtype=numpy.int32),
81
+ len(list_grid_sizes),
82
+ n,
83
+ drop_leaf,
84
+ run_exact,
85
+ grid_threshold,
86
+ silent
87
+ )
88
+
89
+ # permute y to (d, n)
90
+ y = numpy.transpose(y)
91
+
92
+ return y
@@ -0,0 +1,98 @@
1
+ /*!
2
+ \file sgtsne.hpp
3
+ \brief SG-t-SNE-Pi header with structure and function definitions.
4
+
5
+ The main procedure definition, responsible for parsing the data
6
+ and the parameters, preprocessing the input, running the
7
+ gradient descent iterations and returning.
8
+
9
+ \author Dimitris Floros
10
+ \date 2019-06-21
11
+ */
12
+
13
+
14
+ #ifndef SGTSNE_HPP
15
+ #define SGTSNE_HPP
16
+
17
+ #include "types.hpp"
18
+ #include <iostream> // NULL
19
+
20
+ //! List of SG-t-SNE-Pi parameters
21
+ /*!
22
+ A list of parameters available in SG-t-SNE-Pi, with default values
23
+ specified.
24
+ */
25
+ typedef struct {
26
+
27
+ int d = 2; //!< Number of embedding dimensions
28
+ double lambda = 1; //!< λ rescaling parameter
29
+ double alpha = 12; //!< Early exaggeration multiplier
30
+ int maxIter = 1000; //!< Maximum number of iterations
31
+ int earlyIter = 250; //!< Number of early exaggeration iterations
32
+ int n = 0; //!< Number of vertices
33
+ double *h = NULL; //!< Grid side length (accuracy control)
34
+ bool dropLeaf = false; //!< Drop edges originating from leaf nodes?
35
+ int np = 0; //!< Number of CILK workers (processes)
36
+ double bound_box = 1e64; //!< Bounding box (default infinite)
37
+ double eta = 200.0; //!< learning rate
38
+ bool run_exact = false; //!< exact qq
39
+ int fftw_single = 0; //!< run FFTW single precision? (default false)
40
+ } tsneparams;
41
+
42
+
43
+ //! Sparse matrix structure in CSC format
44
+ /*!
45
+ Custom structure to hold the elements of a CSC sparse matrix format.
46
+ */
47
+ typedef struct {
48
+
49
+ int m; //!< Number of rows
50
+ int n; //!< Number of columns
51
+ int nnz; //!< Number of nonzero elements
52
+
53
+ matidx * row; //!< Rows indices (NNZ length)
54
+ matidx * col; //!< Columns offset (N+1 length)
55
+ matval * val; //!< Values (NNZ length)
56
+
57
+ } sparse_matrix;
58
+
59
+ // include utility functions
60
+ #include "utils.hpp"
61
+
62
+
63
+ //! Embed the sparse stochastic graph P
64
+ /*!
65
+ Compute the embedding of the input stochastic graph P.
66
+ A list of parameters are defined in the tsneparams structure.
67
+
68
+
69
+ \return [d-by-N] The embedding coordinates
70
+ */
71
+ coord* sgtsne(sparse_matrix P, //!< The sparse stochastic graph P in CSC storage
72
+ tsneparams params, //!< A struct with the SG-t-SNE parameters
73
+ coord *y_in = nullptr, //!< [Optional] The embedding coordinates
74
+ double **timeInfo = nullptr //!< [Optional] Returns timing information
75
+ );
76
+
77
+
78
+ //! Perplexity equalization
79
+ /*!
80
+
81
+ The input as the kNN graph of a dataset, of size [(k+1)-by-N]. The
82
+ (k+1) input must contain the self-loop as the first element. Both
83
+ the indices and the distances are needed.
84
+
85
+
86
+ \return The CSC sparse column-stochastic all-kNN, after perplexity equalization.
87
+ */
88
+ extern "C" {
89
+ sparse_matrix perplexityEqualization( int *I, //!< [(k+1)-by-N] array with the neighbor IDs
90
+ double *D, //!< [(k+1)-by-N] array with the neighbor distances
91
+ int n, //!< [scalar] Number of data points N
92
+ int nn, //!< [scalar] Number of neighbors k
93
+ double u //!< [scalar] Perplexity u
94
+ );
95
+
96
+ }
97
+
98
+ #endif /* _SGTSNE_H_ */
@@ -0,0 +1,102 @@
1
+ Metadata-Version: 2.1
2
+ Name: sgtsnepi
3
+ Version: 0.5.0
4
+ Summary: SG-t-SNE-Π wrapper for Python
5
+ Author-Email: Alexandros Athanasiadis <athanasiadisalex2@gmail.com>
6
+ License: GPLv3
7
+ Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
8
+ Classifier: Programming Language :: C
9
+ Classifier: Programming Language :: C++
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.9
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Programming Language :: Python :: 3.14
17
+ Project-URL: Homepage, https://github.com/alex-unofficial/sgtsnepi-python
18
+ Requires-Dist: numpy>=1.19.5
19
+ Requires-Dist: scipy>=1.7.3
20
+ Requires-Dist: nextprod>=1.0
21
+ Provides-Extra: dev
22
+ Requires-Dist: matplotlib>=3.5; extra == "dev"
23
+ Requires-Dist: pylint>=2.17; extra == "dev"
24
+ Requires-Dist: flake8>=6.0; extra == "dev"
25
+ Description-Content-Type: text/markdown
26
+
27
+ # SG-t-SNE-Π wrapper for Python
28
+
29
+ This repository aims to provide a `Python` interface to
30
+ [SG-t-SNE-Π](http://t-sne-pi.cs.duke.edu), which is a high-performance
31
+ software for swift embedding of a large, sparse graph into
32
+ a d-dimensional space (d=1,2,3) on a shared-memory computer.
33
+
34
+ > :warning: **Warning!** This package is still a work in progress.
35
+
36
+ ## Installation
37
+
38
+ ### Prerequisites
39
+
40
+ `sgtsnepi` supports Linux, macOS, and Windows.
41
+
42
+ Installation requires `Python 3.9` or higher.
43
+
44
+ Wheels are not built for all architectures as of now.
45
+ If your architecture is not supported please open a relevant issue on the GitHub page.
46
+
47
+ ### Installing the Module
48
+
49
+ To install the package run
50
+ ```sh
51
+ pip install sgtsnepi
52
+ ```
53
+
54
+ Then in your Python code run the following to import the library:
55
+ ```python
56
+ import sgtsnepi
57
+
58
+ # [ ... ]
59
+
60
+ sgtsnepi.sgtsnepi(sparse_matrix, args)
61
+ ```
62
+
63
+ Or to import the `sgtsnepi` function directly:
64
+ ```python
65
+ from sgtsnepi import sgtsnepi
66
+
67
+ # [ ... ]
68
+
69
+ sgtsnepi(sparse_matrix, args)
70
+ ```
71
+
72
+ ## Running the Demo
73
+
74
+ To use the demo you should install [matplotlib](https://matplotlib.org/) by running
75
+ ```sh
76
+ pip install scipy matplotlib
77
+ ```
78
+
79
+ Then from the source directory run
80
+ ```
81
+ python tests/demo.py mm_file.mtx ndim
82
+ ```
83
+ where `mm_file.mtx` is a file containing the input matrix which is in the
84
+ [Matrix Market](https://math.nist.gov/MatrixMarket/index.html) file format,
85
+ and `ndim` is the number of embedding dimensions.
86
+
87
+ You can find some compressed `MatrixMarket` files in the `data/` subdirectory.
88
+
89
+ ## Citation
90
+
91
+ If you use this software, pleace cite the following paper:
92
+
93
+ ```bibtex
94
+ @inproceedings{pitsianis2019sgtsnepi,
95
+ author = {Pitsianis, Nikos and Iliopoulos, Alexandros-Stavros and Floros, Dimitris and Sun, Xiaobai},
96
+ doi = {10.1109/HPEC.2019.8916505},
97
+ booktitle = {IEEE High Performance Extreme Computing Conference},
98
+ month = {11},
99
+ title = {{Spaceland Embedding of Sparse Stochastic Graphs}},
100
+ year = {2019}
101
+ }
102
+ ```
@@ -0,0 +1,8 @@
1
+ sgtsnepi-0.5.0.dist-info/METADATA,sha256=NWKwHs0aa2g-WPIXE4dS40e5MbAWcKSeGmYTDigkzrc,2989
2
+ sgtsnepi-0.5.0.dist-info/WHEEL,sha256=suq8ARrxbiI7iLH3BgK-82uzxQ-4Hm-m8w01oCokrtA,85
3
+ sgtsnepi/_sgtsnepi.cp313-win_amd64.pyd,sha256=5N9TTLTV-ieuULaNS_KpdHTjf6M_qK_2Yw2q8lNQZaQ,509394
4
+ sgtsnepi/_sgtsnepi.cp313-win_amd64.dll.a,sha256=DxszU6rXncgYCnfqi81QLk7feVjJZRg6rzJyRKSAI5E,1752
5
+ sgtsnepi/sgtsne.py,sha256=xMzqg2hyG8lyr72Ok2cOrUTdXldCnVnnDpjCkHlvLtc,2510
6
+ sgtsnepi/__init__.py,sha256=32ArB_7Y5qWi8FfciG2CnPWyeZPj019XzP0aJi3nuC8,52
7
+ sgtsnepi-0.5.0.data/headers/sgtsne.hpp,sha256=WT6XG3EgH2fT0j6_JOndbbd91bQTGuN50HoGcImDbkU,3340
8
+ sgtsnepi-0.5.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: meson
3
+ Root-Is-Purelib: false
4
+ Tag: cp313-cp313-win_amd64