D Optimal
d_optimal
D-Optimal computer-generated classical Design of Experiments (DoE) matrices.
This module provides the DOptimalDesign class, which constructs D-optimal design matrices using
computer-guided coordinate exchange algorithms. D-optimal designs are critical when classical geometric
templates (such as factorials) are rendered impossible due to irregular design spaces, physical constraints,
or restricted trial footprints.
| CLASS | DESCRIPTION |
|---|---|
DOptimalDesign |
Optimizes the design matrix determinant |X'X| using coordinate exchange algorithms. |
DOptimalDesign
Bases: DesignMatrix
Optimizes the design matrix determinant |X'X| using coordinate exchange algorithms.
Unlike classical designs which rely on rigid geometric symmetries, D-optimal designs are algorithmic, computer-generated designs. They are customized to fit a user-specified model (e.g., linear, interactive, or quadratic) and a fixed budget of \(N\) runs, subject to arbitrary boundary constraints.
When to use D-Optimal Designs
- Irregular Design Space: When certain factor combinations are physically impossible or unsafe (e.g., Temperature + Pressure \(\le\) Threshold). This represents a non-rectangular design space.
- Specific Run Constraints: When the budget restricts the experiment to exactly \(N\) runs, which does not match any standard geometric size (such as \(16\) or \(27\)).
- Mix of Qualitative Factors: When factors have irregular, unequal numbers of discrete levels.
Mathematical Criterion
Let \(X\) be the \(N \times p\) model design matrix (where columns include main effects, interactions, and quadratic terms). The information matrix is \(M = X^T X\). D-optimality maximizes the determinant of the information matrix: $$ \max_{X} \left| X^T X \right| $$ Maximizing this determinant is mathematically equivalent to minimizing the volume of the joint confidence ellipsoid for the estimated model parameters \(\beta\). The D-efficiency of a design is: $$ D_{\text{eff}} = 100 \times \left( \frac{\left| X^T X \right|^{1/p}}{N} \right) $$
Coordinate Exchange Algorithm (Meyer & Nachtsheim, 1995): To find the optimal design without evaluating all combinations (which is NP-hard): 1. Create an initial design matrix \(X^{(0)}\) of size \(N \times k\) by randomly sampling from candidate levels. 2. Loop through each cell \(x_{i, j}\) (row \(i\), factor \(j\)) in the matrix: - Replace \(x_{i, j}\) with each possible candidate level. - For each replacement, compute the new determinant \(|X^T X|\) using rank-one update formulas (Sherman-Morrison-Woodbury theorem) to avoid expensive \(O(p^3)\) matrix inversion. - Keep the level that maximizes the determinant. 3. Repeat coordinate sweeps across the matrix until a full sweep results in no determinant improvements. 4. Run this process from multiple (e.g., 20 to 50) random initial starts to prevent convergence into local optima, selecting the global maximum found.
| ATTRIBUTE | DESCRIPTION |
|---|---|
num_runs |
The exact target trial budget (number of runs in the final matrix).
TYPE:
|
Examples:
Example
| PARAMETER | DESCRIPTION |
|---|---|
factors
|
Mapping of factor labels to their candidate levels.
TYPE:
|
num_runs
|
The target budget of trials.
TYPE:
|
seed
|
Random seed for reproducibility. Defaults to 42.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
generate |
Generates the D-Optimal design matrix. |
Source code in src\xpyrment\design\doe\d_optimal.py
generate
Generates the D-Optimal design matrix.
Runs the coordinate exchange optimization loop from multiple random starts, applying boundary constraints, and maps the best output to physical units.
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
pd.DataFrame: A pandas DataFrame containing the optimal design matrix. |
Source code in src\xpyrment\design\doe\d_optimal.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |