Skip to contents

Constructs a Keras model implementing the monotone-integral architecture of Norouzi et al. (2025). The returned list contains two models that share weights:

  • theta_model — full prediction model (pF query + covariates → theta).

  • param_model — extracts the saturated water content (theta_s) from covariates only.

Usage

build_swrc_model(
  n_covariates,
  hidden = c(128L, 64L),
  dropout = 0.1,
  K = 64L,
  monotone = TRUE
)

Arguments

n_covariates

Integer. Number of soil-property covariates (p).

hidden

Integer vector of length 2. Number of filters in the first and second Conv1D layers (default c(128L, 64L)).

dropout

Numeric dropout rate after each Conv1D layer (default 0.10).

K

Integer. Number of knot points for the cumulative integration grid (default 64L).

monotone

Logical. TRUE (default) builds the monotone integral head, which guarantees \(\partial\theta/\partial pF \le 0\) for any parameter values. FALSE replaces it with a dense head that emits \(\theta\) directly and is free to produce a non-monotone curve. The backbone, knots, scaling and inputs are identical either way, so the two differ only in the output construction. Use FALSE as an ablation control, to measure what the monotone architecture contributes rather than assert it; it is not a modelling recommendation.

Value

A named list:

theta_model

Keras model: inputs [Xseq_knots, pf_norm], output shape [N, 2] (theta_hat, theta_s).

param_model

Keras model: input Xseq_knots, output shape [N, 1] (theta_s only).

K

The K value used.

dk

The knot spacing 1 / (K - 1).

knot_grid

Numeric vector of knot positions.

Examples

# \donttest{
# Building the graph needs a working TensorFlow; without one this is a
# no-op rather than an error, so the example is safe to run anywhere.
if (reticulate::py_module_available("tensorflow")) {
  # K = 16 keeps the example well inside CRAN's time budget on a
  # machine that does have TensorFlow; the default is K = 64.
  mod <- build_swrc_model(n_covariates = 9L, K = 16L)
  mod$theta_model$count_params()
}
#> Downloading uv...
#> Done!
# }