Skip to main content

Experimental design and Bayesian optimization with Gaussian Processes and QMC sampling

Project description

ChemBayes

ChemBayes is a Python library designed to streamline experimental design (DoE) and Bayesian optimization for scientific and chemical research. It leverages Gaussian Processes to model complex response surfaces and efficiently identify optimal conditions.

🚀 Key Features

  • Intelligent Sampling (QMC): Generate initial experimental designs using Halton sequences (Quasi-Monte Carlo) for optimal space-filling coverage. Supports integer, float, and categorical parameters.
  • Automatic Preprocessing: Integrated handling of numeric variables (scaling) and categorical variables (one-hot encoding).
  • Hyperparameter Tuning: Automated Gaussian Process parameter adjustment (Matern + WhiteKernel) using Leave‑One‑Out (LOO) cross‑validation and NLPD loss.
  • Bayesian Optimization: Global maximum search using the Expected Improvement (EI) acquisition function. Supports both single‑objective and weighted multi‑objective optimization.
  • Visual Diagnostics: Automated generation of model validation charts (true vs predicted with uncertainty), feature importance (permutation importance), and partial dependence plots (1D, 2D, and categorical bar charts).

📦 Installation

Option 1: Install from PyPI (recommended)

pip install chembayes

Option 2: Install from source (for development or latest version)

git clone https://github.com/jesusalmartin/chembayes.git
cd chembayes
pip install -e .

🛠️ Quick Start

1. Generating an Experimental Design (Sampling)

Define your search space with numeric and categorical parameters:

from chembayes import Sampler

# Create a sampler instance
sampler = Sampler()

# Add parameters
sampler.add_float('temperature', 20.0, 100.0)
sampler.add_int('time', 5, 60)
sampler.add_categoric('catalyst', ['Pd', 'Ni', 'Cu'])

# Generate 20 optimal experimental points
sampler.qmc_sampling(n_points=20)

# Get the sample as a DataFrame
df_experiments = sampler.get_df()

# Visualize the distribution of numeric parameters
sampler.plot()

You can also define parameters using a dictionary:

params = {
    'temperature': {'type': 'float', 'l_bound': 20.0, 'u_bound': 100.0},
    'time': {'type': 'int', 'l_bound': 5, 'u_bound': 60},
    'catalyst': {'type': 'categoric', 'categories': ['Pd', 'Ni', 'Cu']}
}

sampler.set_params(params)
sampler.qmc_sampling(20)

2. Bayesian Optimization

Once you have experimental data, find the optimal conditions:

Single Output Optimization

from chembayes import Optimizer

# Define input features and the target column
inputs = ['temperature', 'time', 'catalyst']
output = 'yield'

# Run the complete optimization pipeline
opt = Optimizer(
    data=df_data,
    inputs=inputs,
    output=output,
    n_tuning_trials=50,
    n_opt_trials=100
)

# Print the best parameters and predicted objective
opt.summary()

# Visualize model performance and feature importance
opt.true_vs_pred_plot()
opt.permutation_importance_plot()

# Generate partial dependence plots to understand the response surface
opt.partial_dependence_plot()

Weighted Multi‑Output Optimization

If you have multiple response variables and want to optimize a weighted combination:

# Define weights for each output (higher weight = more importance)
outputs = {
    'yield': 0.7,
    'selectivity': 0.2,
    'cost': 0.1
}

opt = Optimizer(
    data=df_data,
    inputs=inputs,
    output=outputs,
    n_tuning_trials=50,
    n_opt_trials=100
)

# Results automatically use the weighted objective
opt.summary()

📂 Project Structure

  • src/chembayes/sampler.py: Tools for QMC sample generation.
  • src/chembayes/optimizer.py: Bayesian optimization engine and Gaussian Processes.
  • src/chembayes/__init__.py: Public API exposure.
  • pyproject.toml: Modern package configuration and dependencies.

✉️ Contact & Contribution

Author: Jesus Alberto Martin del Campo
Email: j.a.martin-campo@hotmail.com
GitHub: jesusalmartin/chembayes

Citation

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chembayes-1.0.2.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

chembayes-1.0.2-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file chembayes-1.0.2.tar.gz.

File metadata

  • Download URL: chembayes-1.0.2.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for chembayes-1.0.2.tar.gz
Algorithm Hash digest
SHA256 0ddfb8bfc3cab0bea47ccd262b9f12c164b6eb979aea38f1274dc139146f8676
MD5 4aaafcee2599e689ec4b1c1d662db2f3
BLAKE2b-256 18012bfccb2e349ef1d5c474dbf5402b3f6736cbfbc4ea9d6a11f78ba69e6fc8

See more details on using hashes here.

Provenance

The following attestation bundles were made for chembayes-1.0.2.tar.gz:

Publisher: publish.yml on jesusalmartin/chembayes

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file chembayes-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: chembayes-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 12.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for chembayes-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 beded2a606f1e72bb7d976d22907fde0182fdf9511b74adcb2bc33ff33ea442c
MD5 6c0b54b724b3204e15afc9dbd12d5fb7
BLAKE2b-256 c626491dc63464e2c7c5906b6030dd55a25e7fa896cde0657f5c3a7e2d86ec72

See more details on using hashes here.

Provenance

The following attestation bundles were made for chembayes-1.0.2-py3-none-any.whl:

Publisher: publish.yml on jesusalmartin/chembayes

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page