Skip to content

Commit 580d693

Browse files
boxcrete: V2 strength GP — final-form module layout
Introduces the V2 strength GP — a multiplicatively-gated kernel architecture that structurally enforces the physics constraint f(x, t=0) = 0 with zero posterior variance — plus the supporting public API and the saved model artifact. Module layout (each module focused on one concept): * boxcrete/concrete_model.py — SustainableConcreteModel (the multi-output joint GWP/slump/strength model) and AppendDerivedFeatures. * boxcrete/strength_model.py — public fit/load API for V2: fit_strength_gp() and load_pretrained_strength_gp(). Hosts the V2 fit factory and ChainedInputTransform composition. * boxcrete/kernels.py — kernel primitives: TimeGatedKernel, within_group_prior, ard_matern_with_within_group_prior, additive_time_kernel, build_strength_kernel_for_aug_dim, make_gated_strength_kernel_builder. * boxcrete/features.py — features and transforms: F5_ALLLOG_FEATURES, GATE_TAU, IDX, FEATURE_BUILDERS, append_engineered_features_callable, augmented_bounds, max_scale_Y. * boxcrete/likelihoods.py — GatedGaussianLikelihood (heteroscedastic Gaussian with h(t)² gating, paired with the gated kernel) and PartialFixedNoiseLikelihood. * boxcrete/priors.py — WithinGroupShrinkagePrior + the binder / aggregate group definitions used for ARD lengthscale shrinkage. * boxcrete/slump_model.py — fit_slump_gp() for the slump model. * boxcrete/strength_model_legacy.py — V1 helpers retained for backward compatibility (get_strength_gp_input_transform). Replaces the legacy boxcrete/models.py (758 lines) with the focused modules above. Persisted artifact: * docs/model/strength_model.pt — PyTorch state_dict for the deployed V2 strength GP. load_pretrained_strength_gp() reconstructs the full SingleTaskGP from this without re-fitting. Float64 throughout the fit (precision fix): explicit dtype=torch.float64 in boxcrete/utils.py (bounds, constraint coefficients), strength_model.py (time-transform parameters), and priors.py (MVN loc/scale). Without this, ~7-decimal float32 precision was sensitive enough to per-runner CPU rounding that L-BFGS-B occasionally landed in different local optima — including a wb_ratio-railed basin. Tests: * test/test_lengthscale_identifiability.py — guards lengthscales remain identifiable (no rail-at-cap pathologies); also asserts fresh-fit predictions agree with committed test_vectors.json within a cross-architecture-portable tolerance. * test/test_strength_curve_monotonicity.py — physical-constraint regression for monotonic strength evolution (committed JSON + freshly-fit V2). * test/test_pretrained_loader_fidelity.py — guards the state_dict round-trip reproduces the trained model's predictions exactly. * test/test_public_api.py — public API surface guard.
1 parent 348b0ac commit 580d693

28 files changed

Lines changed: 4301 additions & 2788 deletions

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ This repository contains probabilistic models and data for the
1616
2) The associated global warming potential (GWP)
1717
3) Slump prediction using Gaussian Process regression with derived features
1818

19-
as a function of their composition, consisting of cement, fly ash, slag, fine and coarse aggregate, admixtures, and water, to name a few basic ingredients. See `boxcrete/models.py` for implementation details.
19+
as a function of their composition, consisting of cement, fly ash, slag, fine and coarse aggregate, admixtures, and water, to name a few basic ingredients. See `boxcrete/concrete_model.py` for implementation details.
2020

2121
### Included Data
2222

