Metadata-Version: 2.4
Name: fdia-analysis
Version: 0.22.0
Summary: State estimation, attack localization, federated training and trusted-meter selection on fdia-graph timelines.
Author: Benjamin Myers
Author-email: Benjamin Myers <benjamin.myers.465@my.csun.edu>
License-Expression: MIT
Project-URL: Homepage, https://github.com/myersben9/fdia-graph
Project-URL: Repository, https://github.com/myersben9/fdia-graph
Keywords: power-systems,false-data-injection,FDIA,state-estimation,localization,federated-learning,smart-grid
Classifier: Programming Language :: Python :: 3
Classifier: Intended Audience :: Science/Research
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: fdia-graph==0.22.0
Requires-Dist: numpy>=1.21
Requires-Dist: h5py>=3.6
Provides-Extra: torch
Requires-Dist: torch>=1.12; extra == "torch"
Provides-Extra: se
Requires-Dist: pandapower>=2.10; extra == "se"
Requires-Dist: pandas>=1.3; extra == "se"
Requires-Dist: scipy>=1.8; extra == "se"
Provides-Extra: federated
Requires-Dist: torch>=1.12; extra == "federated"
Requires-Dist: scikit-learn>=1.3; extra == "federated"
Provides-Extra: all
Requires-Dist: torch>=1.12; extra == "all"
Requires-Dist: pandapower>=2.10; extra == "all"
Requires-Dist: pandas>=1.3; extra == "all"
Requires-Dist: scipy>=1.8; extra == "all"
Requires-Dist: scikit-learn>=1.3; extra == "all"
Provides-Extra: test
Requires-Dist: pytest>=7; extra == "test"
Requires-Dist: pytest-xdist>=3; extra == "test"
Dynamic: license-file

# fdia-analysis

The analysis toolkit for [fdia-graph](https://github.com/myersben9/fdia-graph) timelines: state
estimation, attack localization, federated training, trusted-meter selection, and the store the
measured results are kept in.

`fdia-graph` generates a timeline and loads it. `fdia-analysis` is what is measured on one. It reads
the files through `fdia_graph.dataset` and builds on the generation toolkit's formulas and records;
`fdia_graph` never imports it, so the generation toolkit installs and runs without this one.

| package | holds |
|---|---|
| `fdia_analysis.se` | the state estimators (one solver, six estimators), the Jacobian features, and the alarm rules in `fdia_analysis.se.detect` |
| `fdia_analysis.localization` | the per-bus localizers: thresholds on the swing, the temporal change and the residual, and the learned ones |
| `fdia_analysis.federated` | the localizers and the estimator's prior trained over K clients that never pool their records |
| `fdia_analysis.trust` | trusted-meter selection and its scoring |
| `fdia_analysis.results` | the results store: a run's records with their provenance, and the renderers the docs read them through |
| `fdia_analysis.models` | the settings and score tables of the packages above |
| `fdia_analysis.formulas` | their mathematics, as pure functions |

## Install

| Install | Adds |
|---|---|
| `pip install fdia-analysis` | the toolkit and `fdia-graph`: the threshold localizers and the results store |
| `pip install "fdia-analysis[se]"` | pandapower and scipy, for `fdia_analysis.se` and the residual localizer |
| `pip install "fdia-analysis[torch]"` | torch, for the learned localizers and faster per-record inverses |
| `pip install "fdia-analysis[federated]"` | torch and scikit-learn, for `fdia_analysis.federated` |
| `pip install "fdia-analysis[all]"` | every extra above |

## One example

```python
import fdia_graph as fg
from fdia_analysis.models.config import PriorConfig
from fdia_analysis.se.methods import SubspacePrior  # pip install "fdia-analysis[se]"

train, test = fg.load("ieee118", split="train"), fg.load("ieee118", split="test")
est = SubspacePrior(prior=PriorConfig(rank_frac=0.5, reweight="huber", c=2.5)).fit(train)
print(est.score(test))  # angle and voltage error per attack family
```

The documentation is the repository's: the tutorial `docs/getting-started/analyse.md`, the pages
under `docs/analysis/` (one per study), `docs/guides/state_estimation.md`,
`docs/concepts/layers.md` for which layers an analysis may read, and `results/README.md` for the
results store.

## In this repository

The toolkit lives in `analysis/`: the package under `analysis/src/fdia_analysis`, its tests under
`analysis/tests` (they share the fixtures of the repository root's `conftest.py`, the tiny generated
timeline among them), and its own `pyproject.toml`. The tests run from the repository root, where
pytest is configured: `pytest analysis/tests` runs its suite and
`python tools/prereview.py` runs every gate of both toolkits.
