Metadata-Version: 2.4
Name: facet-core
Version: 0.1.1
Summary: FACET, Factorization, Alignment, Component Estimation, and Transforms
Author-email: Omid Solari <solari@berkeley.edu>
License: # Licensing
        
        This repository is dual-licensed to separate the research code from the manuscript.
        
        ## Library code, MIT License
        
        Everything under `src/facet/`, `papers/*/experiments/`, `papers/*/configs/`,
        `tests/`, `scripts/`, and the top-level configuration files (`pyproject.toml`,
        `conftest.py`, `.github/workflows/`) is released under the MIT License, below.
        
        ```
        MIT License
        
        Copyright (c) 2026 Omid Solari and the FACET contributors
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
        THE SOFTWARE.
        ```
        
        ## Manuscripts, Creative Commons Attribution 4.0 (CC-BY 4.0)
        
        Everything under `docs/manuscripts/` is released under
        [Creative Commons Attribution 4.0 International (CC-BY 4.0)](https://creativecommons.org/licenses/by/4.0/).
        You are free to share and adapt the manuscripts for any purpose, including
        commercially, provided you give appropriate credit, link to the license, and
        indicate if changes were made. See the linked deed for the full legal text.
        
        ## Third-party dependencies
        
        Pretrained model weights downloaded at experiment time (GPT-2 small, ViT-base,
        `transformers` tokenizers) are not redistributed by this repository and remain
        under their respective upstream licenses (OpenAI, Google, Hugging Face).
        
Project-URL: Homepage, https://github.com/omidsolari/FACET
Project-URL: Repository, https://github.com/omidsolari/FACET
Project-URL: Issues, https://github.com/omidsolari/FACET/issues
Project-URL: Changelog, https://github.com/omidsolari/FACET/blob/main/CHANGELOG.md
Keywords: sparse-pca,block-generalized-power,stiefel-manifold,kurdyka-lojasiewicz,safe-screening,interpretability
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Mathematics
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE.md
Requires-Dist: numpy>=1.26
Provides-Extra: torch
Requires-Dist: torch<3.0,>=2.14; extra == "torch"
Provides-Extra: bench
Provides-Extra: experiments
Requires-Dist: pyyaml>=6; extra == "experiments"
Requires-Dist: matplotlib>=3.8; extra == "experiments"
Requires-Dist: seaborn>=0.13; extra == "experiments"
Requires-Dist: pandas>=2.0; extra == "experiments"
Requires-Dist: scipy>=1.11; extra == "experiments"
Requires-Dist: scikit-learn>=1.3; extra == "experiments"
Requires-Dist: transformers<6.0,>=5.19; extra == "experiments"
Requires-Dist: h5py>=3.10; extra == "experiments"
Requires-Dist: anndata>=0.10; extra == "experiments"
Provides-Extra: dev
Requires-Dist: pytest>=8; extra == "dev"
Requires-Dist: hypothesis>=6; extra == "dev"
Requires-Dist: mypy>=1.10; extra == "dev"
Requires-Dist: ruff>=0.8; extra == "dev"
Requires-Dist: pre-commit; extra == "dev"
Requires-Dist: pyyaml>=6; extra == "dev"
Requires-Dist: matplotlib>=3.8; extra == "dev"
Requires-Dist: seaborn>=0.13; extra == "dev"
Requires-Dist: pandas>=2.0; extra == "dev"
Requires-Dist: scipy>=1.11; extra == "dev"
Requires-Dist: scikit-learn>=1.3; extra == "dev"
Dynamic: license-file

# FACET

**Factorization, Alignment, Component Estimation, and Transforms.**

A theory-first sparse-spectral library. The reference implementation accompanies
**BGSP (Block Generalized Sparse Power): Corrected Block Sparse Spectral
Optimization**, which proves (A1–A10) and empirically validates a corrected
block generalized-power estimator with whole-sequence convergence under the
Kurdyka–Łojasiewicz property, finite support/sign identification, and a
radius-based safe-screening rule.

## Install

```bash
python -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install -e '.[dev]'
python -m pytest -q
```

Optional extras:

```bash
python -m pip install -e '.[torch]'         # facet.torch backend
python -m pip install -e '.[experiments]'   # pyyaml + matplotlib + seaborn
python -m pip install -e '.[bench]'         # facet-bench CLI
```

The modern-AI experiment drivers (Tier-3, M1, M2, M4, M5) additionally need
`transformers`; install with `pip install transformers>=5.19` or add
`[experiments]` and `[torch]` together.

## Repository layout

```text
src/facet/
  operators/   base, dense, covariance, screened       # A10 engine
  geometry/    sphere, stiefel  (rank_policy: canonical / raise)
  supports/    threshold, groups, topk, safe_screen    # A10 mask
  objectives/  base, sum_norm, squared_threshold, topk_correlation
  solvers/     polar (FullPolarSolver), safeguarded (SafeguardedRiemannianAscent)
  refit/       rank_one, subspace, mask_then_normalize
  generators/  planted_spike                            # Tier-1 fixture
  diagnostics/ SolverTrace, IterationRecord
  results/     EstimatorStage, FacetResult
  papers/
    block_sparse/   BlockSparseEstimator               # BGSP sklearn-style
  torch/            optional, facet[torch]
  bench/            optional, facet[bench]

papers/a/experiments/   # driver scripts for each figure in the BGSP paper §7
papers/a/configs/       # deterministic YAML for each driver
papers/a/runs/          # per-run CSVs + PNGs

tests/                  # 167 tests; model-free in CI
docs/manuscripts/       # Overleaf-synced LaTeX for the paper
.claude/skills/         # agent-oriented SKILL files + plans
scripts/overleaf_sync.sh  # push/pull manuscripts to Overleaf
```

## Reproducing a BGSP figure

Every figure in `docs/manuscripts/FACET/paper-a/paper/sections/07-results-and-analysis.tex`
is regenerated from a single YAML config. Example (Q4 local-rate validation):

```bash
python papers/a/experiments/q4_local_rate.py \
  --config papers/a/configs/q4_local_rate.yaml \
  --output-dir papers/a/runs/q4
```

Smoke tests under `tests/papers/a/` run the drivers on reduced fixtures with no
model downloads, so CI stays model-free. The full-scale GPT-2 / ViT runs
(T3, M1, M2, M4, M5) require `pip install transformers` and will download the
pretrained weights once from Hugging Face on first run.

## Overleaf sync

Manuscripts are kept in `docs/manuscripts/` and mirrored to Overleaf via a
`git-remote` helper. See `.claude/skills/overleaf/SKILL.md` for the protocol.

```bash
scripts/overleaf_sync.sh compare FACET      # diff
scripts/overleaf_sync.sh push FACET --yes   # push
```

The repository does not compile LaTeX in CI, you compile locally
(`latexmk -pdf main.tex`).

## Status

- **BGSP paper**, manuscript ready to submit; library tagged for v0.1.1 release.
- Theorems A1–A10 proved; whole-sequence KŁ convergence (A8) proof via
  Attouch–Bolte–Svaiter abstract theorem + semi-algebraicity of soft-threshold
  on the algebraic Stiefel variety.
- 7 generated figures (Q1, Q2, Q3, Q4, A4, T2, T3) + 6 modern-AI extension
  figures (M1 multi-layer sweep, M2 monosemanticity, M4 FACET vs SAE, M5 ViT
  CLS clustering, M6 Pitprops benchmark, M7 safe-screening solver uptake).
- 167 tests passing on Python 3.11 / 3.12 / 3.13.

## Research invariant

Every estimator is tracked through four distinct stages, never conflated:

```text
raw selected estimator
    → support-conditioned refit
    → support-fixed recalibration
    → optional end-to-end fine-tuning
```

Gains from later stages are not attributed to support selection.

## Citing

```bibtex
@software{facet_v0_1_0,
  author  = {Solari, Omid},
  title   = {FACET: Factorization, Alignment, Component Estimation, and Transforms},
  version = {0.1.0},
  year    = {2026},
  url     = {https://github.com/omidsolari/FACET}
}
```

For the manuscript, see `CITATION.cff` and the arXiv entry once posted.

## License

Dual-licensed. Library code: MIT. Manuscripts: CC-BY 4.0. See
[`LICENSE.md`](LICENSE.md).
