Skip to contents

Replaces v1's SANN with L-BFGS-B plus analytic gradients via Deriv::Deriv applied to the eml-expanded master expression. After convergence, snaps each slot to its argmax one-hot vertex and reports the snapped MSE — values at machine epsilon squared indicate exact symbolic recovery.

Usage

eml_fit(
  x,
  y,
  depth = 3L,
  parameterization = c("simplex", "direct"),
  method = "L-BFGS-B",
  maxit = 1000L,
  n_restarts = 1L,
  seed = 42L
)

Arguments

x

numeric vector of inputs.

y

numeric vector of targets.

depth

integer >= 1.

parameterization

either "simplex" (logits → per-slot softmax; the paper's choice) or "direct" (raw scaling).

method

optim method; defaults to "L-BFGS-B".

maxit

maximum optimiser iterations.

n_restarts

number of independent random restarts; the best is returned. "Best" is the smallest continuous final loss — for exact symbolic recovery this coincides with the snapping vertex when the global optimum sits at a grammar vertex (as it does for the paper's exp/log targets); it is not selected on snap_mse.

seed

RNG seed for reproducibility (each restart shifts it by 1).

Value

List with par, theta, theta_snap, pred, pred_snap, final_value, snap_mse, n_restarts_run, best_seed.

Examples

# \donttest{
xs <- seq(0.5, 5, length.out = 30)
ys <- log(xs)
fit <- eml_fit(xs, ys,
  depth = 3, n_restarts = 2,
  maxit = 200, seed = 1
)
fit$snap_mse # ~ 0 indicates exact symbolic recovery of log(x)
#> [1] 5.399024e-33
# }