omega-lock 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.
- omega_lock-0.1.0/LICENSE +21 -0
- omega_lock-0.1.0/PKG-INFO +331 -0
- omega_lock-0.1.0/README.md +297 -0
- omega_lock-0.1.0/pyproject.toml +68 -0
- omega_lock-0.1.0/setup.cfg +4 -0
- omega_lock-0.1.0/src/omega_lock/__init__.py +68 -0
- omega_lock-0.1.0/src/omega_lock/adapters.py +89 -0
- omega_lock-0.1.0/src/omega_lock/benchmark.py +365 -0
- omega_lock-0.1.0/src/omega_lock/fitness.py +99 -0
- omega_lock-0.1.0/src/omega_lock/grid.py +275 -0
- omega_lock-0.1.0/src/omega_lock/keyholes/__init__.py +13 -0
- omega_lock-0.1.0/src/omega_lock/keyholes/phantom.py +178 -0
- omega_lock-0.1.0/src/omega_lock/keyholes/phantom_deep.py +265 -0
- omega_lock-0.1.0/src/omega_lock/kill_criteria.py +167 -0
- omega_lock-0.1.0/src/omega_lock/orchestrator.py +590 -0
- omega_lock-0.1.0/src/omega_lock/p2_tpe.py +395 -0
- omega_lock-0.1.0/src/omega_lock/params.py +103 -0
- omega_lock-0.1.0/src/omega_lock/random_search.py +196 -0
- omega_lock-0.1.0/src/omega_lock/stress.py +187 -0
- omega_lock-0.1.0/src/omega_lock/target.py +78 -0
- omega_lock-0.1.0/src/omega_lock/walk_forward.py +105 -0
- omega_lock-0.1.0/src/omega_lock.egg-info/PKG-INFO +331 -0
- omega_lock-0.1.0/src/omega_lock.egg-info/SOURCES.txt +40 -0
- omega_lock-0.1.0/src/omega_lock.egg-info/dependency_links.txt +1 -0
- omega_lock-0.1.0/src/omega_lock.egg-info/requires.txt +8 -0
- omega_lock-0.1.0/src/omega_lock.egg-info/top_level.txt +1 -0
- omega_lock-0.1.0/tests/test_adapters.py +105 -0
- omega_lock-0.1.0/tests/test_benchmark.py +212 -0
- omega_lock-0.1.0/tests/test_benchmark_regression.py +205 -0
- omega_lock-0.1.0/tests/test_fitness.py +116 -0
- omega_lock-0.1.0/tests/test_grid.py +82 -0
- omega_lock-0.1.0/tests/test_holdout.py +169 -0
- omega_lock-0.1.0/tests/test_integration_phantom.py +152 -0
- omega_lock-0.1.0/tests/test_integration_phantom_deep.py +204 -0
- omega_lock-0.1.0/tests/test_integration_rosenbrock.py +121 -0
- omega_lock-0.1.0/tests/test_iterative.py +182 -0
- omega_lock-0.1.0/tests/test_kill_criteria.py +99 -0
- omega_lock-0.1.0/tests/test_p2_tpe.py +303 -0
- omega_lock-0.1.0/tests/test_random_search.py +324 -0
- omega_lock-0.1.0/tests/test_sc2_advisory.py +97 -0
- omega_lock-0.1.0/tests/test_stress.py +157 -0
- omega_lock-0.1.0/tests/test_zooming.py +154 -0
omega_lock-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 hibou
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: omega-lock
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Sensitivity-driven coordinate descent calibration framework (stress → top-K unlock → grid → walk-forward)
|
|
5
|
+
Author: hibou
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/hibou04-ops/omega-lock
|
|
8
|
+
Project-URL: Repository, https://github.com/hibou04-ops/omega-lock
|
|
9
|
+
Project-URL: Issues, https://github.com/hibou04-ops/omega-lock/issues
|
|
10
|
+
Project-URL: Documentation, https://github.com/hibou04-ops/omega-lock#readme
|
|
11
|
+
Keywords: calibration,hyperparameter-optimization,sensitivity-analysis,walk-forward,overfitting-detection,coordinate-descent,kill-criteria,machine-learning,research
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Intended Audience :: Science/Research
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
22
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
23
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
24
|
+
Requires-Python: >=3.11
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
License-File: LICENSE
|
|
27
|
+
Requires-Dist: numpy>=1.24
|
|
28
|
+
Provides-Extra: dev
|
|
29
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
30
|
+
Requires-Dist: pytest-cov>=4.0; extra == "dev"
|
|
31
|
+
Provides-Extra: p2
|
|
32
|
+
Requires-Dist: optuna>=3.0; extra == "p2"
|
|
33
|
+
Dynamic: license-file
|
|
34
|
+
|
|
35
|
+
# Omega-Lock
|
|
36
|
+
|
|
37
|
+
[](https://pypi.org/project/omega-lock/)
|
|
38
|
+
[](https://pypi.org/project/omega-lock/)
|
|
39
|
+
[](https://opensource.org/licenses/MIT)
|
|
40
|
+
|
|
41
|
+
**Sensitivity-driven coordinate descent calibration framework.**
|
|
42
|
+
|
|
43
|
+
> "Use the keyhole as the mold." Lock every parameter tight. Unlock only those that push back hardest under perturbation. Grid-search the low-dimensional subspace, then validate with walk-forward to catch overfitting.
|
|
44
|
+
|
|
45
|
+
This package generalizes the methodology from `Omega_TB_1/research/omega_lock_p1/` (a v1 HeartCore target that ended in KC-4 FAIL) into a reusable library for arbitrary parameter-search problems. The original HeartCore experiment was not a "success" in the naive sense, it was a successful *overfitting detection*, which is exactly what this framework is designed to produce (see `archive/`).
|
|
46
|
+
|
|
47
|
+
한국어 README: **[README_KR.md](README_KR.md)**
|
|
48
|
+
|
|
49
|
+
## Table of Contents
|
|
50
|
+
|
|
51
|
+
- [Philosophy](#philosophy)
|
|
52
|
+
- [Pipeline](#pipeline)
|
|
53
|
+
- [Quick Start](#quick-start)
|
|
54
|
+
- [Kill Criteria](#kill-criteria-pre-declared)
|
|
55
|
+
- [Module Structure](#module-structure)
|
|
56
|
+
- [Search Strategy Comparison](#search-strategy-comparison)
|
|
57
|
+
- [vs External Alternatives](#vs-external-alternatives)
|
|
58
|
+
- [Holdout Target](#holdout-target)
|
|
59
|
+
- [Fractal-vise Mode](#fractal-vise-mode-multi-scale-refinement)
|
|
60
|
+
- [Tests](#tests)
|
|
61
|
+
- [Limitations](#limitations)
|
|
62
|
+
- [Roadmap](#roadmap-out-of-scope-for-this-package)
|
|
63
|
+
- [Citation](#citation)
|
|
64
|
+
- [License](#license)
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## Philosophy
|
|
69
|
+
|
|
70
|
+
Most parameter search suffers from the **curse of dimensionality**. You can hit a 22-dimensional space with random search or TPE, but if samples are scarce and evaluations are expensive, iterations run out and you converge on a Goodhart local optimum.
|
|
71
|
+
|
|
72
|
+
Omega-Lock makes three assumptions:
|
|
73
|
+
|
|
74
|
+
- **Effective dimension ≪ nominal dimension.** Most parameters don't meaningfully affect the result.
|
|
75
|
+
- Therefore, **measure sensitivity first** and only search the top-K.
|
|
76
|
+
- **Kill criteria must be pre-declared.** The experimenter cannot fudge thresholds post-hoc (Winchester prevention).
|
|
77
|
+
|
|
78
|
+
If these assumptions don't hold, Omega-Lock doesn't work. P1 HeartCore confirmed assumptions 1 and 2 but failed KC-4 in walk-forward, meaning even reduced to 3 dimensions, v1's signal layer was fundamentally overfit. That outcome was itself useful information.
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## Pipeline
|
|
83
|
+
|
|
84
|
+
```
|
|
85
|
+
target.evaluate(neutral_defaults) # baseline
|
|
86
|
+
↓
|
|
87
|
+
for each param: # stress measurement (KC-2)
|
|
88
|
+
perturb by ±ε, measure |Δfitness|/ε
|
|
89
|
+
↓
|
|
90
|
+
sort stress desc, pick top-K # unlock set
|
|
91
|
+
↓
|
|
92
|
+
grid search over K-dim subspace # train fitness
|
|
93
|
+
↓
|
|
94
|
+
walk-forward: top-N on test target # KC-4 (Pearson + trade ratio)
|
|
95
|
+
↓
|
|
96
|
+
[optional] hybrid validation: top-K with slower judge target
|
|
97
|
+
↓
|
|
98
|
+
KC-1 (time box) + KC-3 (action count floor)
|
|
99
|
+
↓
|
|
100
|
+
P1Result (JSON-serializable)
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## Quick Start
|
|
106
|
+
|
|
107
|
+
### 1. Install
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
# PyPI (recommended)
|
|
111
|
+
pip install omega-lock
|
|
112
|
+
|
|
113
|
+
# With optional Optuna TPE (P2) support
|
|
114
|
+
pip install "omega-lock[p2]"
|
|
115
|
+
|
|
116
|
+
# From source (development)
|
|
117
|
+
git clone https://github.com/hibou04-ops/omega-lock.git
|
|
118
|
+
cd omega-lock
|
|
119
|
+
pip install -e ".[dev]"
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### 2. Run the toy examples
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
python examples/rosenbrock_demo.py # 2D Rosenbrock — grid convergence sanity check
|
|
126
|
+
python examples/phantom_demo.py # 12-param synthetic keyhole — full P1 end-to-end
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
- `rosenbrock_demo.py` — 2D static function, no walk-forward / KC-4.
|
|
130
|
+
- `phantom_demo.py` — **`PhantomKeyhole`** (12 params: 3 effective + 9 decoy, seed-driven train / test / validation). Exercises stress → top-K unlock → grid → walk-forward → hybrid, with KC-1..4 all PASS. The reference keyhole for the framework.
|
|
131
|
+
|
|
132
|
+
### 3. Implement your own target
|
|
133
|
+
|
|
134
|
+
Implement the `CalibrableTarget` protocol:
|
|
135
|
+
|
|
136
|
+
```python
|
|
137
|
+
from omega_lock import CalibrableTarget, EvalResult, ParamSpec, P1Config, run_p1
|
|
138
|
+
|
|
139
|
+
class MyTarget:
|
|
140
|
+
def param_space(self) -> list[ParamSpec]:
|
|
141
|
+
return [
|
|
142
|
+
ParamSpec(name="threshold", dtype="float", low=0.0, high=1.0, neutral=0.5),
|
|
143
|
+
ParamSpec(name="window", dtype="int", low=10, high=100, neutral=50),
|
|
144
|
+
ParamSpec(name="use_cache", dtype="bool", neutral=False),
|
|
145
|
+
]
|
|
146
|
+
|
|
147
|
+
def evaluate(self, params: dict) -> EvalResult:
|
|
148
|
+
# ... your logic here ...
|
|
149
|
+
return EvalResult(
|
|
150
|
+
fitness=score, # scalar to maximize
|
|
151
|
+
n_trials=n_actions, # for KC-3
|
|
152
|
+
metadata={"mode": ...},
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
result = run_p1(train_target=MyTarget())
|
|
156
|
+
print(result.status) # "PASS" or "FAIL:KC-..."
|
|
157
|
+
print(result.grid_best["unlocked"])
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### 4. Walk-forward
|
|
161
|
+
|
|
162
|
+
For time-series targets, pass separate train / test targets:
|
|
163
|
+
|
|
164
|
+
```python
|
|
165
|
+
result = run_p1(
|
|
166
|
+
train_target=MyTarget(data=train_slice),
|
|
167
|
+
test_target=MyTarget(data=test_slice),
|
|
168
|
+
config=P1Config(trade_ratio_scale=len(test_slice) / len(train_slice)),
|
|
169
|
+
)
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### 5. Hybrid fitness (A+B pattern)
|
|
173
|
+
|
|
174
|
+
Search cheaply with A, re-validate the top-K with an expensive-but-accurate B:
|
|
175
|
+
|
|
176
|
+
```python
|
|
177
|
+
# A: fast heuristic (e.g. diversity score from history)
|
|
178
|
+
class FastTarget:
|
|
179
|
+
def param_space(self): return SHARED_SPECS
|
|
180
|
+
def evaluate(self, params): return EvalResult(fitness=cheap_score(params))
|
|
181
|
+
|
|
182
|
+
# B: slow judge (e.g. LLM rubric)
|
|
183
|
+
class JudgeTarget:
|
|
184
|
+
def param_space(self): return SHARED_SPECS
|
|
185
|
+
def evaluate(self, params): return EvalResult(fitness=gemini_judge(params))
|
|
186
|
+
|
|
187
|
+
result = run_p1(
|
|
188
|
+
train_target=FastTarget(),
|
|
189
|
+
validation_target=JudgeTarget(), # B re-evaluates only the top-K
|
|
190
|
+
config=P1Config(walk_forward_top_n=5),
|
|
191
|
+
)
|
|
192
|
+
# result.hybrid_top[0] is the #1 by B's score
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
## Kill Criteria (pre-declared)
|
|
198
|
+
|
|
199
|
+
| KC | Checked at | Default threshold | Purpose |
|
|
200
|
+
|----|-----------|-------------------|---------|
|
|
201
|
+
| KC-1 | end of run | elapsed ≤ 3 days | time box |
|
|
202
|
+
| KC-2 | after stress measurement | Gini ≥ 0.2, top/bot ratio ≥ 2.0 | differentiation guaranteed |
|
|
203
|
+
| KC-3 | final stage | baseline / train_best / test_best ≥ 50 trades | statistical power |
|
|
204
|
+
| KC-4 | after walk-forward | Pearson ≥ 0.3, trade_ratio ≥ 0.5 | overfitting defense |
|
|
205
|
+
|
|
206
|
+
All thresholds are overridable via the `KCThresholds` dataclass. Toy examples typically relax them (e.g. `trade_count_min=1`).
|
|
207
|
+
|
|
208
|
+
---
|
|
209
|
+
|
|
210
|
+
## Module Structure
|
|
211
|
+
|
|
212
|
+
```
|
|
213
|
+
src/omega_lock/
|
|
214
|
+
├── target.py # CalibrableTarget Protocol + ParamSpec + EvalResult
|
|
215
|
+
├── params.py # LockedParams + clip / default_epsilon
|
|
216
|
+
├── stress.py # measure_stress + gini + select_unlock_top_k
|
|
217
|
+
├── grid.py # GridSearch + ZoomingGridSearch + grid_points(_in)
|
|
218
|
+
├── random_search.py # RandomSearch + top_quartile_fitness + compare_to_grid (SC-2)
|
|
219
|
+
├── walk_forward.py # WalkForward + pearson
|
|
220
|
+
├── fitness.py # BaseFitness + HybridFitness
|
|
221
|
+
├── kill_criteria.py # KCThresholds + check_kc1..4
|
|
222
|
+
├── orchestrator.py # run_p1() + run_p1_iterative() (+ holdout support)
|
|
223
|
+
├── p2_tpe.py # run_p2_tpe() — Optuna TPE continuous-space optimizer (optional dep)
|
|
224
|
+
└── keyholes/
|
|
225
|
+
├── phantom.py # PhantomKeyhole — effective_dim 3 / nominal 12 (happy-path demo)
|
|
226
|
+
└── phantom_deep.py # PhantomKeyholeDeep — effective_dim 6 / nominal 20 (iteration required)
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
## Search Strategy Comparison
|
|
230
|
+
|
|
231
|
+
| Method | Continuity | Resolution | Use case |
|
|
232
|
+
|---|---|---|---|
|
|
233
|
+
| `GridSearch` | discrete | 1 round × $n^K$ | fast first pass |
|
|
234
|
+
| `ZoomingGridSearch` | discrete (geometric shrink) | $n^K \times r$ rounds | refine beyond grid lattice |
|
|
235
|
+
| `RandomSearch` | mixed discrete / continuous | same-budget random sampling | SC-2 baseline (grid top-q ≥ 1.5× random) |
|
|
236
|
+
| `run_p2_tpe` (Optuna) | fully continuous | TPE adaptive | true continuous-space optimizer, optional `pip install "omega-lock[p2]"` |
|
|
237
|
+
|
|
238
|
+
## vs External Alternatives
|
|
239
|
+
|
|
240
|
+
| Tool | Approach | Omega-Lock's difference |
|
|
241
|
+
|---|---|---|
|
|
242
|
+
| Optuna / Hyperopt (TPE) | Bayesian adaptive sampling, full-dim | Omega-Lock fixes a top-K subspace via stress *before* sampling. When `effective_dim ≪ nominal_dim` holds, sample efficiency dominates. Complementary, wrap TPE via `run_p2_tpe`. |
|
|
243
|
+
| Ray Tune / scikit-optimize | general-purpose HPO frameworks | single fitness, no built-in walk-forward / overfit gate. Omega-Lock makes KC-4 (Pearson + trade_ratio) a required gate. |
|
|
244
|
+
| Plain grid search | exhaustive | high-dim explosion ($n^D$). Omega-Lock reduces to $n^K$ via stress → top-K unlock. |
|
|
245
|
+
| Nelder-Mead / Powell | local continuous search | continuous-only, no categoricals or bools. Omega-Lock handles mixed int / bool / continuous. |
|
|
246
|
+
|
|
247
|
+
**Omega-Lock's USP**: *pre-declared kill criteria + low-dim subspace hypothesis.* Not another adaptive-sampling optimizer, a **methodology framework**. Ideally layered on top of existing optimizers (TPE / Bayesian / Genetic); `run_p2_tpe` is the reference example.
|
|
248
|
+
|
|
249
|
+
## Holdout Target
|
|
250
|
+
|
|
251
|
+
Pass a third target that is *never touched during rounds* via `run_p1(..., holdout_target=T3)` or `run_p1_iterative(..., holdout_target=T3)`. The final `grid_best` or `final_baseline` is evaluated on it exactly once, and the result is recorded in `holdout_result`. This is an honest auxiliary check, in iterative mode the test_set gets reused for lock-in decisions round after round, which weakens KC-4 evidence.
|
|
252
|
+
|
|
253
|
+
## Fractal-vise Mode (multi-scale refinement)
|
|
254
|
+
|
|
255
|
+
Think of a fractal vise: a large segment clamps the object first (round 1 lock-in), then smaller segments conform within that coordinate system (zooming within a round, or the next round on remaining params).
|
|
256
|
+
|
|
257
|
+
Two independent axes:
|
|
258
|
+
|
|
259
|
+
1. **Iterative lock-in** (`run_p1_iterative` + `IterativeConfig`):
|
|
260
|
+
After round 1 unlocks top-K and locks the grid-best, round 2 re-measures stress on the remaining params, and so on. Valuable when `effective_dim > unlock_k`.
|
|
261
|
+
|
|
262
|
+
2. **Zooming grid** (`ZoomingGridSearch`, or `P1Config(zoom_rounds=N)`):
|
|
263
|
+
Within a single round, the grid shrinks geometrically around the previous winner. Reaches finer values (e.g. `alpha=0.4375`) that the initial discrete grid (e.g. `alpha=0.5`) cannot. Roughly 4× error reduction every two zoom rounds.
|
|
264
|
+
|
|
265
|
+
The two axes compose: `run_p1_iterative(config=IterativeConfig(rounds=3, zoom_rounds=4))` is the full fractal vise. On `PhantomKeyhole`, plain grid (`alpha=0.5`, fitness=12.0) vs. fractal (`alpha=0.4375`, fitness=13.0) makes the contrast visible.
|
|
266
|
+
|
|
267
|
+
**Warning**: KC thresholds are strictly enforced every round, Winchester prevention. Because `test_set` is reused across rounds, `KC-4` PASS becomes weaker evidence as rounds deepen. In practice, splitting out a hold-out set is recommended.
|
|
268
|
+
|
|
269
|
+
---
|
|
270
|
+
|
|
271
|
+
## Tests
|
|
272
|
+
|
|
273
|
+
```bash
|
|
274
|
+
pip install -e ".[dev]"
|
|
275
|
+
pytest tests/ # all
|
|
276
|
+
pytest tests/test_stress.py -v # single module
|
|
277
|
+
pytest --cov=omega_lock # coverage
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
---
|
|
281
|
+
|
|
282
|
+
## Limitations
|
|
283
|
+
|
|
284
|
+
- **Determinism assumption.** Stress measurement is accurate only when the target is deterministic. For non-deterministic targets, fix the seed or average multiple evaluations.
|
|
285
|
+
- **OFI-biased parameters.** If a parameter's stress is artificially low due to environmental constraints, mark it with `ParamSpec(ofi_biased=True)`. It gets flagged in results but not auto-filtered (observational only).
|
|
286
|
+
- **Continuous + int mixed.** Epsilon is type-aware (continuous = 10% of range, int = 1, bool = flip). Override via `StressOptions(epsilons={...})`.
|
|
287
|
+
- **Grid dimension explosion.** K=3 / 5 points-per-axis = 125 combos. For larger K, adaptive search like Optuna TPE is better (currently outside P2 TPE's scope; future enhancement).
|
|
288
|
+
|
|
289
|
+
---
|
|
290
|
+
|
|
291
|
+
## Roadmap (out of scope for this package)
|
|
292
|
+
|
|
293
|
+
- **Omega_X adapter** — `adapters/omega_x/` implementing `SelectorTarget`, `ValidationTarget` for X thread pipeline calibration.
|
|
294
|
+
- **P2 Optuna TPE** — `orchestrator.run_p2()`, adaptive search instead of grid.
|
|
295
|
+
- **P3 enrichment** — faithful OFI reconstruction from bookDepth / aggTrades (HeartCore-specific).
|
|
296
|
+
- **Random-search baseline** — actually compare SC-2 "top-quartile ≥ 1.5× random" (missed in P1).
|
|
297
|
+
|
|
298
|
+
---
|
|
299
|
+
|
|
300
|
+
## Citation
|
|
301
|
+
|
|
302
|
+
If you use Omega-Lock in research or a published project, please cite:
|
|
303
|
+
|
|
304
|
+
```bibtex
|
|
305
|
+
@software{omega_lock_2026,
|
|
306
|
+
author = {hibou},
|
|
307
|
+
title = {Omega-Lock: Sensitivity-driven coordinate descent calibration framework},
|
|
308
|
+
year = {2026},
|
|
309
|
+
version = {0.1.0},
|
|
310
|
+
url = {https://github.com/hibou04-ops/omega-lock}
|
|
311
|
+
}
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
---
|
|
315
|
+
|
|
316
|
+
## Archive (private, not in public repo)
|
|
317
|
+
|
|
318
|
+
The methodological origin, **Omega-Lock P1 HeartCore** applied case (2026-04-13 to 04-14), lives in a separate local `archive/` directory (gitignored).
|
|
319
|
+
|
|
320
|
+
- `P1_HeartCore_SPEC.md` — original design document for the 21-param v1 HeartCore target.
|
|
321
|
+
- `P1_HeartCore_RESULT.md` — KC-4 FAIL report (Pearson 0.119, successful train/test overfit detection).
|
|
322
|
+
|
|
323
|
+
Both documents are **immutable**, preserved as the **first recorded case** of the methodology detecting overfitting as intended. Not publicly released (Omega_TB_1 internal research + BTCUSDT real-data references).
|
|
324
|
+
|
|
325
|
+
---
|
|
326
|
+
|
|
327
|
+
## License
|
|
328
|
+
|
|
329
|
+
MIT License. See [LICENSE](LICENSE) for details.
|
|
330
|
+
|
|
331
|
+
Copyright (c) 2026 hibou.
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
# Omega-Lock
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/omega-lock/)
|
|
4
|
+
[](https://pypi.org/project/omega-lock/)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
|
|
7
|
+
**Sensitivity-driven coordinate descent calibration framework.**
|
|
8
|
+
|
|
9
|
+
> "Use the keyhole as the mold." Lock every parameter tight. Unlock only those that push back hardest under perturbation. Grid-search the low-dimensional subspace, then validate with walk-forward to catch overfitting.
|
|
10
|
+
|
|
11
|
+
This package generalizes the methodology from `Omega_TB_1/research/omega_lock_p1/` (a v1 HeartCore target that ended in KC-4 FAIL) into a reusable library for arbitrary parameter-search problems. The original HeartCore experiment was not a "success" in the naive sense, it was a successful *overfitting detection*, which is exactly what this framework is designed to produce (see `archive/`).
|
|
12
|
+
|
|
13
|
+
한국어 README: **[README_KR.md](README_KR.md)**
|
|
14
|
+
|
|
15
|
+
## Table of Contents
|
|
16
|
+
|
|
17
|
+
- [Philosophy](#philosophy)
|
|
18
|
+
- [Pipeline](#pipeline)
|
|
19
|
+
- [Quick Start](#quick-start)
|
|
20
|
+
- [Kill Criteria](#kill-criteria-pre-declared)
|
|
21
|
+
- [Module Structure](#module-structure)
|
|
22
|
+
- [Search Strategy Comparison](#search-strategy-comparison)
|
|
23
|
+
- [vs External Alternatives](#vs-external-alternatives)
|
|
24
|
+
- [Holdout Target](#holdout-target)
|
|
25
|
+
- [Fractal-vise Mode](#fractal-vise-mode-multi-scale-refinement)
|
|
26
|
+
- [Tests](#tests)
|
|
27
|
+
- [Limitations](#limitations)
|
|
28
|
+
- [Roadmap](#roadmap-out-of-scope-for-this-package)
|
|
29
|
+
- [Citation](#citation)
|
|
30
|
+
- [License](#license)
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## Philosophy
|
|
35
|
+
|
|
36
|
+
Most parameter search suffers from the **curse of dimensionality**. You can hit a 22-dimensional space with random search or TPE, but if samples are scarce and evaluations are expensive, iterations run out and you converge on a Goodhart local optimum.
|
|
37
|
+
|
|
38
|
+
Omega-Lock makes three assumptions:
|
|
39
|
+
|
|
40
|
+
- **Effective dimension ≪ nominal dimension.** Most parameters don't meaningfully affect the result.
|
|
41
|
+
- Therefore, **measure sensitivity first** and only search the top-K.
|
|
42
|
+
- **Kill criteria must be pre-declared.** The experimenter cannot fudge thresholds post-hoc (Winchester prevention).
|
|
43
|
+
|
|
44
|
+
If these assumptions don't hold, Omega-Lock doesn't work. P1 HeartCore confirmed assumptions 1 and 2 but failed KC-4 in walk-forward, meaning even reduced to 3 dimensions, v1's signal layer was fundamentally overfit. That outcome was itself useful information.
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## Pipeline
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
target.evaluate(neutral_defaults) # baseline
|
|
52
|
+
↓
|
|
53
|
+
for each param: # stress measurement (KC-2)
|
|
54
|
+
perturb by ±ε, measure |Δfitness|/ε
|
|
55
|
+
↓
|
|
56
|
+
sort stress desc, pick top-K # unlock set
|
|
57
|
+
↓
|
|
58
|
+
grid search over K-dim subspace # train fitness
|
|
59
|
+
↓
|
|
60
|
+
walk-forward: top-N on test target # KC-4 (Pearson + trade ratio)
|
|
61
|
+
↓
|
|
62
|
+
[optional] hybrid validation: top-K with slower judge target
|
|
63
|
+
↓
|
|
64
|
+
KC-1 (time box) + KC-3 (action count floor)
|
|
65
|
+
↓
|
|
66
|
+
P1Result (JSON-serializable)
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## Quick Start
|
|
72
|
+
|
|
73
|
+
### 1. Install
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
# PyPI (recommended)
|
|
77
|
+
pip install omega-lock
|
|
78
|
+
|
|
79
|
+
# With optional Optuna TPE (P2) support
|
|
80
|
+
pip install "omega-lock[p2]"
|
|
81
|
+
|
|
82
|
+
# From source (development)
|
|
83
|
+
git clone https://github.com/hibou04-ops/omega-lock.git
|
|
84
|
+
cd omega-lock
|
|
85
|
+
pip install -e ".[dev]"
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### 2. Run the toy examples
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
python examples/rosenbrock_demo.py # 2D Rosenbrock — grid convergence sanity check
|
|
92
|
+
python examples/phantom_demo.py # 12-param synthetic keyhole — full P1 end-to-end
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
- `rosenbrock_demo.py` — 2D static function, no walk-forward / KC-4.
|
|
96
|
+
- `phantom_demo.py` — **`PhantomKeyhole`** (12 params: 3 effective + 9 decoy, seed-driven train / test / validation). Exercises stress → top-K unlock → grid → walk-forward → hybrid, with KC-1..4 all PASS. The reference keyhole for the framework.
|
|
97
|
+
|
|
98
|
+
### 3. Implement your own target
|
|
99
|
+
|
|
100
|
+
Implement the `CalibrableTarget` protocol:
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
from omega_lock import CalibrableTarget, EvalResult, ParamSpec, P1Config, run_p1
|
|
104
|
+
|
|
105
|
+
class MyTarget:
|
|
106
|
+
def param_space(self) -> list[ParamSpec]:
|
|
107
|
+
return [
|
|
108
|
+
ParamSpec(name="threshold", dtype="float", low=0.0, high=1.0, neutral=0.5),
|
|
109
|
+
ParamSpec(name="window", dtype="int", low=10, high=100, neutral=50),
|
|
110
|
+
ParamSpec(name="use_cache", dtype="bool", neutral=False),
|
|
111
|
+
]
|
|
112
|
+
|
|
113
|
+
def evaluate(self, params: dict) -> EvalResult:
|
|
114
|
+
# ... your logic here ...
|
|
115
|
+
return EvalResult(
|
|
116
|
+
fitness=score, # scalar to maximize
|
|
117
|
+
n_trials=n_actions, # for KC-3
|
|
118
|
+
metadata={"mode": ...},
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
result = run_p1(train_target=MyTarget())
|
|
122
|
+
print(result.status) # "PASS" or "FAIL:KC-..."
|
|
123
|
+
print(result.grid_best["unlocked"])
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### 4. Walk-forward
|
|
127
|
+
|
|
128
|
+
For time-series targets, pass separate train / test targets:
|
|
129
|
+
|
|
130
|
+
```python
|
|
131
|
+
result = run_p1(
|
|
132
|
+
train_target=MyTarget(data=train_slice),
|
|
133
|
+
test_target=MyTarget(data=test_slice),
|
|
134
|
+
config=P1Config(trade_ratio_scale=len(test_slice) / len(train_slice)),
|
|
135
|
+
)
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### 5. Hybrid fitness (A+B pattern)
|
|
139
|
+
|
|
140
|
+
Search cheaply with A, re-validate the top-K with an expensive-but-accurate B:
|
|
141
|
+
|
|
142
|
+
```python
|
|
143
|
+
# A: fast heuristic (e.g. diversity score from history)
|
|
144
|
+
class FastTarget:
|
|
145
|
+
def param_space(self): return SHARED_SPECS
|
|
146
|
+
def evaluate(self, params): return EvalResult(fitness=cheap_score(params))
|
|
147
|
+
|
|
148
|
+
# B: slow judge (e.g. LLM rubric)
|
|
149
|
+
class JudgeTarget:
|
|
150
|
+
def param_space(self): return SHARED_SPECS
|
|
151
|
+
def evaluate(self, params): return EvalResult(fitness=gemini_judge(params))
|
|
152
|
+
|
|
153
|
+
result = run_p1(
|
|
154
|
+
train_target=FastTarget(),
|
|
155
|
+
validation_target=JudgeTarget(), # B re-evaluates only the top-K
|
|
156
|
+
config=P1Config(walk_forward_top_n=5),
|
|
157
|
+
)
|
|
158
|
+
# result.hybrid_top[0] is the #1 by B's score
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
---
|
|
162
|
+
|
|
163
|
+
## Kill Criteria (pre-declared)
|
|
164
|
+
|
|
165
|
+
| KC | Checked at | Default threshold | Purpose |
|
|
166
|
+
|----|-----------|-------------------|---------|
|
|
167
|
+
| KC-1 | end of run | elapsed ≤ 3 days | time box |
|
|
168
|
+
| KC-2 | after stress measurement | Gini ≥ 0.2, top/bot ratio ≥ 2.0 | differentiation guaranteed |
|
|
169
|
+
| KC-3 | final stage | baseline / train_best / test_best ≥ 50 trades | statistical power |
|
|
170
|
+
| KC-4 | after walk-forward | Pearson ≥ 0.3, trade_ratio ≥ 0.5 | overfitting defense |
|
|
171
|
+
|
|
172
|
+
All thresholds are overridable via the `KCThresholds` dataclass. Toy examples typically relax them (e.g. `trade_count_min=1`).
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## Module Structure
|
|
177
|
+
|
|
178
|
+
```
|
|
179
|
+
src/omega_lock/
|
|
180
|
+
├── target.py # CalibrableTarget Protocol + ParamSpec + EvalResult
|
|
181
|
+
├── params.py # LockedParams + clip / default_epsilon
|
|
182
|
+
├── stress.py # measure_stress + gini + select_unlock_top_k
|
|
183
|
+
├── grid.py # GridSearch + ZoomingGridSearch + grid_points(_in)
|
|
184
|
+
├── random_search.py # RandomSearch + top_quartile_fitness + compare_to_grid (SC-2)
|
|
185
|
+
├── walk_forward.py # WalkForward + pearson
|
|
186
|
+
├── fitness.py # BaseFitness + HybridFitness
|
|
187
|
+
├── kill_criteria.py # KCThresholds + check_kc1..4
|
|
188
|
+
├── orchestrator.py # run_p1() + run_p1_iterative() (+ holdout support)
|
|
189
|
+
├── p2_tpe.py # run_p2_tpe() — Optuna TPE continuous-space optimizer (optional dep)
|
|
190
|
+
└── keyholes/
|
|
191
|
+
├── phantom.py # PhantomKeyhole — effective_dim 3 / nominal 12 (happy-path demo)
|
|
192
|
+
└── phantom_deep.py # PhantomKeyholeDeep — effective_dim 6 / nominal 20 (iteration required)
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
## Search Strategy Comparison
|
|
196
|
+
|
|
197
|
+
| Method | Continuity | Resolution | Use case |
|
|
198
|
+
|---|---|---|---|
|
|
199
|
+
| `GridSearch` | discrete | 1 round × $n^K$ | fast first pass |
|
|
200
|
+
| `ZoomingGridSearch` | discrete (geometric shrink) | $n^K \times r$ rounds | refine beyond grid lattice |
|
|
201
|
+
| `RandomSearch` | mixed discrete / continuous | same-budget random sampling | SC-2 baseline (grid top-q ≥ 1.5× random) |
|
|
202
|
+
| `run_p2_tpe` (Optuna) | fully continuous | TPE adaptive | true continuous-space optimizer, optional `pip install "omega-lock[p2]"` |
|
|
203
|
+
|
|
204
|
+
## vs External Alternatives
|
|
205
|
+
|
|
206
|
+
| Tool | Approach | Omega-Lock's difference |
|
|
207
|
+
|---|---|---|
|
|
208
|
+
| Optuna / Hyperopt (TPE) | Bayesian adaptive sampling, full-dim | Omega-Lock fixes a top-K subspace via stress *before* sampling. When `effective_dim ≪ nominal_dim` holds, sample efficiency dominates. Complementary, wrap TPE via `run_p2_tpe`. |
|
|
209
|
+
| Ray Tune / scikit-optimize | general-purpose HPO frameworks | single fitness, no built-in walk-forward / overfit gate. Omega-Lock makes KC-4 (Pearson + trade_ratio) a required gate. |
|
|
210
|
+
| Plain grid search | exhaustive | high-dim explosion ($n^D$). Omega-Lock reduces to $n^K$ via stress → top-K unlock. |
|
|
211
|
+
| Nelder-Mead / Powell | local continuous search | continuous-only, no categoricals or bools. Omega-Lock handles mixed int / bool / continuous. |
|
|
212
|
+
|
|
213
|
+
**Omega-Lock's USP**: *pre-declared kill criteria + low-dim subspace hypothesis.* Not another adaptive-sampling optimizer, a **methodology framework**. Ideally layered on top of existing optimizers (TPE / Bayesian / Genetic); `run_p2_tpe` is the reference example.
|
|
214
|
+
|
|
215
|
+
## Holdout Target
|
|
216
|
+
|
|
217
|
+
Pass a third target that is *never touched during rounds* via `run_p1(..., holdout_target=T3)` or `run_p1_iterative(..., holdout_target=T3)`. The final `grid_best` or `final_baseline` is evaluated on it exactly once, and the result is recorded in `holdout_result`. This is an honest auxiliary check, in iterative mode the test_set gets reused for lock-in decisions round after round, which weakens KC-4 evidence.
|
|
218
|
+
|
|
219
|
+
## Fractal-vise Mode (multi-scale refinement)
|
|
220
|
+
|
|
221
|
+
Think of a fractal vise: a large segment clamps the object first (round 1 lock-in), then smaller segments conform within that coordinate system (zooming within a round, or the next round on remaining params).
|
|
222
|
+
|
|
223
|
+
Two independent axes:
|
|
224
|
+
|
|
225
|
+
1. **Iterative lock-in** (`run_p1_iterative` + `IterativeConfig`):
|
|
226
|
+
After round 1 unlocks top-K and locks the grid-best, round 2 re-measures stress on the remaining params, and so on. Valuable when `effective_dim > unlock_k`.
|
|
227
|
+
|
|
228
|
+
2. **Zooming grid** (`ZoomingGridSearch`, or `P1Config(zoom_rounds=N)`):
|
|
229
|
+
Within a single round, the grid shrinks geometrically around the previous winner. Reaches finer values (e.g. `alpha=0.4375`) that the initial discrete grid (e.g. `alpha=0.5`) cannot. Roughly 4× error reduction every two zoom rounds.
|
|
230
|
+
|
|
231
|
+
The two axes compose: `run_p1_iterative(config=IterativeConfig(rounds=3, zoom_rounds=4))` is the full fractal vise. On `PhantomKeyhole`, plain grid (`alpha=0.5`, fitness=12.0) vs. fractal (`alpha=0.4375`, fitness=13.0) makes the contrast visible.
|
|
232
|
+
|
|
233
|
+
**Warning**: KC thresholds are strictly enforced every round, Winchester prevention. Because `test_set` is reused across rounds, `KC-4` PASS becomes weaker evidence as rounds deepen. In practice, splitting out a hold-out set is recommended.
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
237
|
+
## Tests
|
|
238
|
+
|
|
239
|
+
```bash
|
|
240
|
+
pip install -e ".[dev]"
|
|
241
|
+
pytest tests/ # all
|
|
242
|
+
pytest tests/test_stress.py -v # single module
|
|
243
|
+
pytest --cov=omega_lock # coverage
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
---
|
|
247
|
+
|
|
248
|
+
## Limitations
|
|
249
|
+
|
|
250
|
+
- **Determinism assumption.** Stress measurement is accurate only when the target is deterministic. For non-deterministic targets, fix the seed or average multiple evaluations.
|
|
251
|
+
- **OFI-biased parameters.** If a parameter's stress is artificially low due to environmental constraints, mark it with `ParamSpec(ofi_biased=True)`. It gets flagged in results but not auto-filtered (observational only).
|
|
252
|
+
- **Continuous + int mixed.** Epsilon is type-aware (continuous = 10% of range, int = 1, bool = flip). Override via `StressOptions(epsilons={...})`.
|
|
253
|
+
- **Grid dimension explosion.** K=3 / 5 points-per-axis = 125 combos. For larger K, adaptive search like Optuna TPE is better (currently outside P2 TPE's scope; future enhancement).
|
|
254
|
+
|
|
255
|
+
---
|
|
256
|
+
|
|
257
|
+
## Roadmap (out of scope for this package)
|
|
258
|
+
|
|
259
|
+
- **Omega_X adapter** — `adapters/omega_x/` implementing `SelectorTarget`, `ValidationTarget` for X thread pipeline calibration.
|
|
260
|
+
- **P2 Optuna TPE** — `orchestrator.run_p2()`, adaptive search instead of grid.
|
|
261
|
+
- **P3 enrichment** — faithful OFI reconstruction from bookDepth / aggTrades (HeartCore-specific).
|
|
262
|
+
- **Random-search baseline** — actually compare SC-2 "top-quartile ≥ 1.5× random" (missed in P1).
|
|
263
|
+
|
|
264
|
+
---
|
|
265
|
+
|
|
266
|
+
## Citation
|
|
267
|
+
|
|
268
|
+
If you use Omega-Lock in research or a published project, please cite:
|
|
269
|
+
|
|
270
|
+
```bibtex
|
|
271
|
+
@software{omega_lock_2026,
|
|
272
|
+
author = {hibou},
|
|
273
|
+
title = {Omega-Lock: Sensitivity-driven coordinate descent calibration framework},
|
|
274
|
+
year = {2026},
|
|
275
|
+
version = {0.1.0},
|
|
276
|
+
url = {https://github.com/hibou04-ops/omega-lock}
|
|
277
|
+
}
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
---
|
|
281
|
+
|
|
282
|
+
## Archive (private, not in public repo)
|
|
283
|
+
|
|
284
|
+
The methodological origin, **Omega-Lock P1 HeartCore** applied case (2026-04-13 to 04-14), lives in a separate local `archive/` directory (gitignored).
|
|
285
|
+
|
|
286
|
+
- `P1_HeartCore_SPEC.md` — original design document for the 21-param v1 HeartCore target.
|
|
287
|
+
- `P1_HeartCore_RESULT.md` — KC-4 FAIL report (Pearson 0.119, successful train/test overfit detection).
|
|
288
|
+
|
|
289
|
+
Both documents are **immutable**, preserved as the **first recorded case** of the methodology detecting overfitting as intended. Not publicly released (Omega_TB_1 internal research + BTCUSDT real-data references).
|
|
290
|
+
|
|
291
|
+
---
|
|
292
|
+
|
|
293
|
+
## License
|
|
294
|
+
|
|
295
|
+
MIT License. See [LICENSE](LICENSE) for details.
|
|
296
|
+
|
|
297
|
+
Copyright (c) 2026 hibou.
|