Build a surrogate for your LnL(d|θ)± ΔLnL(d|θ)
Project description
COMPAS LnL Surrogate
This python package helps make an LnL surrogate for COMPAS SF-params given a set of BBH mergers. The surrogate is trained using active learning/bayesian optimisation techniques. This package acts as a bridge between the COMPAS LnL computer, surrogate modelling packages, and Bayesian optimisation packages.
Installation
pip install lnl_surrogate@git+https://github.com/COMPAS-Surrogate/lnl_surrogate.git
Example
from trieste.acquisition.function import PredictiveVariance, ExpectedImprovement
import numpy as np
from lnl_surrogate.surrogate import train
from scipy.stats import norm
from lnl_surrogate.surrogate.setup_optimizer import McZGrid
from lnl_computer.mock_data import generate_mock_data
from typing import Dict
import matplotlib.pyplot as plt
import os
np.random.seed(0)
MINX, MAXX = 0.005, 0.015
MIDX = (MINX + MAXX) / 2
NORM = norm(MIDX, 0.003)
OUTDIR = 'outdir'
os.makedirs(OUTDIR, exist_ok=True)
def mock_lnl(*args, **kwargs):
sf_sample: Dict = kwargs.get('sf_sample')
sf_sample = np.array(list(sf_sample.values()))
return NORM.logpdf(sf_sample), 0
def plot_res(model, data, search_space):
x = np.linspace(MINX, MAXX, 100).reshape(-1, 1)
true_y = NORM.logpdf(x) * -1.0
model_y, model_yunc = model.predict(x)
x_obs = data.query_points
y_obs = data.observations
tf_to_np = lambda x: x.numpy().flatten() if hasattr(x, 'numpy') else x
# make new fig
plt.figure()
plt.plot(x, true_y, label='True', color='black')
plt.plot(x, model_y, label='Model', color="tab:orange")
plt.scatter(x_obs, y_obs, label='Observed', color='black')
yup, ydown = tf_to_np(model_y + model_yunc), tf_to_np(model_y - model_yunc)
plt.fill_between(x.flatten(), yup.flatten(), ydown.flatten(), alpha=0.2 , color="tab:orange")
plt.legend(loc='upper right')
return plt.gcf()
McZGrid.lnl = mock_lnl
mock_data = generate_mock_data(OUTDIR)
acq_fns = [PredictiveVariance(), ExpectedImprovement()]
for acq_fn in acq_fns:
res = train(
model_type='gp',
mcz_obs=mock_data.observations.mcz,
compas_h5_filename=mock_data.compas_filename,
acquisition_fns=[acq_fn],
params=['aSF'],
n_init=2,
n_rounds=10,
n_pts_per_round=1,
outdir=f"{OUTDIR}/gp",
truth=dict(
aSF=MIDX,
lnl=mock_lnl(sf_sample={'aSF': MIDX})[0]*-1.0
),
model_plotter=plot_res,
noise_level=1e-3
)
| Exploratory Acquisition | Exploitative Acquisition |
|---|---|
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file compas_surrogate_lnl_surrogate-0.1.1.tar.gz.
File metadata
- Download URL: compas_surrogate_lnl_surrogate-0.1.1.tar.gz
- Upload date:
- Size: 587.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ea91991f19e538e205309407d25ede46d220a00e866b1e9bb05b24ce09fbc001
|
|
| MD5 |
54a87eb65297d6614ea6f381eb8ca6c3
|
|
| BLAKE2b-256 |
64480526d302234c18f36414609200f98aa4791dfef8b324a2c8fe726ff5e5c5
|
Provenance
The following attestation bundles were made for compas_surrogate_lnl_surrogate-0.1.1.tar.gz:
Publisher:
release.yml on COMPAS-Surrogate/lnl_surrogate
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
compas_surrogate_lnl_surrogate-0.1.1.tar.gz -
Subject digest:
ea91991f19e538e205309407d25ede46d220a00e866b1e9bb05b24ce09fbc001 - Sigstore transparency entry: 154884840
- Sigstore integration time:
-
Permalink:
COMPAS-Surrogate/lnl_surrogate@90dba2d8f154ccd56abe566e6a9cae59d63a45a6 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/COMPAS-Surrogate
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@90dba2d8f154ccd56abe566e6a9cae59d63a45a6 -
Trigger Event:
push
-
Statement type:
File details
Details for the file compas_surrogate.lnl_surrogate-0.1.1-py3-none-any.whl.
File metadata
- Download URL: compas_surrogate.lnl_surrogate-0.1.1-py3-none-any.whl
- Upload date:
- Size: 23.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fe459bc094098561e23dc130c62a1d2c1e7fe9ea42b9ffca02dc586431ef7c93
|
|
| MD5 |
26a808a3fb5a0c1cd63ec1639c90fee4
|
|
| BLAKE2b-256 |
11a5909f0566353c49100a6139c9a97ada766a6b8634d3daaa3ee1b696ac8e24
|
Provenance
The following attestation bundles were made for compas_surrogate.lnl_surrogate-0.1.1-py3-none-any.whl:
Publisher:
release.yml on COMPAS-Surrogate/lnl_surrogate
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
compas_surrogate_lnl_surrogate-0.1.1-py3-none-any.whl -
Subject digest:
fe459bc094098561e23dc130c62a1d2c1e7fe9ea42b9ffca02dc586431ef7c93 - Sigstore transparency entry: 154884841
- Sigstore integration time:
-
Permalink:
COMPAS-Surrogate/lnl_surrogate@90dba2d8f154ccd56abe566e6a9cae59d63a45a6 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/COMPAS-Surrogate
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@90dba2d8f154ccd56abe566e6a9cae59d63a45a6 -
Trigger Event:
push
-
Statement type: