nsa-flow 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.
- nsa_flow-0.1.0/PKG-INFO +145 -0
- nsa_flow-0.1.0/README.md +131 -0
- nsa_flow-0.1.0/nsa_flow/__init__.py +3 -0
- nsa_flow-0.1.0/nsa_flow/core.py +1229 -0
- nsa_flow-0.1.0/nsa_flow.egg-info/PKG-INFO +145 -0
- nsa_flow-0.1.0/nsa_flow.egg-info/SOURCES.txt +13 -0
- nsa_flow-0.1.0/nsa_flow.egg-info/dependency_links.txt +1 -0
- nsa_flow-0.1.0/nsa_flow.egg-info/requires.txt +3 -0
- nsa_flow-0.1.0/nsa_flow.egg-info/top_level.txt +1 -0
- nsa_flow-0.1.0/pyproject.toml +26 -0
- nsa_flow-0.1.0/setup.cfg +4 -0
- nsa_flow-0.1.0/tests/test_energy_behavior.py +101 -0
- nsa_flow-0.1.0/tests/test_nsa_autograd.py +108 -0
- nsa_flow-0.1.0/tests/test_nsa_flow_extended.py +191 -0
- nsa_flow-0.1.0/tests/test_nsa_flow_opt.py +7 -0
nsa_flow-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: nsa_flow
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Non-negative Stiefel Approximating Flow for interpretable representation learning
|
|
5
|
+
Author-email: "B. Avants" <stnava@example.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/stnava/nsa_flow
|
|
8
|
+
Project-URL: Repository, https://github.com/stnava/nsa_flow
|
|
9
|
+
Requires-Python: >=3.9
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
Requires-Dist: torch>=2.0
|
|
12
|
+
Requires-Dist: numpy>=1.23
|
|
13
|
+
Requires-Dist: matplotlib>=3.7
|
|
14
|
+
|
|
15
|
+
# 🧠 NSA-Flow: Non-negative Stiefel Approximating Flow
|
|
16
|
+
|
|
17
|
+
**NSA-Flow** is a general-purpose optimization framework for interpretable representation learning.
|
|
18
|
+
It unifies sparse matrix factorization, orthogonalization, and manifold constraints into a single, differentiable algorithm that operates near the Stiefel manifold.
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## ✨ Overview
|
|
23
|
+
|
|
24
|
+
Interpretable representation learning remains a core challenge in high-dimensional domains such as neuroimaging, genomics, and text analysis.
|
|
25
|
+
**NSA-Flow** provides a smooth geometric mechanism for balancing **reconstruction fidelity** and **column-wise decorrelation**, producing sparse, stable, and interpretable representations.
|
|
26
|
+
|
|
27
|
+
NSA-Flow enforces structured sparsity via a single tunable weight parameter, combining:
|
|
28
|
+
- Continuous orthogonality control via manifold retraction (e.g., soft-polar, polar)
|
|
29
|
+
- Non-negativity via proximal updates
|
|
30
|
+
- Adaptive gradient scaling and learning-rate control
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## 🧩 Key Features
|
|
35
|
+
|
|
36
|
+
- ⚙️ **Continuous flow near the Stiefel manifold**
|
|
37
|
+
- 🧮 **Non-negative and orthogonal constraints**
|
|
38
|
+
- 🧠 **Interpretable latent representations**
|
|
39
|
+
- 🚀 **Compatible with PyTorch optimization routines**
|
|
40
|
+
- 🧬 **Validated on neuroimaging and genomics datasets**
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## 📦 Installation
|
|
45
|
+
|
|
46
|
+
Install from PyPI (once published):
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
pip install nsa_flow
|
|
50
|
+
|
|
51
|
+
Or install the latest development version directly from GitHub:
|
|
52
|
+
|
|
53
|
+
pip install git+https://github.com/stnava/nsa_flow.git
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
⸻
|
|
57
|
+
|
|
58
|
+
🧰 Dependencies
|
|
59
|
+
• Python ≥ 3.9
|
|
60
|
+
• PyTorch ≥ 2.0
|
|
61
|
+
• NumPy ≥ 1.23
|
|
62
|
+
• Matplotlib (for optional visualization)
|
|
63
|
+
|
|
64
|
+
⸻
|
|
65
|
+
|
|
66
|
+
🚀 Quick Start
|
|
67
|
+
|
|
68
|
+
import torch
|
|
69
|
+
import nsa_flow
|
|
70
|
+
from nsa_flow import nsa_flow, invariant_orthogonality_defect
|
|
71
|
+
|
|
72
|
+
torch.manual_seed(42)
|
|
73
|
+
|
|
74
|
+
# Random initialization
|
|
75
|
+
Y = torch.randn(50, 10)
|
|
76
|
+
X0 = torch.randn_like(Y)
|
|
77
|
+
|
|
78
|
+
# Run NSA-Flow optimization
|
|
79
|
+
result = nsa_flow(
|
|
80
|
+
Y,
|
|
81
|
+
X0=X0,
|
|
82
|
+
w=0.8,
|
|
83
|
+
retraction="soft_polar",
|
|
84
|
+
optimizer="sgdp",
|
|
85
|
+
max_iter=50,
|
|
86
|
+
record_every=1,
|
|
87
|
+
tol=1e-8,
|
|
88
|
+
initial_learning_rate=1e-2,
|
|
89
|
+
verbose=True,
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
print("Initial orthogonality defect:", invariant_orthogonality_defect(Y))
|
|
93
|
+
print("Final orthogonality defect:", invariant_orthogonality_defect(result["Y"]))
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
⸻
|
|
97
|
+
|
|
98
|
+
📖 Documentation
|
|
99
|
+
|
|
100
|
+
NSA-Flow exposes a small set of high-level functions:
|
|
101
|
+
|
|
102
|
+
Function Description
|
|
103
|
+
nsa_flow() Main optimization loop balancing fidelity and orthogonality
|
|
104
|
+
nsa_flow_retract_auto() Retraction operator enforcing manifold constraints
|
|
105
|
+
invariant_orthogonality_defect() Computes orthogonality defect measure
|
|
106
|
+
defect_fast() Fast approximate defect metric
|
|
107
|
+
nsa_flow_autograd() Autograd-compatible variant for joint optimization
|
|
108
|
+
get_torch_optimizer() Returns a configured PyTorch optimizer
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
⸻
|
|
112
|
+
|
|
113
|
+
🧪 Validation
|
|
114
|
+
|
|
115
|
+
NSA-Flow has been validated in:
|
|
116
|
+
• Golub leukemia gene expression dataset
|
|
117
|
+
• Alzheimer’s Disease Neuroimaging Initiative (ADNI) dataset
|
|
118
|
+
|
|
119
|
+
NSA-Flow constraints maintain or improve performance while simplifying latent representations and improving interpretability.
|
|
120
|
+
|
|
121
|
+
⸻
|
|
122
|
+
|
|
123
|
+
🧑💻 Citation
|
|
124
|
+
|
|
125
|
+
If you use NSA-Flow in research, please cite:
|
|
126
|
+
|
|
127
|
+
Stnava et al. (2025). NSA-Flow: Non-negative Stiefel Approximating Flow for Interpretable Representation Learning.
|
|
128
|
+
|
|
129
|
+
⸻
|
|
130
|
+
|
|
131
|
+
⚖️ License
|
|
132
|
+
|
|
133
|
+
MIT License © 2025
|
|
134
|
+
|
|
135
|
+
⸻
|
|
136
|
+
|
|
137
|
+
📫 Contact
|
|
138
|
+
|
|
139
|
+
For issues, feature requests, or contributions, open an issue on
|
|
140
|
+
GitHub.
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
|
nsa_flow-0.1.0/README.md
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# 🧠 NSA-Flow: Non-negative Stiefel Approximating Flow
|
|
2
|
+
|
|
3
|
+
**NSA-Flow** is a general-purpose optimization framework for interpretable representation learning.
|
|
4
|
+
It unifies sparse matrix factorization, orthogonalization, and manifold constraints into a single, differentiable algorithm that operates near the Stiefel manifold.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## ✨ Overview
|
|
9
|
+
|
|
10
|
+
Interpretable representation learning remains a core challenge in high-dimensional domains such as neuroimaging, genomics, and text analysis.
|
|
11
|
+
**NSA-Flow** provides a smooth geometric mechanism for balancing **reconstruction fidelity** and **column-wise decorrelation**, producing sparse, stable, and interpretable representations.
|
|
12
|
+
|
|
13
|
+
NSA-Flow enforces structured sparsity via a single tunable weight parameter, combining:
|
|
14
|
+
- Continuous orthogonality control via manifold retraction (e.g., soft-polar, polar)
|
|
15
|
+
- Non-negativity via proximal updates
|
|
16
|
+
- Adaptive gradient scaling and learning-rate control
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## 🧩 Key Features
|
|
21
|
+
|
|
22
|
+
- ⚙️ **Continuous flow near the Stiefel manifold**
|
|
23
|
+
- 🧮 **Non-negative and orthogonal constraints**
|
|
24
|
+
- 🧠 **Interpretable latent representations**
|
|
25
|
+
- 🚀 **Compatible with PyTorch optimization routines**
|
|
26
|
+
- 🧬 **Validated on neuroimaging and genomics datasets**
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## 📦 Installation
|
|
31
|
+
|
|
32
|
+
Install from PyPI (once published):
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install nsa_flow
|
|
36
|
+
|
|
37
|
+
Or install the latest development version directly from GitHub:
|
|
38
|
+
|
|
39
|
+
pip install git+https://github.com/stnava/nsa_flow.git
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
⸻
|
|
43
|
+
|
|
44
|
+
🧰 Dependencies
|
|
45
|
+
• Python ≥ 3.9
|
|
46
|
+
• PyTorch ≥ 2.0
|
|
47
|
+
• NumPy ≥ 1.23
|
|
48
|
+
• Matplotlib (for optional visualization)
|
|
49
|
+
|
|
50
|
+
⸻
|
|
51
|
+
|
|
52
|
+
🚀 Quick Start
|
|
53
|
+
|
|
54
|
+
import torch
|
|
55
|
+
import nsa_flow
|
|
56
|
+
from nsa_flow import nsa_flow, invariant_orthogonality_defect
|
|
57
|
+
|
|
58
|
+
torch.manual_seed(42)
|
|
59
|
+
|
|
60
|
+
# Random initialization
|
|
61
|
+
Y = torch.randn(50, 10)
|
|
62
|
+
X0 = torch.randn_like(Y)
|
|
63
|
+
|
|
64
|
+
# Run NSA-Flow optimization
|
|
65
|
+
result = nsa_flow(
|
|
66
|
+
Y,
|
|
67
|
+
X0=X0,
|
|
68
|
+
w=0.8,
|
|
69
|
+
retraction="soft_polar",
|
|
70
|
+
optimizer="sgdp",
|
|
71
|
+
max_iter=50,
|
|
72
|
+
record_every=1,
|
|
73
|
+
tol=1e-8,
|
|
74
|
+
initial_learning_rate=1e-2,
|
|
75
|
+
verbose=True,
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
print("Initial orthogonality defect:", invariant_orthogonality_defect(Y))
|
|
79
|
+
print("Final orthogonality defect:", invariant_orthogonality_defect(result["Y"]))
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
⸻
|
|
83
|
+
|
|
84
|
+
📖 Documentation
|
|
85
|
+
|
|
86
|
+
NSA-Flow exposes a small set of high-level functions:
|
|
87
|
+
|
|
88
|
+
Function Description
|
|
89
|
+
nsa_flow() Main optimization loop balancing fidelity and orthogonality
|
|
90
|
+
nsa_flow_retract_auto() Retraction operator enforcing manifold constraints
|
|
91
|
+
invariant_orthogonality_defect() Computes orthogonality defect measure
|
|
92
|
+
defect_fast() Fast approximate defect metric
|
|
93
|
+
nsa_flow_autograd() Autograd-compatible variant for joint optimization
|
|
94
|
+
get_torch_optimizer() Returns a configured PyTorch optimizer
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
⸻
|
|
98
|
+
|
|
99
|
+
🧪 Validation
|
|
100
|
+
|
|
101
|
+
NSA-Flow has been validated in:
|
|
102
|
+
• Golub leukemia gene expression dataset
|
|
103
|
+
• Alzheimer’s Disease Neuroimaging Initiative (ADNI) dataset
|
|
104
|
+
|
|
105
|
+
NSA-Flow constraints maintain or improve performance while simplifying latent representations and improving interpretability.
|
|
106
|
+
|
|
107
|
+
⸻
|
|
108
|
+
|
|
109
|
+
🧑💻 Citation
|
|
110
|
+
|
|
111
|
+
If you use NSA-Flow in research, please cite:
|
|
112
|
+
|
|
113
|
+
Stnava et al. (2025). NSA-Flow: Non-negative Stiefel Approximating Flow for Interpretable Representation Learning.
|
|
114
|
+
|
|
115
|
+
⸻
|
|
116
|
+
|
|
117
|
+
⚖️ License
|
|
118
|
+
|
|
119
|
+
MIT License © 2025
|
|
120
|
+
|
|
121
|
+
⸻
|
|
122
|
+
|
|
123
|
+
📫 Contact
|
|
124
|
+
|
|
125
|
+
For issues, feature requests, or contributions, open an issue on
|
|
126
|
+
GitHub.
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
from .core import nsa_flow, nsa_flow_retract_auto, inv_sqrt_sym_adaptive, invariant_orthogonality_defect, energy_fidelity, nsa_flow_autograd, get_torch_optimizer, defect_fast
|
|
2
|
+
__all__ = ["nsa_flow", "nsa_flow_retract_auto", "inv_sqrt_sym_adaptive", "invariant_orthogonality_defect", "energy_fidelity","nsa_flow_autograd","get_torch_optimizer","defect_fast"]
|
|
3
|
+
|