@iyulab/u-doe 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -121,6 +121,115 @@ println!("Required replicates: {n}");
121
121
  - Jones, B. & Nachtsheim, C.J. (2011). A Class of Three-Level Designs for Definitive Screening in the Presence of Second-Order Effects. *Journal of Quality Technology* 43(1), 1–15.
122
122
  - Taguchi, G. (1986). *Introduction to Quality Engineering*. Asian Productivity Organization.
123
123
 
124
+ ## WebAssembly / npm
125
+
126
+ Available as an npm package via [wasm-pack](https://rustwasm.github.io/wasm-pack/).
127
+
128
+ ```bash
129
+ npm install @iyulab/u-doe
130
+ ```
131
+
132
+ ### Quick Start
133
+
134
+ ```javascript
135
+ import init, { full_factorial, doe_anova } from '@iyulab/u-doe';
136
+
137
+ await init();
138
+ const design = full_factorial(3); // 2^3 = 8 runs
139
+ ```
140
+
141
+ ### Functions
142
+
143
+ #### `full_factorial(k) -> DesignMatrix`
144
+
145
+ Generate a 2^k full factorial design (k = 1..7).
146
+
147
+ **Output:**
148
+ ```json
149
+ { "data": [[...]], "factor_names": ["X1","X2"], "run_count": 4, "factor_count": 2 }
150
+ ```
151
+
152
+ #### `fractional_factorial(k, p) -> DesignMatrix`
153
+
154
+ Generate a 2^(k-p) fractional factorial design (k = 4..7, p = 1..3).
155
+
156
+ #### `plackett_burman(k) -> DesignMatrix`
157
+
158
+ Generate a Plackett-Burman screening design (k = 1..19).
159
+
160
+ #### `ccd(k, design_type, n_center) -> DesignMatrix`
161
+
162
+ Generate a Central Composite Design. `design_type`: `"FaceCentered"` | `"Rotatable"` | `"Inscribed"`. k = 2..6.
163
+
164
+ #### `box_behnken(k, n_center) -> DesignMatrix`
165
+
166
+ Generate a Box-Behnken design (k = 3, 4, or 5).
167
+
168
+ #### `taguchi_array(name, k) -> DesignMatrix`
169
+
170
+ Get a Taguchi orthogonal array. `name`: `"L4"` | `"L8"` | `"L9"` | `"L12"` | `"L16"` | `"L18"` | `"L27"`.
171
+
172
+ #### `definitive_screening(k) -> DesignMatrix`
173
+
174
+ Generate a Definitive Screening Design (k = 2..12).
175
+
176
+ #### `doe_anova(design, responses, factor_names, effect_names) -> AnovaResult`
177
+
178
+ Perform DOE ANOVA on a coded design matrix.
179
+
180
+ **Input:** `design`: `[[f64]]`, `responses`: `Float64Array`, `factor_names`: `["A","B"]`, `effect_names`: `["A","B","AB"]`
181
+
182
+ **Output:**
183
+ ```json
184
+ { "effects": [{ "name": "A", "sum_of_squares": 10.0, "df": 1, "mean_square": 10.0, "f_statistic": 5.0, "p_value": 0.03 }], "residual_ss": 4.0, "residual_df": 2, "total_ss": 14.0, "r_squared": 0.71, "r_squared_adj": 0.57 }
185
+ ```
186
+
187
+ #### `signal_to_noise(responses, goal) -> [f64]`
188
+
189
+ Compute Taguchi S/N ratios. `responses`: `[[f64]]` (replicates per run). `goal`: `"LargerIsBetter"` | `"SmallerIsBetter"` | `"NominalIsBest"`.
190
+
191
+ #### `estimate_effects(design, responses, factor_names, max_order) -> EffectsResult`
192
+
193
+ Estimate main effects and interactions for a 2-level factorial design.
194
+
195
+ **Output:**
196
+ ```json
197
+ { "effects": [{ "name": "A", "estimate": 21.6, "sum_of_squares": 1870.6, "percent_contribution": 45.2 }], "half_normal": [[21.6, 1.15]] }
198
+ ```
199
+
200
+ #### `fit_rsm(design, responses, factor_names) -> RsmModel`
201
+
202
+ Fit a second-order Response Surface Model via OLS.
203
+
204
+ **Output:**
205
+ ```json
206
+ { "coefficients": [10.0, 2.5, -1.3, 0.5, 0.8, -0.2], "r_squared": 0.95, "factor_count": 2 }
207
+ ```
208
+
209
+ #### `steepest_ascent(coefficients, factor_count, n_steps, step_size) -> AscentResult`
210
+
211
+ Compute the steepest ascent path from a fitted RSM model.
212
+
213
+ **Output:**
214
+ ```json
215
+ { "steps": [{ "coded": [0.5, 0.3], "step_number": 1 }] }
216
+ ```
217
+
218
+ #### `desirability(specs, responses) -> DesirabilityResult`
219
+
220
+ Compute Derringer-Suich desirability for multiple responses.
221
+
222
+ **Input:** `specs`: `[{ "goal": "Maximize"|"Minimize"|"Target", "lower": 0, "target": 100, "upper": 100, "s1": 1, "s2": 1 }]`, `responses`: `Float64Array`
223
+
224
+ **Output:**
225
+ ```json
226
+ { "individual": [0.8, 0.6], "overall": 0.69 }
227
+ ```
228
+
229
+ #### `two_level_factorial_power(k, p, n_replicates, effect_size, sigma, alpha) -> f64`
230
+
231
+ Compute statistical power of a 2^(k-p) factorial design. Returns power in [0, 1].
232
+
124
233
  ## Related
125
234
 
126
235
  - [`u-analytics`](https://crates.io/crates/u-analytics) — SPC, process capability, statistical analysis
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "iyulab"
6
6
  ],
7
7
  "description": "Design of Experiments (DOE) framework: factorial, Plackett-Burman, CCD, Box-Behnken, Taguchi, effects analysis, RSM, and desirability optimization.",
8
- "version": "0.2.0",
8
+ "version": "0.3.0",
9
9
  "license": "MIT",
10
10
  "repository": {
11
11
  "type": "git",
package/u_doe.d.ts CHANGED
@@ -38,6 +38,21 @@ export function ccd(k: number, design_type: string, n_center: number): any;
38
38
  */
39
39
  export function definitive_screening(k: number): any;
40
40
 
41
+ /**
42
+ * Compute Derringer-Suich desirability for multiple responses.
43
+ *
44
+ * `specs_json`: JSON array of response specifications, each:
45
+ * `{ goal: "Maximize"|"Minimize"|"Target", lower, target, upper, s1, s2 }`
46
+ * `responses`: flat array of observed response values (one per spec).
47
+ *
48
+ * Returns `{ individual: [f64], overall: f64 }`.
49
+ *
50
+ * # Errors
51
+ * Returns an error string if JSON is malformed, specs/responses length mismatch,
52
+ * or goal string is unrecognised.
53
+ */
54
+ export function desirability(specs_json: any, responses: Float64Array): any;
55
+
41
56
  /**
42
57
  * Perform DOE ANOVA.
43
58
  *
@@ -54,6 +69,52 @@ export function definitive_screening(k: number): any;
54
69
  */
55
70
  export function doe_anova(design_json: any, responses: Float64Array, factor_names_json: any, effect_names_json: any): any;
56
71
 
72
+ /**
73
+ * Estimate main effects and interactions for a 2-level factorial design,
74
+ * plus half-normal plot data for identifying active effects.
75
+ *
76
+ * `design_json`: JSON array-of-arrays `[[f64]]` — the coded design matrix (rows = runs).
77
+ * `responses`: flat array of response values, one per run.
78
+ * `factor_names_json`: JSON array of factor name strings.
79
+ * `max_order`: maximum interaction order (1 = main effects only, 2 = + 2FI, 3 = + 3FI).
80
+ *
81
+ * Returns `{ effects: [{ name, estimate, sum_of_squares, percent_contribution }],
82
+ * half_normal: [[abs_effect, quantile]] }`.
83
+ *
84
+ * # Errors
85
+ * Returns an error string if dimensions do not match or JSON is malformed.
86
+ */
87
+ export function estimate_effects(design_json: any, responses: Float64Array, factor_names_json: any, max_order: number): any;
88
+
89
+ /**
90
+ * Fit a second-order Response Surface Model (RSM) using OLS.
91
+ *
92
+ * `design_json`: JSON array-of-arrays `[[f64]]` — the coded design matrix.
93
+ * `responses`: flat array of response values, one per run.
94
+ * `factor_names_json`: JSON array of factor name strings.
95
+ *
96
+ * Returns `{ coefficients: [f64], r_squared: f64, factor_count: usize }`.
97
+ * Coefficient order: [intercept, linear..., quadratic..., interactions...].
98
+ *
99
+ * # Errors
100
+ * Returns an error string if dimensions do not match, JSON is malformed,
101
+ * or the model matrix is singular.
102
+ */
103
+ export function fit_rsm(design_json: any, responses: Float64Array, factor_names_json: any): any;
104
+
105
+ /**
106
+ * Generate a 2^(k-p) fractional factorial design.
107
+ *
108
+ * Uses standard generators from Montgomery (2019) Table 8.14.
109
+ * Supported: k=4..7, p=1..3 (standard combinations only).
110
+ *
111
+ * Returns `{ data: [[f64]], factor_names: [str], run_count: usize, factor_count: usize }`.
112
+ *
113
+ * # Errors
114
+ * Returns an error string if the (k, p) combination is not in the standard table.
115
+ */
116
+ export function fractional_factorial(k: number, p: number): any;
117
+
57
118
  /**
58
119
  * Generate a 2^k full factorial design.
59
120
  *
@@ -64,6 +125,18 @@ export function doe_anova(design_json: any, responses: Float64Array, factor_name
64
125
  */
65
126
  export function full_factorial(k: number): any;
66
127
 
128
+ /**
129
+ * Generate a Plackett-Burman screening design for `k` factors (1 ≤ k ≤ 19).
130
+ *
131
+ * Automatically selects the smallest N (multiple of 4) such that N − 1 ≥ k.
132
+ *
133
+ * Returns `{ data: [[f64]], factor_names: [str], run_count: usize, factor_count: usize }`.
134
+ *
135
+ * # Errors
136
+ * Returns an error string if `k == 0` or `k > 19`.
137
+ */
138
+ export function plackett_burman(k: number): any;
139
+
67
140
  /**
68
141
  * Compute Taguchi Signal-to-Noise ratios.
69
142
  *
@@ -79,6 +152,18 @@ export function full_factorial(k: number): any;
79
152
  */
80
153
  export function signal_to_noise(responses_json: any, goal: string): any;
81
154
 
155
+ /**
156
+ * Compute the steepest ascent path from a fitted RSM model.
157
+ *
158
+ * `coefficients_json`: JSON array of model coefficients (from `fit_rsm`).
159
+ * `factor_count`: number of factors in the model.
160
+ * `n_steps`: number of steps along the ascent path.
161
+ * `step_size`: step size in coded units.
162
+ *
163
+ * Returns `{ steps: [{ coded: [f64], step_number: usize }] }`.
164
+ */
165
+ export function steepest_ascent(coefficients_json: any, factor_count: number, n_steps: number, step_size: number): any;
166
+
82
167
  /**
83
168
  * Get a Taguchi orthogonal array.
84
169
  *
package/u_doe.js CHANGED
@@ -5,5 +5,5 @@ import { __wbg_set_wasm } from "./u_doe_bg.js";
5
5
  __wbg_set_wasm(wasm);
6
6
  wasm.__wbindgen_start();
7
7
  export {
8
- box_behnken, ccd, definitive_screening, doe_anova, full_factorial, signal_to_noise, taguchi_array, two_level_factorial_power
8
+ box_behnken, ccd, definitive_screening, desirability, doe_anova, estimate_effects, fit_rsm, fractional_factorial, full_factorial, plackett_burman, signal_to_noise, steepest_ascent, taguchi_array, two_level_factorial_power
9
9
  } from "./u_doe_bg.js";
package/u_doe_bg.js CHANGED
@@ -64,6 +64,32 @@ export function definitive_screening(k) {
64
64
  return takeFromExternrefTable0(ret[0]);
65
65
  }
66
66
 
67
+ /**
68
+ * Compute Derringer-Suich desirability for multiple responses.
69
+ *
70
+ * `specs_json`: JSON array of response specifications, each:
71
+ * `{ goal: "Maximize"|"Minimize"|"Target", lower, target, upper, s1, s2 }`
72
+ * `responses`: flat array of observed response values (one per spec).
73
+ *
74
+ * Returns `{ individual: [f64], overall: f64 }`.
75
+ *
76
+ * # Errors
77
+ * Returns an error string if JSON is malformed, specs/responses length mismatch,
78
+ * or goal string is unrecognised.
79
+ * @param {any} specs_json
80
+ * @param {Float64Array} responses
81
+ * @returns {any}
82
+ */
83
+ export function desirability(specs_json, responses) {
84
+ const ptr0 = passArrayF64ToWasm0(responses, wasm.__wbindgen_malloc);
85
+ const len0 = WASM_VECTOR_LEN;
86
+ const ret = wasm.desirability(specs_json, ptr0, len0);
87
+ if (ret[2]) {
88
+ throw takeFromExternrefTable0(ret[1]);
89
+ }
90
+ return takeFromExternrefTable0(ret[0]);
91
+ }
92
+
67
93
  /**
68
94
  * Perform DOE ANOVA.
69
95
  *
@@ -93,6 +119,86 @@ export function doe_anova(design_json, responses, factor_names_json, effect_name
93
119
  return takeFromExternrefTable0(ret[0]);
94
120
  }
95
121
 
122
+ /**
123
+ * Estimate main effects and interactions for a 2-level factorial design,
124
+ * plus half-normal plot data for identifying active effects.
125
+ *
126
+ * `design_json`: JSON array-of-arrays `[[f64]]` — the coded design matrix (rows = runs).
127
+ * `responses`: flat array of response values, one per run.
128
+ * `factor_names_json`: JSON array of factor name strings.
129
+ * `max_order`: maximum interaction order (1 = main effects only, 2 = + 2FI, 3 = + 3FI).
130
+ *
131
+ * Returns `{ effects: [{ name, estimate, sum_of_squares, percent_contribution }],
132
+ * half_normal: [[abs_effect, quantile]] }`.
133
+ *
134
+ * # Errors
135
+ * Returns an error string if dimensions do not match or JSON is malformed.
136
+ * @param {any} design_json
137
+ * @param {Float64Array} responses
138
+ * @param {any} factor_names_json
139
+ * @param {number} max_order
140
+ * @returns {any}
141
+ */
142
+ export function estimate_effects(design_json, responses, factor_names_json, max_order) {
143
+ const ptr0 = passArrayF64ToWasm0(responses, wasm.__wbindgen_malloc);
144
+ const len0 = WASM_VECTOR_LEN;
145
+ const ret = wasm.estimate_effects(design_json, ptr0, len0, factor_names_json, max_order);
146
+ if (ret[2]) {
147
+ throw takeFromExternrefTable0(ret[1]);
148
+ }
149
+ return takeFromExternrefTable0(ret[0]);
150
+ }
151
+
152
+ /**
153
+ * Fit a second-order Response Surface Model (RSM) using OLS.
154
+ *
155
+ * `design_json`: JSON array-of-arrays `[[f64]]` — the coded design matrix.
156
+ * `responses`: flat array of response values, one per run.
157
+ * `factor_names_json`: JSON array of factor name strings.
158
+ *
159
+ * Returns `{ coefficients: [f64], r_squared: f64, factor_count: usize }`.
160
+ * Coefficient order: [intercept, linear..., quadratic..., interactions...].
161
+ *
162
+ * # Errors
163
+ * Returns an error string if dimensions do not match, JSON is malformed,
164
+ * or the model matrix is singular.
165
+ * @param {any} design_json
166
+ * @param {Float64Array} responses
167
+ * @param {any} factor_names_json
168
+ * @returns {any}
169
+ */
170
+ export function fit_rsm(design_json, responses, factor_names_json) {
171
+ const ptr0 = passArrayF64ToWasm0(responses, wasm.__wbindgen_malloc);
172
+ const len0 = WASM_VECTOR_LEN;
173
+ const ret = wasm.fit_rsm(design_json, ptr0, len0, factor_names_json);
174
+ if (ret[2]) {
175
+ throw takeFromExternrefTable0(ret[1]);
176
+ }
177
+ return takeFromExternrefTable0(ret[0]);
178
+ }
179
+
180
+ /**
181
+ * Generate a 2^(k-p) fractional factorial design.
182
+ *
183
+ * Uses standard generators from Montgomery (2019) Table 8.14.
184
+ * Supported: k=4..7, p=1..3 (standard combinations only).
185
+ *
186
+ * Returns `{ data: [[f64]], factor_names: [str], run_count: usize, factor_count: usize }`.
187
+ *
188
+ * # Errors
189
+ * Returns an error string if the (k, p) combination is not in the standard table.
190
+ * @param {number} k
191
+ * @param {number} p
192
+ * @returns {any}
193
+ */
194
+ export function fractional_factorial(k, p) {
195
+ const ret = wasm.fractional_factorial(k, p);
196
+ if (ret[2]) {
197
+ throw takeFromExternrefTable0(ret[1]);
198
+ }
199
+ return takeFromExternrefTable0(ret[0]);
200
+ }
201
+
96
202
  /**
97
203
  * Generate a 2^k full factorial design.
98
204
  *
@@ -111,6 +217,26 @@ export function full_factorial(k) {
111
217
  return takeFromExternrefTable0(ret[0]);
112
218
  }
113
219
 
220
+ /**
221
+ * Generate a Plackett-Burman screening design for `k` factors (1 ≤ k ≤ 19).
222
+ *
223
+ * Automatically selects the smallest N (multiple of 4) such that N − 1 ≥ k.
224
+ *
225
+ * Returns `{ data: [[f64]], factor_names: [str], run_count: usize, factor_count: usize }`.
226
+ *
227
+ * # Errors
228
+ * Returns an error string if `k == 0` or `k > 19`.
229
+ * @param {number} k
230
+ * @returns {any}
231
+ */
232
+ export function plackett_burman(k) {
233
+ const ret = wasm.plackett_burman(k);
234
+ if (ret[2]) {
235
+ throw takeFromExternrefTable0(ret[1]);
236
+ }
237
+ return takeFromExternrefTable0(ret[0]);
238
+ }
239
+
114
240
  /**
115
241
  * Compute Taguchi Signal-to-Noise ratios.
116
242
  *
@@ -137,6 +263,29 @@ export function signal_to_noise(responses_json, goal) {
137
263
  return takeFromExternrefTable0(ret[0]);
138
264
  }
139
265
 
266
+ /**
267
+ * Compute the steepest ascent path from a fitted RSM model.
268
+ *
269
+ * `coefficients_json`: JSON array of model coefficients (from `fit_rsm`).
270
+ * `factor_count`: number of factors in the model.
271
+ * `n_steps`: number of steps along the ascent path.
272
+ * `step_size`: step size in coded units.
273
+ *
274
+ * Returns `{ steps: [{ coded: [f64], step_number: usize }] }`.
275
+ * @param {any} coefficients_json
276
+ * @param {number} factor_count
277
+ * @param {number} n_steps
278
+ * @param {number} step_size
279
+ * @returns {any}
280
+ */
281
+ export function steepest_ascent(coefficients_json, factor_count, n_steps, step_size) {
282
+ const ret = wasm.steepest_ascent(coefficients_json, factor_count, n_steps, step_size);
283
+ if (ret[2]) {
284
+ throw takeFromExternrefTable0(ret[1]);
285
+ }
286
+ return takeFromExternrefTable0(ret[0]);
287
+ }
288
+
140
289
  /**
141
290
  * Get a Taguchi orthogonal array.
142
291
  *
@@ -210,6 +359,10 @@ export function __wbg___wbindgen_debug_string_5398f5bb970e0daa(arg0, arg1) {
210
359
  getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
211
360
  getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
212
361
  }
362
+ export function __wbg___wbindgen_in_41dbb8413020e076(arg0, arg1) {
363
+ const ret = arg0 in arg1;
364
+ return ret;
365
+ }
213
366
  export function __wbg___wbindgen_is_function_3c846841762788c1(arg0) {
214
367
  const ret = typeof(arg0) === 'function';
215
368
  return ret;
@@ -219,6 +372,10 @@ export function __wbg___wbindgen_is_object_781bc9f159099513(arg0) {
219
372
  const ret = typeof(val) === 'object' && val !== null;
220
373
  return ret;
221
374
  }
375
+ export function __wbg___wbindgen_is_undefined_52709e72fb9f179c(arg0) {
376
+ const ret = arg0 === undefined;
377
+ return ret;
378
+ }
222
379
  export function __wbg___wbindgen_jsval_loose_eq_5bcc3bed3c69e72b(arg0, arg1) {
223
380
  const ret = arg0 == arg1;
224
381
  return ret;
@@ -256,6 +413,10 @@ export function __wbg_get_unchecked_329cfe50afab7352(arg0, arg1) {
256
413
  const ret = arg0[arg1 >>> 0];
257
414
  return ret;
258
415
  }
416
+ export function __wbg_get_with_ref_key_6412cf3094599694(arg0, arg1) {
417
+ const ret = arg0[arg1];
418
+ return ret;
419
+ }
259
420
  export function __wbg_instanceof_ArrayBuffer_101e2bf31071a9f6(arg0) {
260
421
  let result;
261
422
  try {
package/u_doe_bg.wasm CHANGED
Binary file