Compose The Libraries: Analyze A Partial Factorial Study#

This tutorial samples model-size and design-task combinations instead of running their full cross product. It executes deterministic ideation traces, exports canonical events, and fits a regression directly from the artifact.

What You Will Learn#

  • Define a larger factor space while materializing a deliberate partial matrix.

  • Bind problem IDs and model metadata to explicit conditions.

  • Return normalized custom-agent metrics and event sequences.

  • Fit numeric and categorical predictors without manually loading CSV tables.

  • Keep regression inputs traceable to the exported experiment artifact.

Install And Run#

Download partial_factorial_ideation_regression.py, open its containing folder in VS Code, and use the integrated terminal:

python -m pip install design-research==0.4.0
python partial_factorial_ideation_regression.py

Core Orchestration#

The excerpt shows the user-facing run and analysis path. The complete source also defines the explicit condition matrix and deterministic participant.

 1def main() -> None:
 2    """Run a larger ideation DOE without touching the exported tables directly."""
 3    # Build the study separately from the condition matrix so the tutorial can
 4    # show both pieces of a custom design of experiments.
 5    study = _study()
 6    conditions = _partial_factorial_conditions()
 7
 8    # The scripted agent keeps execution offline and deterministic, but it still
 9    # returns the same result shape expected from a live ideation agent.
10    results = dr.experiments.run_study(
11        study,
12        conditions=conditions,
13        agent_bindings={AGENT_ID: _ideation_agent},
14        checkpoint=False,
15        show_progress=False,
16    )
17
18    # Persist the standard artifacts before analysis. This keeps the example
19    # aligned with a reproducible workflow where tables can be inspected later.
20    artifacts = dr.experiments.export_analysis_tables(
21        study,
22        conditions=conditions,
23        run_results=results,
24        output_dir=study.output_dir / "analysis",
25        validate_with_analysis_package=True,
26    )
27
28    # Fit a linear model from artifacts with both a numeric predictor and a
29    # categorical task-family predictor. No user code touches the CSV tables.
30    regression = dr.analysis.fit_regression_from_artifacts(
31        artifacts["events.csv"],
32        outcome=PRIMARY_METRIC,
33        predictors=("model_size_b", "task_family"),
34        categorical_predictors=("task_family",),
35    )
36    validation = dr.analysis.validate_experiment_events(artifacts["events.csv"])
37
38    # Print the regression headline and validation status; the detailed rows stay
39    # in the generated artifacts.
40    print("Partial factorial ideation regression:", study.study_id)
41    print("Conditions:", len(conditions))
42    print("Runs:", len(results))
43    print("Event rows valid:", validation.is_valid, f"(rows={validation.n_rows})")
44    print("Regression samples:", regression.n_samples)
45    print("Model size coefficient:", f"{regression.coefficients['model_size_b']:.4f}")
46    print("Task family terms:", _task_terms(regression.coefficients))
47    print("R2:", f"{regression.r2:.3f}")
48    print("Artifacts directory:", artifacts["events.csv"].parent)
49
50

Selected Output#

The script also lists the fitted task-family terms and artifact directory. These lines capture the main regression checks:

Partial factorial ideation regression: partial_factorial_ideation_regression
Conditions: 12
Runs: 24
Event rows valid: True (rows=120)
Regression samples: 24
Model size coefficient: 0.0098
R2: 0.992

Use an explicit partial matrix only when its estimable effects match the research question. For generated fractional-factorial or Latin-hypercube designs, use the DOE helpers owned by design-research-experiments.

Continue to Prompt Strategy Comparison Walkthrough to replace deterministic participant logic with a managed local model while preserving the same artifact boundary.