fisher-simplex 0.3.1__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.
- fisher_simplex-0.3.1/.github/workflows/workflow.yml +59 -0
- fisher_simplex-0.3.1/.gitignore +21 -0
- fisher_simplex-0.3.1/PKG-INFO +13 -0
- fisher_simplex-0.3.1/README.md +116 -0
- fisher_simplex-0.3.1/SPEC.md +959 -0
- fisher_simplex-0.3.1/docs/mathematical_notes.md +257 -0
- fisher_simplex-0.3.1/docs/quickstart.md +84 -0
- fisher_simplex-0.3.1/docs/user_guide.md +256 -0
- fisher_simplex-0.3.1/examples/basic_geometry.py +83 -0
- fisher_simplex-0.3.1/examples/biodiversity_concentration.py +96 -0
- fisher_simplex-0.3.1/examples/distributional_shift.py +81 -0
- fisher_simplex-0.3.1/examples/frontier_enrichment.py +109 -0
- fisher_simplex-0.3.1/examples/portfolio_rebalancing.py +146 -0
- fisher_simplex-0.3.1/examples/sparse_zeros.py +106 -0
- fisher_simplex-0.3.1/pyproject.toml +34 -0
- fisher_simplex-0.3.1/src/fisher_simplex/__init__.py +156 -0
- fisher_simplex-0.3.1/src/fisher_simplex/analysis.py +677 -0
- fisher_simplex-0.3.1/src/fisher_simplex/core.py +550 -0
- fisher_simplex-0.3.1/src/fisher_simplex/frontier.py +281 -0
- fisher_simplex-0.3.1/src/fisher_simplex/generators.py +331 -0
- fisher_simplex-0.3.1/src/fisher_simplex/geometry.py +1016 -0
- fisher_simplex-0.3.1/src/fisher_simplex/harmonic.py +429 -0
- fisher_simplex-0.3.1/src/fisher_simplex/py.typed +0 -0
- fisher_simplex-0.3.1/src/fisher_simplex/utils.py +171 -0
- fisher_simplex-0.3.1/src/fisher_simplex/viz.py +276 -0
- fisher_simplex-0.3.1/tests/__init__.py +0 -0
- fisher_simplex-0.3.1/tests/conftest.py +29 -0
- fisher_simplex-0.3.1/tests/test_analysis.py +490 -0
- fisher_simplex-0.3.1/tests/test_core.py +456 -0
- fisher_simplex-0.3.1/tests/test_frontier.py +161 -0
- fisher_simplex-0.3.1/tests/test_generators.py +145 -0
- fisher_simplex-0.3.1/tests/test_geometry.py +765 -0
- fisher_simplex-0.3.1/tests/test_harmonic.py +287 -0
- fisher_simplex-0.3.1/tests/test_utils.py +193 -0
- fisher_simplex-0.3.1/tests/test_viz.py +203 -0
- fisher_simplex-0.3.1/uv.lock +1645 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
name: CI & Publish
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
tags: ["v*"]
|
|
7
|
+
pull_request:
|
|
8
|
+
branches: [main]
|
|
9
|
+
|
|
10
|
+
permissions:
|
|
11
|
+
contents: read
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
test:
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
strategy:
|
|
17
|
+
matrix:
|
|
18
|
+
python-version: ["3.9", "3.12"]
|
|
19
|
+
steps:
|
|
20
|
+
- uses: actions/checkout@v4
|
|
21
|
+
|
|
22
|
+
- uses: actions/setup-python@v5
|
|
23
|
+
with:
|
|
24
|
+
python-version: ${{ matrix.python-version }}
|
|
25
|
+
|
|
26
|
+
- name: Install dependencies
|
|
27
|
+
run: |
|
|
28
|
+
python -m pip install --upgrade pip
|
|
29
|
+
pip install -e ".[dev,viz]"
|
|
30
|
+
|
|
31
|
+
- name: Lint
|
|
32
|
+
run: ruff check src/ tests/
|
|
33
|
+
|
|
34
|
+
- name: Test
|
|
35
|
+
run: pytest tests/ -v
|
|
36
|
+
|
|
37
|
+
publish:
|
|
38
|
+
needs: test
|
|
39
|
+
runs-on: ubuntu-latest
|
|
40
|
+
if: startsWith(github.ref, 'refs/tags/v')
|
|
41
|
+
permissions:
|
|
42
|
+
id-token: write
|
|
43
|
+
environment:
|
|
44
|
+
name: pypi
|
|
45
|
+
url: https://pypi.org/p/fisher-simplex
|
|
46
|
+
steps:
|
|
47
|
+
- uses: actions/checkout@v4
|
|
48
|
+
|
|
49
|
+
- uses: actions/setup-python@v5
|
|
50
|
+
with:
|
|
51
|
+
python-version: "3.12"
|
|
52
|
+
|
|
53
|
+
- name: Build
|
|
54
|
+
run: |
|
|
55
|
+
python -m pip install --upgrade pip build
|
|
56
|
+
python -m build
|
|
57
|
+
|
|
58
|
+
- name: Publish to PyPI
|
|
59
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Virtual environments
|
|
2
|
+
.venv/
|
|
3
|
+
|
|
4
|
+
# Python
|
|
5
|
+
__pycache__/
|
|
6
|
+
*.pyc
|
|
7
|
+
*.egg-info/
|
|
8
|
+
dist/
|
|
9
|
+
build/
|
|
10
|
+
|
|
11
|
+
# Test / lint caches
|
|
12
|
+
.pytest_cache/
|
|
13
|
+
.ruff_cache/
|
|
14
|
+
.mypy_cache/
|
|
15
|
+
.coverage
|
|
16
|
+
htmlcov/
|
|
17
|
+
|
|
18
|
+
# Tool state directories
|
|
19
|
+
.cardinal/
|
|
20
|
+
.avril/
|
|
21
|
+
.claude/
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fisher-simplex
|
|
3
|
+
Version: 0.3.1
|
|
4
|
+
Summary: Canonical simplex geometry via the Fisher amplitude lift, with low-complexity invariant tools
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Requires-Python: >=3.9
|
|
7
|
+
Requires-Dist: numpy>=1.21
|
|
8
|
+
Requires-Dist: scipy>=1.7
|
|
9
|
+
Provides-Extra: dev
|
|
10
|
+
Requires-Dist: pytest>=7.0; extra == 'dev'
|
|
11
|
+
Requires-Dist: ruff>=0.4; extra == 'dev'
|
|
12
|
+
Provides-Extra: viz
|
|
13
|
+
Requires-Dist: matplotlib>=3.5; extra == 'viz'
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# fisher-simplex
|
|
2
|
+
|
|
3
|
+
A boundary-safe information-geometry toolkit for probability-simplex data, built around the Fisher/Hellinger square-root embedding and extended with canonical low-complexity invariant diagnostics.
|
|
4
|
+
|
|
5
|
+
Use it when your data are normalized nonnegative vectors and you need principled distances, means, interpolation, and low-order structural summaries without ad hoc zero handling.
|
|
6
|
+
|
|
7
|
+
Need a different language than Python? `fisher-simplex` maintains a [SPEC.md](/SPEC.md) in order to serve as a ghost library. Clone the repository as reference and point your favorite coding agent at the specification to reproduce with your unique requirements met.
|
|
8
|
+
|
|
9
|
+
## Positioning
|
|
10
|
+
|
|
11
|
+
**Primarily a geometry toolkit** — exact Fisher/Hellinger distances, means, geodesics, tangent PCA, and kernel methods on the probability simplex.
|
|
12
|
+
|
|
13
|
+
**Secondarily a low-complexity invariant toolkit** — canonical overlap diagnostics and forced-pair summaries (Q_delta, H_3) grounded in the Fisher-lifted symmetric-even harmonic sector.
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pip install fisher-simplex
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
For visualization support:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pip install "fisher-simplex[viz]"
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Or install from source:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
git clone <repo-url> && cd fisher-simplex
|
|
31
|
+
pip install -e ".[dev,viz]"
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Quick usage
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
import numpy as np
|
|
38
|
+
import fisher_simplex as fs
|
|
39
|
+
|
|
40
|
+
# Two probability vectors
|
|
41
|
+
a = np.array([0.5, 0.3, 0.2])
|
|
42
|
+
b = np.array([0.1, 0.6, 0.3])
|
|
43
|
+
|
|
44
|
+
# Fisher distance (geodesic distance on the simplex)
|
|
45
|
+
d = fs.fisher_distance(a, b)
|
|
46
|
+
print(f"Fisher distance: {d:.4f}")
|
|
47
|
+
|
|
48
|
+
# Extrinsic Fisher mean of a cloud
|
|
49
|
+
cloud = np.array([
|
|
50
|
+
[0.5, 0.3, 0.2],
|
|
51
|
+
[0.1, 0.6, 0.3],
|
|
52
|
+
[0.3, 0.3, 0.4],
|
|
53
|
+
])
|
|
54
|
+
mean = fs.fisher_mean(cloud) # extrinsic projected mean
|
|
55
|
+
print(f"Fisher mean: {mean}")
|
|
56
|
+
|
|
57
|
+
# Forced coordinates (Q_delta, H_3)
|
|
58
|
+
coords = fs.forced_coordinates(cloud)
|
|
59
|
+
print(f"Forced coordinates:\n{coords}")
|
|
60
|
+
|
|
61
|
+
# Divergence analysis
|
|
62
|
+
report = fs.divergence_analysis(cloud)
|
|
63
|
+
print(f"Mean divergence: {report['mean_divergence']:.6f}")
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Module overview
|
|
67
|
+
|
|
68
|
+
| Module | Purpose | Status |
|
|
69
|
+
|--------|---------|--------|
|
|
70
|
+
| `core` | Scalar invariants, overlap families, forced pair, Fisher lift, bridge statistics | Exact |
|
|
71
|
+
| `geometry` | Distances, geodesics, means, tangent maps, PCA, kernels (linear, polynomial, RBF) | Exact / exact-derived |
|
|
72
|
+
| `analysis` | Batch diagnostics, divergence reports, forced-block analysis, text reports | Exact-derived / heuristic |
|
|
73
|
+
| `generators` | Synthetic reference ensembles (Dirichlet, broken stick, lognormal, etc.) | Engineering |
|
|
74
|
+
| `utils` | Validation, projection, closure | Engineering |
|
|
75
|
+
| `frontier` | Degree-8 enrichment coordinates and residual diagnostics | Experimental |
|
|
76
|
+
| `harmonic` | Low-degree symmetric-even harmonic tools | Experimental |
|
|
77
|
+
| `viz` | Matplotlib plotting utilities (requires `matplotlib`) | Optional |
|
|
78
|
+
|
|
79
|
+
## Examples
|
|
80
|
+
|
|
81
|
+
The `examples/` directory contains runnable scripts demonstrating domain-specific workflows:
|
|
82
|
+
|
|
83
|
+
| Example | Domain | Demonstrates |
|
|
84
|
+
|---------|--------|-------------|
|
|
85
|
+
| `basic_geometry.py` | General | Fisher distance, mean, geodesics, tangent PCA, kernels |
|
|
86
|
+
| `portfolio_rebalancing.py` | Finance | Fisher vs Euclidean distance, geodesic rebalancing, HHI shape correction |
|
|
87
|
+
| `biodiversity_concentration.py` | Ecology / Economics | Overlap diagnostics, forced-pair invariants, concentration profiling |
|
|
88
|
+
| `distributional_shift.py` | Machine learning | Shift detection between classifier output clouds |
|
|
89
|
+
| `sparse_zeros.py` | Microbiome | Boundary-safe geometry on zero-inflated compositional data |
|
|
90
|
+
| `frontier_enrichment.py` | Research | Degree-8 enrichment coordinates, residual diagnostics |
|
|
91
|
+
|
|
92
|
+
## Documentation
|
|
93
|
+
|
|
94
|
+
- [Quick start](docs/quickstart.md) — five steps to get going
|
|
95
|
+
- [User guide](docs/user_guide.md) — workflows for geometry, diagnostics, and analysis
|
|
96
|
+
- [Mathematical notes](docs/mathematical_notes.md) — derivations, theorems, and conventions
|
|
97
|
+
|
|
98
|
+
## Dependencies
|
|
99
|
+
|
|
100
|
+
**Required:** Python >= 3.9, NumPy >= 1.21, SciPy >= 1.7
|
|
101
|
+
|
|
102
|
+
**Optional:** matplotlib >= 3.5 (viz module)
|
|
103
|
+
|
|
104
|
+
## License
|
|
105
|
+
|
|
106
|
+
MIT
|
|
107
|
+
|
|
108
|
+
## Citation
|
|
109
|
+
|
|
110
|
+
Software:
|
|
111
|
+
|
|
112
|
+
> `fisher-simplex`: Canonical simplex geometry via the Fisher amplitude lift, with low-complexity invariant diagnostics. Version 0.3.
|
|
113
|
+
|
|
114
|
+
Mathematical attribution:
|
|
115
|
+
|
|
116
|
+
> Fisher-Harmonic programme: overlap-family divergence, low-degree forced compression in the Fisher-lifted symmetric-even sector, and degree-8 selective frontier tools for simplex observables.
|