Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
220 changes: 220 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[codz]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py.cover
*.lcov
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
# Pipfile.lock

# UV
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# uv.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
# poetry.lock
# poetry.toml

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
# pdm.lock
# pdm.toml
.pdm-python
.pdm-build/

# pixi
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
# pixi.lock
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
# in the .venv directory. It is recommended not to include this directory in version control.
.pixi/*
!.pixi/config.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule*
celerybeat.pid

# Redis
*.rdb
*.aof
*.pid

# RabbitMQ
mnesia/
rabbitmq/
rabbitmq-data/

# ActiveMQ
activemq-data/

# SageMath parsed files
*.sage.py

# Environments
.env
.envrc
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
# .idea/

# Abstra
# Abstra is an AI-powered process automation framework.
# Ignore directories containing user credentials, local state, and settings.
# Learn more at https://abstra.io/docs
.abstra/

# Visual Studio Code
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
# and can be added to the global gitignore or merged into this file. However, if you prefer,
# you could uncomment the following to ignore the entire vscode folder
# .vscode/
# Temporary file for partial code execution
tempCodeRunnerFile.py

# Ruff stuff:
.ruff_cache/

# PyPI configuration file
.pypirc

# Marimo
marimo/_static/
marimo/_lsp/
__marimo__/

# Streamlit
.streamlit/secrets.toml
90 changes: 90 additions & 0 deletions EXPERIMENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Experiments
A running log of every validation run, benchmark, and cross-domain test for CNSD.

**Discipline for this file** (so it stays a record, not a trophy case):
- Every entry is tied to a **commit** and a **fixed seed**. The commit's git timestamp is the authoritative date — no manually entered dates.
- The **run record** (command, commit, environment, config, sample counts) is **auto-generated by the run script** and pasted in verbatim — not transcribed by hand.
- The experiment and its purpose are stated *before* the result.
- Null, weak, and unflattering results (abstention rates, accuracy drops, limitations) are recorded alongside the headline numbers.
- Each entry carries a status: `planned` · `running` · `preliminary` · `validated` · `superseded`.

**How to reproduce any entry**: check out the commit in its run record, prepare the dataset as described in `data/README` (layout + expected sample count / checksum), install the pinned environment (`requirements.txt`), and run the exact command shown in the run record. Numbers should match within run-to-run noise (seeds are fixed; minor GPU nondeterminism is expected).

---

## Index

| # | Experiment | Domain | Status |
|---|------------|--------|--------|
| 1 | CWRU baseline (Protocol B) | Bearing (CWRU) | preliminary |
| 2 | Threshold sweep | Bearing (CWRU) | preliminary |
| 3 | Cross-condition robustness (AWGN) | Bearing (CWRU) | preliminary |
| 4 | Multi-seed headline | Bearing (CWRU) | planned |
| 5 | Cross-domain: SEU gearbox | Gear (SEU) | preliminary (failed) |

---

## 1. CWRU baseline — Protocol B (cross-load)

* **Status:** preliminary
* **Purpose:** confirm the full five-layer pipeline runs end-to-end on real CWRU and establish the baseline diagnosis result.
* **Setup:** train loads 0–2, test load 3. All 10 classes. 12 kHz, window 1024.

**Run record**
```text
commit: cd7771ab3668caf9b33109c3a0a9d89f24fd111c
command: python validate_run.py --seed 42
data: 5806 train / 2019 test samples
```

**Layer-2 physics verification rate**
| Verdict | Rate |
|---------|------|
| CONFIRMED | TBD |
| CONFLICT | TBD |
| INCONCLUSIVE | TBD |

**Headline — CNN accuracy by physics verdict**
| Verdict | n | CNN accuracy |
|---------|---|--------------|
| CONFIRMED | TBD | TBD |
| CONFLICT | TBD | TBD |
| INCONCLUSIVE | TBD | TBD |
| **Gap (CONFIRMED - CONFLICT)** | | **TBD** |

* **Causal (Layer 3)** — `do(Z)`: rung *TBD*, max_contrast *TBD*, p *TBD*
* **Counterfactual (Layer 3B)**: DoWhy available *TBD*; method *TBD*
* **Notes / limitations**: record the INCONCLUSIVE rate and any seed drift.

---

## 5. Cross-domain — SEU gearbox (GearProvider)

* **Status:** preliminary (failed validation)
* **Purpose:** demonstrate the framework is genuinely domain-agnostic — same engine, different machine class, only the provider changes.
* **Setup:** full pipeline on SEU gearset using `GearProvider` (gear-mesh physics). `N_TEETH_INPUT` confirmed against rig spec; fixed channel chosen up front; threshold tuned on a held-out split.

**Run record**
```text
commit: <PENDING PR 12 MERGE>
command: python validate_seu.py
data: 5115 train / 5115 test samples
n_teeth_input: 20 | channel: 2 (planetary x-axis)
```

**Layer-2 physics verification rate**
| Verdict | Rate |
|---------|------|
| CONFIRMED | 0.2% |
| CONFLICT | 0.3% |
| INCONCLUSIVE | 99.5% |

**Headline — CNN accuracy by physics verdict**
| Verdict | n | CNN accuracy |
|---------|---|--------------|
| CONFIRMED | 9 | 0.333 |
| CONFLICT | 17 | 0.824 |
| INCONCLUSIVE | 5089 | 0.514 |
| **Gap (CONFIRMED - CONFLICT)** | | **-0.491 (FAILED)** |

* **Known caveats to report honestly:** The accuracy gap is currently backwards and practically noise due to a 99.5% inconclusive rate. This is pending a strict `tau` threshold calibration sweep for gear physics, as well as confirming that GMF strength aligns with the same numerical scale as bearing physics.
9 changes: 9 additions & 0 deletions cnsd/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ def build_provider(config):
cond_to_rpm = _coerce_int_keys(params.get('motor_load_rpm', {0: 1797}))
return provider_cls(bearing=geometry, cond_to_rpm=cond_to_rpm, fs=fs)

if domain_type == 'gear':
cond_to_rpm = _coerce_int_keys(params.get('motor_load_rpm', {0: 1800}))
return provider_cls(
n_teeth_input=params['n_teeth_input'],
n_teeth_output=params.get('n_teeth_output'),
cond_to_rpm=cond_to_rpm,
fs=fs,
)

# other registered domains: pass parameters through + fs
try:
return provider_cls(fs=fs, **params)
Expand Down
9 changes: 7 additions & 2 deletions cnsd/physics/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

@dataclass
class PhysicsConfig:
bearing: dict[str, float]
cond_to_rpm: dict
fs: int
bearing: dict[str, float] | None = None
name: str = 'custom'


Expand All @@ -25,4 +25,9 @@ class PhysicsConfig:
name='JNU-N205',
)

SEU_PHYSICS = None
SEU_PHYSICS = PhysicsConfig(
bearing=None,
cond_to_rpm={0: 1200, 1: 1800},
fs=20000,
name='SEU-Gearbox',
)
Loading
Loading