Design of experiments library for Python with comprehensive experimental design capabilities
—
Taguchi methodology for robust parameter design with orthogonal arrays and signal-to-noise ratio analysis. These methods focus on minimizing variability and improving product/process robustness by identifying factor settings that are insensitive to noise and environmental conditions.
Create experimental designs using Taguchi orthogonal arrays with actual factor levels.
def taguchi_design(oa_name: ORTHOGONAL_ARRAY_NAMES, levels_per_factor: List[List]) -> np.ndarray:
"""
Generate a Taguchi design matrix using an orthogonal array and factor levels
Parameters:
- oa_name: str, name of Taguchi orthogonal array (e.g., 'L4(2^3)', 'L8(2^7)')
- levels_per_factor: list of lists, actual factor settings for each factor
Length must match number of columns in orthogonal array
Returns:
- design_matrix: 2d-array, design matrix with actual factor settings
"""Usage Example:
import pyDOE3
# Define factor levels for L9(3^4) array (4 factors, 3 levels each)
factor_levels = [
[100, 150, 200], # Temperature (°C)
[10, 20, 30], # Pressure (bar)
[0.5, 1.0, 1.5], # Flow rate (L/min)
['A', 'B', 'C'] # Catalyst type
]
# Generate Taguchi design
design = pyDOE3.taguchi_design("L9(3^4)", factor_levels)
print(f"Design shape: {design.shape}") # (9, 4)
print("Factor combinations:")
print(design)Access and explore available Taguchi orthogonal arrays.
def list_orthogonal_arrays() -> List[str]:
"""
List descriptive names of available Taguchi orthogonal arrays
Returns:
- array_names: list of str, available array names like ['L4(2^3)', 'L8(2^7)', ...]
"""def get_orthogonal_array(oa_name: ORTHOGONAL_ARRAY_NAMES) -> np.ndarray:
"""
Return a Taguchi orthogonal array by its descriptive name
Parameters:
- oa_name: str, name of the array (e.g., 'L4(2^3)', 'L8(2^7)', 'L9(3^4)')
Returns:
- array: 2d-array, orthogonal array with zero-indexed factor levels
"""Usage Examples:
import pyDOE3
# List all available orthogonal arrays
arrays = pyDOE3.list_orthogonal_arrays()
print("Available arrays:", arrays)
# Get specific orthogonal array
l4_array = pyDOE3.get_orthogonal_array("L4(2^3)")
print(f"L4 array shape: {l4_array.shape}") # (4, 3)
print("L4 array:")
print(l4_array)
# Get larger array for more factors
l16_array = pyDOE3.get_orthogonal_array("L16(2^15)")
print(f"L16 array shape: {l16_array.shape}") # (16, 15)Calculate signal-to-noise ratios for Taguchi robust design analysis.
class TaguchiObjective(Enum):
"""
Enumeration for Taguchi optimization objectives
"""
LARGER_IS_BETTER = "larger is better"
SMALLER_IS_BETTER = "smaller is better"
NOMINAL_IS_BEST = "nominal is best"def compute_snr(responses: np.ndarray, objective: TaguchiObjective = TaguchiObjective.LARGER_IS_BETTER) -> float:
"""
Calculate the Signal-to-Noise Ratio (SNR) for Taguchi designs
Parameters:
- responses: array-like, response measurements for SNR calculation
- objective: TaguchiObjective, optimization objective type
Returns:
- snr: float, signal-to-noise ratio in decibels (dB)
"""SNR Formulas:
Usage Examples:
import pyDOE3
import numpy as np
# Strength measurements (larger is better)
strength_data = np.array([45.2, 47.8, 44.1, 46.9, 48.3])
snr_strength = pyDOE3.compute_snr(strength_data, pyDOE3.TaguchiObjective.LARGER_IS_BETTER)
print(f"Strength SNR: {snr_strength:.2f} dB")
# Defect rate (smaller is better)
defect_data = np.array([0.02, 0.015, 0.018, 0.022, 0.016])
snr_defects = pyDOE3.compute_snr(defect_data, pyDOE3.TaguchiObjective.SMALLER_IS_BETTER)
print(f"Defect SNR: {snr_defects:.2f} dB")
# Dimension accuracy (nominal is best, target = 50.0)
dimension_data = np.array([49.8, 50.2, 49.9, 50.1, 50.0])
snr_dimension = pyDOE3.compute_snr(dimension_data, pyDOE3.TaguchiObjective.NOMINAL_IS_BEST)
print(f"Dimension SNR: {snr_dimension:.2f} dB")pyDOE3 provides 17 standard Taguchi orthogonal arrays:
# Step 1: Select orthogonal array based on factors and levels
available_arrays = pyDOE3.list_orthogonal_arrays()
# Step 2: Define factor levels
control_factors = [
[20, 25, 30], # Temperature
[1, 2, 3], # Speed
[0.1, 0.2, 0.3], # Feed rate
['A', 'B', 'C'] # Tool type
]
# Step 3: Generate experimental design
design = pyDOE3.taguchi_design("L9(3^4)", control_factors)
# Step 4: Run experiments and collect responses
# responses = run_experiments(design)
# Step 5: Calculate SNR for each run
# snr_values = [pyDOE3.compute_snr(response, objective) for response in responses]After collecting experimental data:
Array Selection Rules:
Factor Assignment:
from typing import List, Literal
from enum import Enum
import numpy as np
# Orthogonal array names type
ORTHOGONAL_ARRAY_NAMES = Literal[
"L4(2^3)", "L8(2^7)", "L9(3^4)", "L12(2^11)", "L16(2^15)", "L16(4^5)",
"L18(6^1 3^6)", "L25(5^6)", "L27(2^1 3^12)", "L32(2^31)", "L32(2^1 4^9)",
"L36(3^23)", "L50(2^1 5^11)", "L54(2^1 3^25)", "L64(2^31)", "L64(4^21)", "L81(3^40)"
]
# Factor levels specification
FactorLevels = List[List]
# Design matrix type
Taguchi_Matrix = np.ndarray
class TaguchiObjective(Enum):
LARGER_IS_BETTER = "larger is better"
SMALLER_IS_BETTER = "smaller is better"
NOMINAL_IS_BEST = "nominal is best"Taguchi designs complement other experimental approaches:
Install with Tessl CLI
npx tessl i tessl/pypi-pydoe3