Skip to contents

Takes one residual data frame (as returned by build_residual_sets()) and builds the 3-D sequence array Xseq (shape [N, K, p+1]) and the pf tensor (shape [N, 1]) needed by the CNN1D model.

Usage

residual_to_tensors(
  df_res,
  scaler,
  K = 64L,
  knot_grid = seq(0, 1, length.out = K),
  pf_left = -2,
  pf_right = 7.6
)

Arguments

df_res

A residual data frame (one of set1 – set4).

scaler

A scaler object from fit_minmax().

K

Number of knot points (default 64).

knot_grid

Numeric vector of knot positions in [0, 1] (default seq(0, 1, length.out = K)).

pf_left

Left boundary of the pF domain (default -2).

pf_right

Right boundary of the pF domain (default 7.6).

Value

A named list with TensorFlow tensors:

Xseq

float32 tensor, shape [N, K, p+1].

pf

float32 tensor, shape [N, 1].

Examples

# \donttest{
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 = 10L, S2 = 10L,
                            S3 = 10L, S4 = 10L)
  tn <- residual_to_tensors(rs$set2, sc, K = 16L)
  tn$Xseq$shape
}
# }