Skip to content

Add optimize_responses (Tool 4) for DOE response optimization#74

Merged
kgdunn merged 10 commits into
mainfrom
claude/add-experiments-docs-bj0Gc
Apr 13, 2026
Merged

Add optimize_responses (Tool 4) for DOE response optimization#74
kgdunn merged 10 commits into
mainfrom
claude/add-experiments-docs-bj0Gc

Conversation

@kgdunn
Copy link
Copy Markdown
Owner

@kgdunn kgdunn commented Apr 13, 2026

Summary

Implement Tool 4 (optimize_responses) — find optimal factor settings for one or multiple responses after fitting a model with analyze_experiment (Tool 3).

Implemented methods

  • Derringer-Suich desirability — single and multi-response optimization with weighted geometric mean composite, optimized via scipy SLSQP with multi-start
  • Stationary point — locate the optimum of a second-order model via numpy.linalg.solve
  • Canonical analysis — eigenvalue decomposition of the B matrix to classify response surface shape (maximum / minimum / saddle)
  • Steepest ascent / descent — move along the gradient of a first-order model from the design centre, generating a step table in coded and actual units
  • Model evaluation layer — parse coefficient term names (Intercept, A, A:B, I(A ** 2)) and evaluate the polynomial at arbitrary coded points (the glue between Tool 3 output and the optimizer)

Stubs (planned for later)

  • Ridge analysis — trace optimum along increasing radii
  • Pareto front — multi-objective NSGA-II

Changes

  • process_improve/experiments/optimization.py — Complete rewrite replacing legacy MATLAB skeleton (~500 lines)
  • process_improve/experiments/tools.py — New optimize_responses tool wrapper with full JSON schema for LLM integration
  • process_improve/experiments/__init__.py — Export optimize_responses
  • tests/test_optimization.py — 74 unit tests covering all methods, desirability functions, dispatcher, validation, and tool wrapper
  • docs/doe/coverage.md — Updated status from "Not started" to "Partial"

Test plan

  • All 74 new tests pass (pytest tests/test_optimization.py -v)
  • All 38 existing analysis tests pass (no regressions)
  • ruff check passes on all modified files
  • Tool discovery includes optimize_responses in experiments category

https://claude.ai/code/session_01Br5mDwaoXvGsaQJZLS5oCV

claude added 10 commits April 13, 2026 06:41
Implement the response optimization engine for designed experiments:
- Model evaluation layer: parse coefficient terms and evaluate polynomial
  at arbitrary coded points (the glue between Tool 3 and the optimizer)
- Stationary point analysis via numpy.linalg.solve on second-order models
- Canonical analysis via eigenvalue decomposition of the B matrix
- Steepest ascent/descent path generation from first-order coefficients
- Derringer-Suich desirability functions (maximize, minimize, target)
  with weighted geometric mean composite and scipy SLSQP multi-start
- Stubs for ridge analysis and Pareto front (planned for later)
- Public dispatcher optimize_responses() routing to all methods

https://claude.ai/code/session_01Br5mDwaoXvGsaQJZLS5oCV
Register optimize_responses as an agent-callable tool with full JSON
schema for LLM integration. The tool accepts fitted model coefficients,
optimization goals, and method selection, dispatching to the core
optimization module.

Also export optimize_responses from the experiments __init__.py.

https://claude.ai/code/session_01Br5mDwaoXvGsaQJZLS5oCV
Initial test file for Tool 4 (optimize_responses) with reusable model
coefficient fixtures for quadratic, linear, saddle, and minimum models,
plus tests for the internal _parse_term function.

https://claude.ai/code/session_01Br5mDwaoXvGsaQJZLS5oCV
Test polynomial evaluation at known points (origin, corners) for both
linear and quadratic models, plus verify correct extraction of the b
vector and symmetric B matrix from coefficient lists.

https://claude.ai/code/session_01Br5mDwaoXvGsaQJZLS5oCV
Test classification (maximum, minimum, saddle), eigenvalue extraction,
coded-to-actual conversion, and error handling for linear models that
lack quadratic terms.

https://claude.ai/code/session_01Br5mDwaoXvGsaQJZLS5oCV
Verify direction vectors, step counts, monotonic response increase for
ascent, coded-to-actual conversion, and error on zero coefficients.

https://claude.ai/code/session_01Br5mDwaoXvGsaQJZLS5oCV
Cover maximize, minimize, target desirability functions, individual
desirability dispatch, and composite (weighted geometric mean) with
edge cases (zero values, empty list, weight effects).

https://claude.ai/code/session_01Br5mDwaoXvGsaQJZLS5oCV
Test end-to-end desirability optimisation (single and multi-response),
stub methods returning proper status, dispatcher routing for all
methods, validation errors, and tool wrapper JSON round-trip.

https://claude.ai/code/session_01Br5mDwaoXvGsaQJZLS5oCV
Mark Tool 4 as partially implemented with desirability, steepest
ascent/descent, stationary point, and canonical analysis. Ridge
analysis and Pareto front remain as stubs.

https://claude.ai/code/session_01Br5mDwaoXvGsaQJZLS5oCV
Remove unused noqa directives, add strict=True to zip() calls,
replace ternary with or operator, add PLR0913 noqa for functions
with many args, and add docstrings to all test methods to satisfy
D102 rule.

https://claude.ai/code/session_01Br5mDwaoXvGsaQJZLS5oCV
@kgdunn kgdunn merged commit 50815c8 into main Apr 13, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants