references/factorial_and_doe.md
8.9 KB查看排版效果| 1 | # Factorial and Design-of-Experiments (DOE) |
| 2 | |
| 3 | When several factors might affect a response, testing them **one factor at a time |
| 4 | (OFAT)** is both wasteful and blind to interactions. Factorial designs vary factors |
| 5 | *together*, so the appropriate full design separates main effects and interactions; |
| 6 | reduced designs trade some of that information for fewer runs. This file covers the family of DOE designs and the |
| 7 | concepts (resolution, aliasing) needed to read them. Generate them with |
| 8 | `scripts/doe_designs.py`. |
| 9 | |
| 10 | ## Table of contents |
| 11 | - [Why factorial beats OFAT](#why-factorial-beats-ofat) |
| 12 | - [Full factorial (2^k)](#full-factorial) |
| 13 | - [Fractional factorial (2^(k-p))](#fractional-factorial) |
| 14 | - [Resolution and aliasing](#resolution-and-aliasing) |
| 15 | - [Screening designs (Plackett-Burman)](#screening-designs) |
| 16 | - [Response-surface designs](#response-surface-designs) |
| 17 | - [Space-filling designs](#space-filling-designs) |
| 18 | - [Choosing a design](#choosing-a-design) |
| 19 | |
| 20 | ## Why factorial beats OFAT |
| 21 | |
| 22 | Vary one factor while holding others fixed and you (1) spend runs inefficiently and |
| 23 | (2) can never see **interactions** — cases where the effect of A depends on the level |
| 24 | of B, which are the rule, not the exception, in real systems. A factorial varies all |
| 25 | factors simultaneously across runs; each effect is estimated using *all* the data, so |
| 26 | a 2^k factorial is more precise than k separate OFAT studies of the same size. |
| 27 | |
| 28 | ## Full factorial |
| 29 | |
| 30 | A **2^k** design runs every combination of k factors at two levels (low/high, coded |
| 31 | −1/+1). It estimates all k main effects and all 2^k − k − 1 interactions. With one observation per combination, the |
| 32 | model containing every effect plus an intercept is saturated: it has zero residual |
| 33 | degrees of freedom. Replicate independently or pre-specify a defensible reduced |
| 34 | model before claiming standard errors or significance. |
| 35 | |
| 36 | - Runs = 2^k: 8 for 3 factors, 16 for 4, 32 for 5. Practical to ~5 factors. |
| 37 | - Use when you have a handful of factors and want a full picture including |
| 38 | interactions. |
| 39 | - `two_level_factorial({"temp": (20,60), "conc": (1,10), "pH": (6,8)})` → 8 runs. |
| 40 | - For factors with more than two levels, use `full_factorial` with explicit level |
| 41 | lists (runs = product of level counts — grows fast). |
| 42 | |
| 43 | Add **center points** (all factors at their midpoint) to a two-level design to get a |
| 44 | cheap check for curvature: if the center response departs from the factorial average, |
| 45 | a linear model is inadequate and you need a response-surface design. |
| 46 | |
| 47 | ## Fractional factorial |
| 48 | |
| 49 | When k is large, 2^k is too many runs — but most high-order interactions are |
| 50 | negligible (the *sparsity-of-effects* principle). A **2^(k−p)** fractional factorial |
| 51 | runs a carefully chosen fraction (1/2, 1/4, ...) of the full design, trading the |
| 52 | ability to estimate some interactions for far fewer runs. |
| 53 | |
| 54 | - `fractional_factorial(factors, generator="a b c abc")` builds a half-fraction of 4 |
| 55 | factors in 8 runs. The generator string (Yates notation) assigns each factor to a |
| 56 | column; a multi-letter token aliases that factor with an interaction. |
| 57 | - The price is **aliasing**: some effects become indistinguishable. You must know |
| 58 | which. |
| 59 | |
| 60 | ## Resolution and aliasing |
| 61 | |
| 62 | **Aliasing** (confounding) means two effects are estimated by the same contrast — the |
| 63 | data cannot separate them. Which effects are aliased is summarized by the design's |
| 64 | **resolution**: |
| 65 | |
| 66 | | Resolution | Aliasing | Interpretation | |
| 67 | |------------|----------|----------------| |
| 68 | | **III** | main effects aliased with 2-factor interactions | Screening only; a "significant" main effect might be an interaction | |
| 69 | | **IV** | main effects clear of 2FI, but 2FIs aliased with each other | Main effects require negligible aliased 3FI+ | |
| 70 | | **V** | main effects and 2FIs all clear of each other (aliased with 3FI+) | Main/2FI separation assumes negligible aliased higher effects | |
| 71 | |
| 72 | Always state the resolution and inspect the alias structure before interpreting a |
| 73 | fractional design. Concluding "factor C has no effect" is unsafe if C is aliased with |
| 74 | a real interaction (it could cancel out). When in doubt, choose a higher-resolution |
| 75 | generator (more runs) or add runs to **de-alias** (fold-over / augment the design). |
| 76 | |
| 77 | ## Screening designs |
| 78 | |
| 79 | When the goal is to **find the vital few** factors out of many (5, 10, 20+), use a |
| 80 | screening design that estimates main effects only, as cheaply as possible: |
| 81 | - **Plackett-Burman** (`plackett_burman`): runs = the next multiple of 4 above k |
| 82 | (e.g. 12 runs for up to 11 factors). Resolution III — two-factor interactions are |
| 83 | often confounded with main effects. Use for triage: run it, keep the few |
| 84 | factors with large effects, then study those with a full or higher-resolution |
| 85 | factorial. |
| 86 | - Resolution III fractional factorials serve the same purpose. |
| 87 | |
| 88 | The current `pydoe==1.5.0` implementation supports run counts in the families |
| 89 | `2^a`, `12*2^a`, and `20*2^a`. It can reject a requested factor count whose next |
| 90 | multiple of four is unsupported (25 factors require 28 runs and raise |
| 91 | `ValueError`). Inspect the actual matrix before budgeting; choose a supported |
| 92 | design or a suitable fractional factorial. Reduced subsets may have better |
| 93 | aliasing properties than the full saturated design, so inspect actual aliases. |
| 94 | See the [current factorial API](https://pydoe.github.io/pydoe/reference/factorial/). |
| 95 | |
| 96 | Screen first, optimize later — don't try to learn interactions and find the optimum |
| 97 | in one cheap design. |
| 98 | |
| 99 | ## Response-surface designs |
| 100 | |
| 101 | Two-level designs fit only a flat (linear + interaction) model; they cannot locate an |
| 102 | interior optimum or describe **curvature**. To fit a quadratic and optimize, use a |
| 103 | response-surface methodology (RSM) design over continuous factors: |
| 104 | |
| 105 | - **Central composite design (CCD)** (`central_composite`): a 2^k factorial + center |
| 106 | points + axial ("star") points. The axial points add the levels needed to estimate |
| 107 | quadratic terms. With `face="circumscribed"` (default) the axial points sit |
| 108 | *outside* the factorial box (so actual factor levels exceed your stated low/high); |
| 109 | use `face="inscribed"` or `"faced"` to keep everything within the original range. |
| 110 | - **Box-Behnken** (`box_behnken`, needs ≥3 factors): a quadratic design that avoids |
| 111 | the extreme all-low/all-high corners — useful when those corners are unsafe, |
| 112 | expensive, or infeasible. Compare actual run counts and the same center-point |
| 113 | replication: Box-Behnken is not always smaller (for five factors, its 40 |
| 114 | non-center runs exceed a half-fraction CCD with 26). The bundled CCD wrapper |
| 115 | uses the full factorial and does not build that half-fraction. |
| 116 | See [NIST response-surface comparisons](https://www.itl.nist.gov/div898/handbook/pri/section3/pri3363.htm). |
| 117 | |
| 118 | The wrappers default to a single center run (`center=(0, 1)` for CCD; |
| 119 | `center=1` for Box-Behnken). That supplies no pure-error replication. Pre-plan |
| 120 | independent replicate runs, inspect quadratic-model rank, and budget lack-of-fit |
| 121 | assessment. CCD `center` counts refer to factorial and axial construction blocks; |
| 122 | the wrapper returns a globally shuffled table without block IDs. Preserve or |
| 123 | construct those IDs before using a physically blocked experiment. |
| 124 | |
| 125 | Workflow: screen → factorial (find important factors & rough region) → response |
| 126 | surface (model curvature, locate optimum), often moving the experimental region |
| 127 | between steps (path of steepest ascent). |
| 128 | |
| 129 | ## Space-filling designs |
| 130 | |
| 131 | For **computer experiments / simulations** (deterministic or expensive models) where |
| 132 | space coverage may be the main objective, you want even coverage of a |
| 133 | high-dimensional input space: |
| 134 | - **Latin hypercube** (`latin_hypercube`): each factor's range is divided into |
| 135 | n_samples equal bins, sampled once each, arranged to spread points apart |
| 136 | (`criterion="maximin"`). Gives good coverage with relatively few points and is the |
| 137 | common input design for surrogate/emulator modeling. A generic LHS alone is not |
| 138 | a Saltelli/Sobol sensitivity estimator design. Stochastic simulations may still |
| 139 | need replicated random seeds; experimental batches may still need blocking. |
| 140 | |
| 141 | ## Choosing a design |
| 142 | |
| 143 | | Goal | Factors | Design | Script function | |
| 144 | |------|---------|--------|-----------------| |
| 145 | | Screen many factors | 5–20+ | Plackett-Burman / Res III | `plackett_burman` | |
| 146 | | Main effects, some interactions, few runs | 4–8 | Res IV/V fractional | `fractional_factorial` | |
| 147 | | All effects + interactions | 2–5 | Full 2^k factorial | `two_level_factorial` | |
| 148 | | Multi-level categorical | few | Full factorial | `full_factorial` | |
| 149 | | Optimize a response (curvature) | 2–5 | Central composite / Box-Behnken | `central_composite`, `box_behnken` | |
| 150 | | Cover a simulation input space | any | Latin hypercube | `latin_hypercube` | |
| 151 | |
| 152 | For physical experiments, **randomize run order within the allowed blocks** to |
| 153 | avoid systematic alignment with drift. DOE wrappers default to a global shuffle; |
| 154 | Latin hypercube defaults to `randomize=False` and already has stochastic sample |
| 155 | placement. Add replicated center points to two-level continuous designs for an |
| 156 | aggregate curvature check; they cannot separate all pure quadratic coefficients. |
文件内容是平台检查时读出的文本,只供查看。平台不会运行包里的任何脚本或程序。

