Metadata-Version: 2.4
Name: calibrated-bo
Version: 0.2.0
Summary: Calibrated Bayesian optimization with composable conformal prediction (Weighted + Localized + Adaptive) on top of bayesian-gp-cvloss.
Author-email: Shifa Zhong <sfzhong@tongji.edu.cn>
License-Expression: MIT
Project-URL: Repository, https://github.com/Shifa-Zhong/calibrated-bo
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: bayesian-gp-cvloss>=0.3.1
Requires-Dist: numpy>=1.18.0
Requires-Dist: scipy>=1.5.0
Requires-Dist: scikit-learn>=0.23.0
Dynamic: license-file

# calibrated-bo

Calibrated Bayesian optimization with composable conformal prediction, built
on top of [`bayesian-gp-cvloss`](https://github.com/Shifa-Zhong/bayesian-gp-cvloss).

**Phase 1 (this release)** — core single-objective stack:

- `CompositeConformalCalibrator` with three orthogonal switches:
  - `localized=True` — pick only x*'s k-NN from the calibration set
  - `weighted=True` — RBF weights against x* on the surviving subset
  - `adaptive=True` — ACI controller updates α from rolling coverage
- `CalibratedUCB`, `CalibratedEI` — drop-in calibrated acquisitions
- `CalibratedBOLoop` — single-objective loop (`suggest()` / `observe()`)
- Platform adapter (`create_bo_session(config)`)

All three calibrator switches are independent: turn them all off and the
calibrator is numerically equivalent to standard split CP.

**Phase 2 (planned)** — multi-objective EHVI, q-batch with fantasies,
diagnostics dashboard, native gp-cv platform integration.

## Install

```bash
pip install -e D:/mypackage/calibrated-bo
```

Requires `bayesian-gp-cvloss>=0.3.1`.

## Quickstart

```python
import numpy as np
from calibrated_bo import CalibratedBOLoop

# 2D toy: minimise (x-0.3)^2 + (y-0.7)^2
def f(x):
    return np.sum((x - np.array([0.3, 0.7]))**2)

bo = CalibratedBOLoop(
    bounds=[(0.0, 1.0), (0.0, 1.0)],
    objective="minimize",
    calibrator_config={
        "alpha": 0.1,
        "localized": True, "k": 20,
        "weighted": True,
        "adaptive": True, "gamma": 0.05,
    },
    acquisition="cUCB",
    acquisition_kwargs={"beta": 2.0},
    batch_size=1,
    initial_random=5,
    gp_max_evals=30,
)

for step in range(20):
    X_next = bo.suggest()
    y_next = np.array([f(x) for x in X_next])
    bo.observe(X_next, y_next)

print("best so far:", bo.best)
print("diagnostics:", bo.diagnostics())
```

## Calibrator-only usage

If you only want the calibrator (no BO loop), drop it on top of any fitted
`GPCrossValidatedOptimizer`:

```python
from bayesian_gp_cvloss import GPCrossValidatedOptimizer
from calibrated_bo import CompositeConformalCalibrator

opt = GPCrossValidatedOptimizer(X_train, y_train, scoring="cv_rmse")
opt.optimize(max_evals=50)

cal = CompositeConformalCalibrator(
    alpha=0.1, localized=True, weighted=True, adaptive=False
).fit_cv(opt)

mean, lower, upper = cal.predict_interval(X_new)
```

## Design

See the project spec (calibrated-bo design doc) for the math behind
Localized + Weighted + Adaptive coordination and the joint half-width
formula.
