FastMapy 0.0.1__tar.gz → 0.1.0__tar.gz
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.
- fastmapy-0.1.0/FastMapy.egg-info/PKG-INFO +154 -0
- {FastMapy-0.0.1 → fastmapy-0.1.0}/FastMapy.egg-info/SOURCES.txt +7 -0
- fastmapy-0.1.0/FastMapy.egg-info/requires.txt +20 -0
- fastmapy-0.1.0/LICENSE +674 -0
- fastmapy-0.1.0/PKG-INFO +154 -0
- fastmapy-0.1.0/README.md +117 -0
- {FastMapy-0.0.1 → fastmapy-0.1.0}/fastmap/__init__.py +2 -2
- {FastMapy-0.0.1 → fastmapy-0.1.0}/fastmap/_distances.py +2 -10
- fastmapy-0.1.0/fastmap/_fastmap.py +282 -0
- {FastMapy-0.0.1 → fastmapy-0.1.0}/fastmap/distances/_cosine.py +15 -8
- fastmapy-0.1.0/fastmap/distances/_helpers.py +18 -0
- fastmapy-0.1.0/fastmap/distances/_jaccard.py +69 -0
- {FastMapy-0.0.1 → fastmapy-0.1.0}/fastmap/distances/_l1.py +7 -7
- {FastMapy-0.0.1 → fastmapy-0.1.0}/fastmap/distances/_l2.py +8 -7
- {FastMapy-0.0.1 → fastmapy-0.1.0}/fastmap/distances/_lev.py +9 -12
- fastmapy-0.1.0/fastmap/metrics.py +84 -0
- fastmapy-0.1.0/fastmap/plots.py +65 -0
- fastmapy-0.1.0/pyproject.toml +72 -0
- fastmapy-0.1.0/setup.py +9 -0
- fastmapy-0.1.0/tests/test_distances.py +53 -0
- fastmapy-0.1.0/tests/test_fastmap.py +111 -0
- fastmapy-0.1.0/tests/test_metrics.py +39 -0
- fastmapy-0.1.0/utils/__init__.py +1 -0
- {FastMapy-0.0.1 → fastmapy-0.1.0}/utils/_tools.py +7 -5
- FastMapy-0.0.1/FastMapy.egg-info/PKG-INFO +0 -42
- FastMapy-0.0.1/FastMapy.egg-info/requires.txt +0 -2
- FastMapy-0.0.1/PKG-INFO +0 -42
- FastMapy-0.0.1/README.md +0 -32
- FastMapy-0.0.1/fastmap/_fastmap.py +0 -185
- FastMapy-0.0.1/fastmap/distances/_helpers.py +0 -17
- FastMapy-0.0.1/fastmap/distances/_jaccard.py +0 -73
- FastMapy-0.0.1/setup.py +0 -25
- FastMapy-0.0.1/utils/__init__.py +0 -1
- {FastMapy-0.0.1 → fastmapy-0.1.0}/FastMapy.egg-info/dependency_links.txt +0 -0
- {FastMapy-0.0.1 → fastmapy-0.1.0}/FastMapy.egg-info/top_level.txt +0 -0
- {FastMapy-0.0.1 → fastmapy-0.1.0}/fastmap/_fastmap_funcs.py +0 -0
- {FastMapy-0.0.1 → fastmapy-0.1.0}/fastmap/distances/__init__.py +2 -2
- {FastMapy-0.0.1 → fastmapy-0.1.0}/setup.cfg +0 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: FastMapy
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python implementation of the FastMap multidimensional-scaling technique.
|
|
5
|
+
Author-email: Shawn Davis <shawndavis.lomod@gmail.com>
|
|
6
|
+
License-Expression: GPL-3.0-only
|
|
7
|
+
Project-URL: Homepage, https://github.com/shawn-davis/FastMapy
|
|
8
|
+
Project-URL: Repository, https://github.com/shawn-davis/FastMapy
|
|
9
|
+
Classifier: Development Status :: 2 - Pre-Alpha
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Requires-Python: >=3.9
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Requires-Dist: numpy>=1.22
|
|
21
|
+
Provides-Extra: dev
|
|
22
|
+
Requires-Dist: build>=1.2; extra == "dev"
|
|
23
|
+
Requires-Dist: pytest<9,>=8; extra == "dev"
|
|
24
|
+
Requires-Dist: ruff>=0.8; extra == "dev"
|
|
25
|
+
Provides-Extra: metrics
|
|
26
|
+
Requires-Dist: scipy>=1.9; extra == "metrics"
|
|
27
|
+
Provides-Extra: plots
|
|
28
|
+
Requires-Dist: matplotlib>=3.6; extra == "plots"
|
|
29
|
+
Requires-Dist: scikit-learn>=1.2; extra == "plots"
|
|
30
|
+
Requires-Dist: umap-learn>=0.5; extra == "plots"
|
|
31
|
+
Provides-Extra: all
|
|
32
|
+
Requires-Dist: scipy>=1.9; extra == "all"
|
|
33
|
+
Requires-Dist: matplotlib>=3.6; extra == "all"
|
|
34
|
+
Requires-Dist: scikit-learn>=1.2; extra == "all"
|
|
35
|
+
Requires-Dist: umap-learn>=0.5; extra == "all"
|
|
36
|
+
Dynamic: license-file
|
|
37
|
+
|
|
38
|
+
# FastMapy
|
|
39
|
+
|
|
40
|
+
FastMapy is a Python implementation of the FastMap<sup id="a1">[1](#f1)</sup> multidimensional-scaling technique. It
|
|
41
|
+
embeds objects into a vector space from a supplied distance metric, attempting to preserve their relative distances.
|
|
42
|
+
|
|
43
|
+
This package has common distance metrics already defined and ready to use over appropriate objects, such as
|
|
44
|
+
Jaccard distance over character shingled _n_-gram strings or Levenshtein edit distance for embedding string objects.
|
|
45
|
+
Euclidean distance and taxi cab distance are also available for vector objects. Dictionary objects also work assuming a
|
|
46
|
+
sparse vector style dictionary of _{index: count}_ where index can be an actual vector index or a token and its
|
|
47
|
+
occurrence count.
|
|
48
|
+
|
|
49
|
+
Threaded execution can be enabled for model building and object transformation with the `cores` argument. It is set to
|
|
50
|
+
serial execution (`cores=1`) by default. The benefit depends on the distance metric and runtime.
|
|
51
|
+
|
|
52
|
+
## Installation
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
python -m pip install FastMapy
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
For local development:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
python -m pip install -e '.[dev]'
|
|
62
|
+
pytest
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Optional features can be installed individually with `FastMapy[metrics]` or `FastMapy[plots]`, or together with
|
|
66
|
+
`FastMapy[all]`. t-SNE and UMAP are included only in the plotting extra.
|
|
67
|
+
|
|
68
|
+
## Usage
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
from fastmap.distances import Jaccard
|
|
72
|
+
import fastmap
|
|
73
|
+
|
|
74
|
+
fm_model = fastmap.FastMap(dim=8, distance=Jaccard, dist_args={'shingle_size':4})
|
|
75
|
+
|
|
76
|
+
embedding = fm_model.fit_transform(string_data)
|
|
77
|
+
```
|
|
78
|
+
The target vector space is eight-dimensional and strings are shingled into four-grams before their distances are
|
|
79
|
+
computed. `fit_transform` returns one NumPy array per input object.
|
|
80
|
+
|
|
81
|
+
`fit` requires more training objects than requested dimensions. `transform` expects a collection of objects; wrap a
|
|
82
|
+
single dense vector in a one-element collection, such as `model.transform([[1.0, 2.0]])`.
|
|
83
|
+
|
|
84
|
+
### Metrics
|
|
85
|
+
|
|
86
|
+
`fastmap.metrics` provides a pairwise-distance helper plus normalized stress, Pearson/Spearman distance correlation,
|
|
87
|
+
and trustworthiness. Pass the original pairwise-distance matrix and the resulting embedding to the evaluators. Spearman
|
|
88
|
+
correlation requires the `metrics` extra.
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
from fastmap.metrics import distance_correlation, pairwise_distances, trustworthiness
|
|
92
|
+
|
|
93
|
+
original_distances = pairwise_distances(string_data, Jaccard(shingle_size=4))
|
|
94
|
+
print(distance_correlation(original_distances, embedding))
|
|
95
|
+
print(trustworthiness(original_distances, embedding, n_neighbors=5))
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Plots
|
|
99
|
+
|
|
100
|
+
`fastmap.plots.plot_embedding` renders 2D or 3D embeddings. For embeddings with more dimensions,
|
|
101
|
+
`reduce_for_plot` performs a visualization-only t-SNE or UMAP reduction; it does not train or stack another FastMap
|
|
102
|
+
model. These helpers require the `plots` extra.
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
from fastmap.plots import plot_embedding, reduce_for_plot
|
|
106
|
+
|
|
107
|
+
plot_embedding(embedding_2d, dimensions=2)
|
|
108
|
+
plot_embedding(embedding_3d, dimensions=3)
|
|
109
|
+
|
|
110
|
+
umap_2d = reduce_for_plot(embedding, method="umap", n_components=2)
|
|
111
|
+
plot_embedding(umap_2d, dimensions=2)
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Reproducibility
|
|
115
|
+
|
|
116
|
+
FastMap selects an initial pivot randomly for each dimension. Consequently, unseeded fits are intentionally
|
|
117
|
+
non-deterministic: two fits over identical data can produce different, valid embeddings. Tests and experiments that need
|
|
118
|
+
repeatability should control Python's random-number generator before fitting.
|
|
119
|
+
|
|
120
|
+
### Built-in metrics
|
|
121
|
+
|
|
122
|
+
| Metric | Inputs |
|
|
123
|
+
| --- | --- |
|
|
124
|
+
| `L1` | Dense sequences or sparse `{index: value}` dictionaries |
|
|
125
|
+
| `L2` | Dense sequences or sparse `{index: value}` dictionaries |
|
|
126
|
+
| `Cosine` | Dense sequences or sparse dictionaries; returns chord distance |
|
|
127
|
+
| `Jaccard` | Strings, sets, or weighted dictionaries |
|
|
128
|
+
| `Lev` | Strings and sequence-like objects |
|
|
129
|
+
|
|
130
|
+
`cores` enables threaded fitting and transformation. It defaults to `1`; any speedup depends on the distance metric and
|
|
131
|
+
runtime.
|
|
132
|
+
|
|
133
|
+
### Fitting a batch of distinct models
|
|
134
|
+
|
|
135
|
+
Use `FastMap.fit_many` to fit several models with identical settings against one training collection:
|
|
136
|
+
|
|
137
|
+
```python
|
|
138
|
+
models = fastmap.FastMap.fit_many(
|
|
139
|
+
string_data,
|
|
140
|
+
count=4,
|
|
141
|
+
dim=8,
|
|
142
|
+
distance=Jaccard,
|
|
143
|
+
dist_args={"shingle_size": 4},
|
|
144
|
+
)
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Each model starts every dimension from a distinct training-object index. The batch also avoids reusing an unordered
|
|
148
|
+
pivot pair anywhere in the batch. If a pair collides, FastMap retries that dimension with another unused starting point
|
|
149
|
+
and retains all prior dimensions. When no distinct pair can be found within `pair_retries` attempts, the collision is
|
|
150
|
+
retained and reported by the model's `pivot_pair_collisions` property. `count` cannot exceed the number of training
|
|
151
|
+
objects.
|
|
152
|
+
|
|
153
|
+
## References
|
|
154
|
+
<b id="f1">1</b> Proceedings of the 1995 ACM SIGMOD international conference on Management of data - SIGMOD ’95. (1995). doi:10.1145/223784 [↩](#a1)
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
LICENSE
|
|
1
2
|
README.md
|
|
3
|
+
pyproject.toml
|
|
2
4
|
setup.py
|
|
3
5
|
FastMapy.egg-info/PKG-INFO
|
|
4
6
|
FastMapy.egg-info/SOURCES.txt
|
|
@@ -9,6 +11,8 @@ fastmap/__init__.py
|
|
|
9
11
|
fastmap/_distances.py
|
|
10
12
|
fastmap/_fastmap.py
|
|
11
13
|
fastmap/_fastmap_funcs.py
|
|
14
|
+
fastmap/metrics.py
|
|
15
|
+
fastmap/plots.py
|
|
12
16
|
fastmap/distances/__init__.py
|
|
13
17
|
fastmap/distances/_cosine.py
|
|
14
18
|
fastmap/distances/_helpers.py
|
|
@@ -16,5 +20,8 @@ fastmap/distances/_jaccard.py
|
|
|
16
20
|
fastmap/distances/_l1.py
|
|
17
21
|
fastmap/distances/_l2.py
|
|
18
22
|
fastmap/distances/_lev.py
|
|
23
|
+
tests/test_distances.py
|
|
24
|
+
tests/test_fastmap.py
|
|
25
|
+
tests/test_metrics.py
|
|
19
26
|
utils/__init__.py
|
|
20
27
|
utils/_tools.py
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
numpy>=1.22
|
|
2
|
+
|
|
3
|
+
[all]
|
|
4
|
+
scipy>=1.9
|
|
5
|
+
matplotlib>=3.6
|
|
6
|
+
scikit-learn>=1.2
|
|
7
|
+
umap-learn>=0.5
|
|
8
|
+
|
|
9
|
+
[dev]
|
|
10
|
+
build>=1.2
|
|
11
|
+
pytest<9,>=8
|
|
12
|
+
ruff>=0.8
|
|
13
|
+
|
|
14
|
+
[metrics]
|
|
15
|
+
scipy>=1.9
|
|
16
|
+
|
|
17
|
+
[plots]
|
|
18
|
+
matplotlib>=3.6
|
|
19
|
+
scikit-learn>=1.2
|
|
20
|
+
umap-learn>=0.5
|