@@ -51,7 +51,7 @@ pip install -e ".[notebooks]"
5151
```python
5252
import torch
5353
from boxcrete.utils import load_concrete_strength, get_bounds
54-
from boxcrete.models import SustainableConcreteModel
54+
from boxcrete.concrete_model import SustainableConcreteModel
5555
from boxcrete.plotting import plot_strength_curve
5656

5757
# Load data and fit models
@@ -105,7 +105,7 @@ The models can be used for a variety of tasks, including but not limited to
105105

106106
## Compressive Strength Model
107107

108-
The `SustainableConcreteModel` in [`boxcrete/models.py`](boxcrete/models.py) includes a strength_model that predicts the evolution of compressive strength as a function of mixture composition. A demo is provided in [`notebooks/strength_curve_prediction_demo.ipynb`](notebooks/strength_curve_prediction_demo.ipynb), which demonstrates how the model can be used to predict the full strength development curve for any user-specified mix. A comprehensive tutorial covering prediction, calibration, Pareto frontiers, and gradient-based experimental design is available in [`notebooks/prediction_and_optimization_tutorial.ipynb`](notebooks/prediction_and_optimization_tutorial.ipynb). The model is based on Gaussian Process (GP) regression and incorporates custom modeling steps to ensure physically consistent strength evolution and calibrated uncertainty.
108+
The `SustainableConcreteModel` in [`boxcrete/concrete_model.py`](boxcrete/concrete_model.py) includes a strength_model that predicts the evolution of compressive strength as a function of mixture composition. A demo is provided in [`notebooks/strength_curve_prediction_demo.ipynb`](notebooks/strength_curve_prediction_demo.ipynb), which demonstrates how the model can be used to predict the full strength development curve for any user-specified mix. A comprehensive tutorial covering prediction, calibration, Pareto frontiers, and gradient-based experimental design is available in [`notebooks/prediction_and_optimization_tutorial.ipynb`](notebooks/prediction_and_optimization_tutorial.ipynb). The model is based on Gaussian Process (GP) regression and incorporates custom modeling steps to ensure physically consistent strength evolution and calibrated uncertainty.
109109

110110
### Strength Curve Predictions
111111

boxcrete/__init__.py

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,36 @@
44
# This source code is licensed under the MIT license found in the
55
# LICENSE file in the root directory of this source tree.
66

7-
from boxcrete.model_utils import FixedFeatureModel, LinearModel
8-
from boxcrete.models import (
7+
from boxcrete.concrete_model import SustainableConcreteModel
8+
from boxcrete.features import (
99
AppendDerivedFeatures,
10-
fit_slump_gp,
11-
fit_strength_gp,
12-
get_strength_gp_input_transform,
13-
PartialFixedNoiseLikelihood,
14-
SustainableConcreteModel,
15-
WithinGroupShrinkagePrior,
10+
F5_ALLLOG_FEATURES,
11+
FEATURE_BUILDERS,
12+
GATE_TAU,
13+
IDX,
14+
append_engineered_features_callable,
15+
augmented_bounds,
16+
max_scale_Y,
17+
)
18+
from boxcrete.kernels import (
19+
TimeGatedKernel,
20+
additive_time_kernel,
21+
ard_matern_with_within_group_prior,
22+
build_strength_kernel_for_aug_dim,
23+
make_gated_strength_kernel_builder,
1624
)
25+
from boxcrete.likelihoods import GatedGaussianLikelihood, PartialFixedNoiseLikelihood
26+
from boxcrete.model_utils import FixedFeatureModel, LinearModel
1727
from boxcrete.plotting import (
1828
compute_loo_cv,
1929
plot_calibration,
2030
plot_feature_importance,
2131
plot_strength_curve,
2232
)
33+
from boxcrete.priors import WithinGroupShrinkagePrior, within_group_prior
34+
from boxcrete.slump_model import fit_slump_gp
35+
from boxcrete.strength_model import fit_strength_gp, load_pretrained_strength_gp
36+
from boxcrete.strength_model_legacy import get_strength_gp_input_transform
2337
from boxcrete.units import (
2438
convert_slump,
2539
convert_strength,
@@ -69,7 +83,12 @@
6983
"DEFAULT_X_COLUMNS",
7084
"DEFAULT_Y_COLUMNS",
7185
"DEFAULT_YSTD_COLUMNS",
86+
"F5_ALLLOG_FEATURES",
87+
"FEATURE_BUILDERS",
7288
"FixedFeatureModel",
89+
"GATE_TAU",
90+
"GatedGaussianLikelihood",
91+
"IDX",
7392
"LinearModel",
7493
"MORTAR_BOUNDS_DICT",
7594
"MORTAR_CONSTRAINTS",
@@ -80,8 +99,14 @@
8099
"STRENGTH_DISPLAY_SCALE",
81100
"SustainableConcreteDataset",
82101
"SustainableConcreteModel",
102+
"TimeGatedKernel",
83103
"UnitSystem",
84104
"WithinGroupShrinkagePrior",
105+
"additive_time_kernel",
106+
"append_engineered_features_callable",
107+
"ard_matern_with_within_group_prior",
108+
"augmented_bounds",
109+
"build_strength_kernel_for_aug_dim",
85110
"compute_loo_cv",
86111
"convert_slump",
87112
"convert_strength",
@@ -93,12 +118,16 @@
93118
"get_reference_point",
94119
"get_strength_gp_input_transform",
95120
"load_concrete_strength",
121+
"load_pretrained_strength_gp",
122+
"make_gated_strength_kernel_builder",
96123
"make_linear_coefficients",
124+
"max_scale_Y",
97125
"plot_calibration",
98126
"plot_feature_importance",
99127
"plot_strength_curve",
100128
"predict_pareto",
101129
"reduce_to_optimization_space",
102130
"slump_label",
103131
"strength_label",
132+
"within_group_prior",
104133
]

0 commit comments

Comments
 (0)