Design of experiments library for Python with comprehensive experimental design capabilities
—
Traditional experimental designs including full factorial, fractional factorial, and screening designs. These methods form the foundation of experimental design methodology and are suitable for factor screening, main effects analysis, and interaction studies.
Complete experimental designs that test all possible combinations of factor levels.
Creates a general full-factorial design for factors with different numbers of levels.
def fullfact(levels):
"""
Create a general full-factorial design
Parameters:
- levels: array-like, number of levels for each factor
Returns:
- mat: 2d-array, design matrix with coded levels 0 to k-1 for k-level factor
"""Usage Example:
import pyDOE3
# 3-factor design: 2 levels, 4 levels, 3 levels
design = pyDOE3.fullfact([2, 4, 3])
print(f"Design shape: {design.shape}") # (24, 3)
# Factor levels coded as 0,1 for factor 1; 0,1,2,3 for factor 2; 0,1,2 for factor 3Creates a 2-level full-factorial design with coded levels -1 and +1.
def ff2n(n_factors: int) -> np.ndarray:
"""
Create a 2-Level full-factorial design
Parameters:
- n_factors: int, number of factors in the design
Returns:
- mat: 2d-array, design matrix with coded levels -1 and +1
"""Usage Example:
import pyDOE3
# 3-factor, 2-level full factorial (2^3 = 8 runs)
design = pyDOE3.ff2n(3)
print(f"Design shape: {design.shape}") # (8, 3)
# All factors coded as -1 (low level) and +1 (high level)Efficient screening designs that test a subset of all possible factor combinations while preserving important statistical properties.
Creates fractional factorial designs using generator strings to define the factor confounding structure.
def fracfact(gen) -> np.ndarray:
"""
Create a 2-level fractional-factorial design with a generator string
Parameters:
- gen: str, generator string defining factors and confounding structure
Uses lowercase letters for main factors, combinations for interactions
Returns:
- H: 2d-array, fractional factorial design matrix with -1/+1 coding
"""Usage Example:
import pyDOE3
# 2^(4-1) fractional factorial design (4 factors in 8 runs)
# Main factors: a, b, c; Generated factor: d = abc
design = pyDOE3.fracfact("a b c abc")
print(f"Design shape: {design.shape}") # (8, 4)
# 2^(5-2) fractional factorial design (5 factors in 8 runs)
design = pyDOE3.fracfact("a b c ab ac")
print(f"Design shape: {design.shape}") # (8, 5)Creates fractional factorial designs based on desired resolution level.
def fracfact_by_res(n, res):
"""
Create a 2-level fractional factorial design by resolution
Parameters:
- n: int, number of factors
- res: int, minimum resolution (III, IV, V, etc.)
Returns:
- H: 2d-array, fractional factorial design matrix
"""Finds optimal generator strings for fractional factorial designs.
def fracfact_opt(n_factors, n_erased, max_attempts=0):
"""
Find optimal generator string for fractional factorial design
Parameters:
- n_factors: int, total number of factors
- n_erased: int, number of factors to generate (not run independently)
- max_attempts: int, maximum optimization attempts (0 for unlimited)
Returns:
- generator: str, optimal generator string
"""Analyzes confounding patterns in fractional factorial designs.
def fracfact_aliasing(design):
"""
Find aliasing structure in a fractional factorial design
Parameters:
- design: 2d-array, fractional factorial design matrix
Returns:
- aliasing: dict, aliasing relationships between effects
"""def alias_vector_indices(n_factors):
"""
Get indices for alias vector conversion
Parameters:
- n_factors: int, number of factors
Returns:
- indices: array, indices for alias vector operations
"""Efficient designs for screening many factors with minimal experimental effort.
Orthogonal screening designs for investigating many factors in few runs.
def pbdesign(n):
"""
Generate a Plackett-Burman design
Parameters:
- n: int, number of factors to screen
Returns:
- H: 2d-array, orthogonal design matrix with n columns
Number of rows is next multiple of 4 higher than n
"""Usage Example:
import pyDOE3
# Screen 7 factors in 8 runs
design = pyDOE3.pbdesign(7)
print(f"Design shape: {design.shape}") # (8, 7)
# Screen 11 factors in 12 runs
design = pyDOE3.pbdesign(11)
print(f"Design shape: {design.shape}") # (12, 11)Generalized screening designs for factors with multiple levels.
def gsd(levels, reduction, n=1):
"""
Create a Generalized Subset Design (GSD)
Parameters:
- levels: array-like, number of levels per factor
- reduction: int, reduction factor (> 1) for design size
- n: int, number of complementary designs (default 1)
Returns:
- H: 2d-array or list of 2d-arrays, GSD design matrix(ces)
"""Usage Example:
import pyDOE3
# GSD for mixed-level factors with reduction
levels = [3, 4, 2, 5] # factors with 3, 4, 2, 5 levels respectively
design = pyDOE3.gsd(levels, reduction=4)
print(f"Design shape: {design.shape}")
# Multiple complementary designs
designs = pyDOE3.gsd(levels, reduction=4, n=2)
print(f"Number of designs: {len(designs)}")Full Factorial Designs:
Fractional Factorial Designs:
Plackett-Burman Designs:
Generalized Subset Designs:
import numpy as np
from typing import Union, List
# Type aliases
LevelsSpec = Union[List[int], np.ndarray]
GeneratorString = str
DesignMatrix = np.ndarrayInstall with Tessl CLI
npx tessl i tessl/pypi-pydoe3