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

DOI

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.1.tar.gz (13.6 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.1-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: chembayes-1.0.1.tar.gz
  • Upload date:
  • Size: 13.6 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.1.tar.gz
Algorithm Hash digest
SHA256 02a2fad5adcffc7418dad58d514a521d0d5785d9bb4ec1eec2d73e865ea055e9
MD5 ae617567035f73ecb4f860d7dd3190d0
BLAKE2b-256 04c3f2484a41639b026a1b26f47b3524d29f76e5bc61989d32e3478b1383413a

See more details on using hashes here.

Provenance

The following attestation bundles were made for chembayes-1.0.1.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.1-py3-none-any.whl.

File metadata

  • Download URL: chembayes-1.0.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0c26171b6d6f023a7073b46c86d448f57cc24b8bfc86fd04a120b799e8e68185
MD5 3eea93916cb3cb14ced8905c1b1c7952
BLAKE2b-256 ff96601efb25b27070964a74a1fcfb2541e64b136b059f3d3c88fbce085c4a1c

See more details on using hashes here.

Provenance

The following attestation bundles were made for chembayes-1.0.1-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