xiaohongshu
xiaohongshu
design-of-experiments
Expert guidance for Design of Experiments (DOE) in Python - interactive goal-driven design selection, classical DOE (factorial, response surface, screening), Bayesian optimization with Gaussian processes, model-driven optimal designs, active learning, and sequential experimentation; includes pyDO...
Full skill instructions
Master experimental design through interactive, goal-driven guidance that asks the right questions to recommend the best approach for your situation. This skill covers classical DOE, Bayesian optimization, model-driven designs, and active learning—helping you choose between batch and sequential strategies, screening and optimization, and exploration and exploitation.
Core value: Don't start with a method—start with questions. Based on your goals, budget, and constraints, get personalized recommendations for experimental design strategies that maximize information gain per experiment.
When a user mentions DOE or experimental design, ASK THESE QUESTIONS FIRST:
"What is your primary goal?"
"Can you run experiments sequentially, or must they be done in a batch?"
"How expensive is each experiment?"
"How many factors are you investigating?"
"Do you have prior knowledge, existing data, or a mechanistic model?"
Sequential + Expensive + Unknown landscape
→ Bayesian Optimization (GP + Expected Improvement)
Sequential + Have model + Parameter estimation goal
→ Model-driven sequential optimal design
Batch only + Screening goal + Many factors
→ Fractional factorial or Definitive Screening Design
Batch only + Optimization + Few factors
→ Central Composite Design or Box-Behnken
Sequential + Moderate cost + Want model
→ Active learning with Gaussian Process
Batch only + No prior knowledge + Exploration
→ Latin Hypercube Sampling
Can experiments be run sequentially with feedback?
│
├─ YES (Sequential possible)
│ │
│ ├─ Expensive experiments (>$1000 or >1 day each)?
│ │ ├─ YES → Bayesian Optimization
│ │ │ • Expected Improvement for optimization
│ │ │ • Upper Confidence Bound for exploration
│ │ │ • Tools: GPyOpt, scikit-optimize, BoTorch
│ │ │
│ │ └─ NO → Have a model?
│ │ ├─ YES → Model-driven sequential design
│ │ │ • D-optimal for parameter estimation
│ │ │ • Update design as parameters learned
│ │ │
│ │ └─ NO → Active learning
│ │ • GP with uncertainty sampling
│ │ • Tools: modAL, custom GP
│ │
└─ NO (Batch only)
│
├─ What's your goal?
│ │
│ ├─ SCREENING (identify important factors)
│ │ ├─ <20 runs available → Plackett-Burman, Fractional Factorial
│ │ ├─ 20-50 runs → Definitive Screening Design
│ │ └─ Tools: pyDOE3, dexpy
│ │
│ ├─ OPTIMIZATION (find best settings)
│ │ ├─ 2-5 factors → Central Composite Design, Box-Behnken
│ │ ├─ >5 factors → Sequential screening → then optimize
│ │ ├─ Have model → D-optimal or I-optimal
│ │ └─ Tools: pyDOE3, pycse, statsmodels
│ │
│ ├─ EXPLORATION (understand system)
│ │ ├─ No prior → Latin Hypercube Sampling
│ │ ├─ Build surrogate → Space-filling + modeling
│ │ └─ Tools: pyDOE3, pycse, scipy
│ │
│ └─ ROBUSTNESS (minimize variability)
│ └─ Control + noise factors → Taguchi / Robust Parameter Design
Use when:
Best for:
Tools: pyDOE3, dexpy, pycse, statsmodels
Use when:
Best for:
Tools: GPyOpt, scikit-optimize, BoTorch, Ax
Use when:
Best for:
Tools: Custom implementation with Fisher Information Matrix, pyoptex
Use when:
Best for:
Tools: modAL, scikit-learn, GPy
| Situation | Recommended Approach | Key Tool | Typical # Runs |
|---|---|---|---|
| Batch, <5 factors, screening | Full/Fractional Factorial | pyDOE3 | 8-32 |
| Batch, 6-15 factors, screening | Plackett-Burman, DSD | pyDOE3, dexpy | 12-50 |
| Batch, optimization, 2-5 factors | CCD, Box-Behnken | pyDOE3, pycse | 13-50 |
| Batch, exploration, unknown | Latin Hypercube | pyDOE3, pycse | 10×factors |
| Sequential, expensive, optimize | Bayesian Optimization | GPyOpt, skopt | 10-50 |
| Sequential, build model | Active Learning + GP | modAL | 20-100 |
| Have mechanistic model | Model-driven D-optimal | Custom FIM | 10-30 |
| Parameter estimation | D-optimal, A-optimal | pyoptex | Varies |
| Model discrimination | T-optimal, KL-optimal | Custom | 10-20 |
| Multiple objectives | Multi-objective BO | BoTorch | 30-100 |
| Mixture components | Simplex designs | pyDOE3 | 10-30 |
Situation: Optimize 3 factors, batch experiments, moderate cost
import pyDOE3 as pyd
import pandas as pd
# Generate Central Composite Design
n_factors = 3
design = pyd.ccdesign(n_factors, center=(0, 4)) # With center points
# Create DataFrame with factor names
factors = ['Temperature', 'Pressure', 'Catalyst']
df = pd.DataFrame(design, columns=factors)
# Scale to actual ranges
ranges = {'Temperature': (300, 400),
'Pressure': (1, 5),
'Catalyst': (0.1, 1.0)}
for factor, (low, high) in ranges.items():
df[factor] = df[factor] * (high - low)/2 + (high + low)/2
print(f"Generated {len(df)} experiments")
print(df.head())
# Export for lab work
df.to_csv('experimental_design.csv', index=False)
Next steps:
Situation: Quick RSM with integrated analysis
from pycse import design_sr, analyze_sr, sr_parity
import numpy as np
# Generate design
bounds = np.array([[300, 400], # Temperature
[1, 5], # Pressure
[0.1, 1.0]]) # Catalyst
design = design_sr(bounds,
inputs=['Temperature', 'Pressure', 'Catalyst'],
outputs=['Yield'])
print(design)
# After running experiments, add results
design['Yield'] = [78, 82, 75, 88, 91, 85, 79, ...] # Your data
# Analyze
anova_table = analyze_sr(design)
print(anova_table)
# Parity plot (model fit)
sr_parity(design, show=True)
Advantages: Integrated workflow, automatic ANOVA, quick visualization
Situation: Expensive experiments, 4 factors, want to minimize total runs
import numpy as np
from skopt import gp_minimize
from skopt.space import Real
from skopt.plots import plot_convergence
# Define parameter space
space = [
Real(300, 400, name='Temperature'),
Real(1, 5, name='Pressure'),
Real(0.1, 1.0, name='Catalyst'),
Real(10, 60, name='Time')
]
# Your black-box function (returns value to minimize)
def expensive_experiment(params):
temp, pressure, catalyst, time = params
# Run actual experiment here
# For now, simulate
yield_value = run_experiment(temp, pressure, catalyst, time)
return -yield_value # Minimize negative = maximize yield
# Bayesian optimization
result = gp_minimize(
expensive_experiment,
space,
n_calls=30, # Maximum experiments
n_random_starts=5, # Initial random exploration
acq_func='EI', # Expected Improvement
random_state=42
)
print(f"Best parameters: {result.x}")
print(f"Best yield: {-result.fun:.2f}")
# Visualize convergence
plot_convergence(result)
Workflow:
Situation: Have kinetic model, need to estimate 3 rate constants
import numpy as np
from scipy.optimize import minimize
from scipy.linalg import det
# Your mechanistic model
def model(t, k1, k2, k3):
"""Concentration vs time model"""
return k1 * (1 - np.exp(-k2 * t)) + k3 * t
# Fisher Information Matrix for given design points
def fisher_information(t_design, k_guess):
"""Calculate FIM for design points t"""
k1, k2, k3 = k_guess
# Jacobian (sensitivity matrix)
J = np.zeros((len(t_design), 3))
for i, t in enumerate(t_design):
J[i, 0] = 1 - np.exp(-k2 * t)
J[i, 1] = k1 * t * np.exp(-k2 * t)
J[i, 2] = t
# FIM = J^T * J (assuming constant variance)
FIM = J.T @ J
return FIM
# D-optimal criterion: maximize determinant of FIM
def d_optimal_criterion(t_design, k_guess):
FIM = fisher_information(t_design, k_guess)
return -np.log(det(FIM)) # Maximize det = minimize -log(det)
# Find optimal design points
k_initial_guess = [1.0, 0.1, 0.05]
n_points = 6
result = minimize(
lambda t: d_optimal_criterion(t, k_initial_guess),
x0=np.linspace(0, 100, n_points),
bounds=[(0, 100)] * n_points,
method='L-BFGS-B'
)
optimal_times = result.x
print(f"Optimal measurement times: {optimal_times}")
# Run experiments at these times
# After getting data, update k_guess and re-optimize design if sequential
Sequential workflow:
Situation: Want accurate surrogate model, can run sequentially
from modAL.models import ActiveLearner
from modAL.uncertainty import uncertainty_sampling
from sklearn.gaussian_process import GaussianProcessRegressor
from sklearn.gaussian_process.kernels import RBF
# Initial random sample
X_initial = np.random.uniform([0, 0], [10, 10], size=(5, 2))
y_initial = [expensive_function(x) for x in X_initial]
# Create active learner with GP
regressor = GaussianProcessRegressor(kernel=RBF())
learner = ActiveLearner(
estimator=regressor,
query_strategy=uncertainty_sampling, # Query where uncertain
X_training=X_initial,
y_training=y_initial
)
# Active learning loop
n_queries = 20
for i in range(n_queries):
# Query next experiment (highest uncertainty)
query_idx, query_instance = learner.query(X_candidate_pool)
# Run experiment
y_new = expensive_function(query_instance[0])
# Update model
learner.teach(query_instance, y_new)
print(f"Iteration {i+1}: GP std = {learner.predict(query_instance)[1]:.4f}")
# Final model is in learner.estimator
When starting a DOE project, expect these questions:
Based on answers, receive:
Use provided code to:
Execute experiments according to design:
Analyze data with appropriate methods:
Based on analysis:
For deep dives into specific topics:
Chemical Engineering:
Materials Science:
Pharmaceutical:
Manufacturing:
Machine Learning:
# Classical DOE
pip install pyDOE3 # Factorial, RSM, LHS
pip install dexpy # Modern DOE library
# pycse for integrated RSM
pip install pycse
# Bayesian Optimization
pip install scikit-optimize # skopt - easiest to use
pip install GPyOpt # Comprehensive BO
pip install ax-platform # Meta's adaptive experimentation
# pip install botorch torch # Advanced BO (requires PyTorch)
# Active Learning
pip install modAL # Active learning framework
# Gaussian Processes
pip install GPy # GP models
# scikit-learn has GP built-in
# Analysis
pip install statsmodels # ANOVA, regression
pip install scipy # Optimization, statistics
pip install scikit-learn # ML models, cross-validation
# Visualization
pip install matplotlib seaborn plotly
# Sensitivity Analysis
pip install SALib
# All in one
pip install pyDOE3 dexpy pycse scikit-optimize statsmodels scipy scikit-learn modAL GPy matplotlib seaborn
❌ Don't: "I'll use a Box-Behnken design" ✅ Do: "My goal is optimization, I have 3 factors, I can only batch, so Box-Behnken makes sense"
Sequential designs (BO, active learning, model-driven):
When batch is better:
Initial phase: Simple screening (fractional factorial, LHS) Refinement: Focus on important factors (RSM, BO) Validation: Confirmation runs
Classical DOE assumes:
Check diagnostics: Residual plots, Q-Q plots, lack-of-fit tests
Bayesian optimization assumes:
Check: GP posterior uncertainty, kernel hyperparameters
After finding "optimum":
Problem: Applying batch RSM to expensive experiments Solution: Ask questions first, consider sequential approaches
Problem: GP needs diverse data to model landscape Solution: Start with 5-10 space-filling points (LHS)
Problem: Design suggests infeasible experiments Solution: Specify constraints upfront, use constrained optimization
Problem: GP fits noise, poor predictions Solution: Cross-validation, hold-out test sets, regularization
Problem: Systematic effects confounded with factors Solution: Randomize execution order (except sequential designs)
Problem: Declare convergence before truly converged Solution: Use stopping criteria (EI < threshold, GP uncertainty low)
Expensive experiments:
Complex landscapes:
Cheap experiments:
Setup costs:
When helping with DOE, Claude should:
python-optimization - Response optimization after DOEpycse - Includes regression, ANOVA, confidence intervals for analysispython-multiobjective-optimization - Multi-response optimizationpython-plotting - Visualization of results and diagnosticsxiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience