| compute_physics_loss | R Documentation |
Evaluates four physics constraints against the current model weights:
Second derivative |\partial^2\theta/\partial pF^2|
in the dry end pF \in [5, 7.6] should be near zero (linearity).
\theta(pF = 6.2) \geq 0 (non-negativity).
\theta(pF = 7.6) \leq 0 (non-positivity),
or \theta(pF = 7.6) = 0 when s3_form = "equality".
First derivative |\partial\theta/\partial pF|
near zero in the saturated plateau pF \in [-2, -0.3].
compute_physics_loss(
theta_model,
res_tensors,
lambda3 = 1,
lambda4 = 1000,
lambda5 = 1000,
lambda6 = 1,
s3_form = c("inequality", "equality"),
pf_left = -2,
pf_right = 7.6,
training = TRUE,
pF_lin_min = 5,
pF_lin_max = 7.6
)
theta_model |
A Keras model with two inputs: |
res_tensors |
A named list with four sublists ( |
lambda3 |
Weight for S1 linearity loss (default 1.0). |
lambda4 |
Weight for S2 non-negativity loss (default 1000.0). |
lambda5 |
Weight for S3 non-positivity loss (default 1000.0). |
lambda6 |
Weight for S4 saturation loss (default 1.0). |
s3_form |
Form of the S3 dry-end residual. The published inequality is satisfied by any non-positive value, and under
a monotone decreasing curve it therefore pushes the whole dry end below
zero, which in turn forces It does NOT remove the degenerate optimum |
pf_left |
Left boundary of the normalised pF domain (default -2). |
pf_right |
Right boundary (default 7.6). |
training |
Logical passed to the model call (default |
pF_lin_min, pF_lin_max |
pF range of the S1 linearity term (defaults
|
A named list of TensorFlow scalars:
L_phys, L_lin, L_pos, L_neg, L_sat.
if (reticulate::py_module_available("tensorflow")) {
df <- prepare_swrc_data(swrc_example, depth_col = "depth")
x <- c("clay", "silt", "bd_gcm3", "soc", "Depth_num")
sc <- fit_minmax(df, x)
rs <- build_residual_sets(df[, x], x, S1 = 20L, S2 = 20L,
S3 = 20L, S4 = 20L)
rt <- lapply(rs, residual_to_tensors, scaler = sc, K = 16L)
mod <- build_swrc_model(n_covariates = length(x), K = 16L)
# The published inequality leaves S3 at zero cost for any negative
# theta(pF 7.6); the equality penalises the distance from zero in
# either direction. L_neg differs between the two for the same weights.
ineq <- compute_physics_loss(mod$theta_model, rt, s3_form = "inequality")
eqty <- compute_physics_loss(mod$theta_model, rt, s3_form = "equality")
c(inequality = as.numeric(ineq$L_neg), equality = as.numeric(eqty$L_neg))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.