Skip to contents

Holds the fine-grid counts and an optional compiled index for repeated evaluation. The R counts are retained so saved objects can rebuild their native index after loading in another session.

Usage

prepare_glbfp(
  data,
  b = NULL,
  m = NULL,
  estimator = c("GLBFP", "LBFP", "ASH"),
  min_vals = NULL,
  max_vals = NULL,
  engine = c("auto", "R", "cpp_direct", "cpp_prefix")
)

# S3 method for class 'glbfp_model'
predict(object, newdata = NULL, ...)

Arguments

data

Numeric observations (n x d) or a glbfp_field().

b

Positive bandwidth vector of length d. If NULL, use the Gaussian-reference L1 heuristic compute_bi_optim() with the supplied m.

m

Positive integer vector of length d. NULL means all ones; the LBFP method always uses ones.

estimator

"GLBFP", "LBFP", or "ASH".

min_vals

Fine-cell lower-bound anchor. NULL uses sample minima.

max_vals

Upper plotting limits. They do not clamp the density support. NULL uses sample maxima. All cells outside the occupied set have zero count.

engine

"auto", "R", "cpp_direct", or "cpp_prefix". Auto uses direct enumeration when the nominal stencil has at most 64 cells, prefix traversal otherwise. This is a computational heuristic, not an optimality claim. All engines use the same counts and weights.

object

Prepared model.

newdata

Matrix/data frame of evaluation points. NULL uses the training observations. Evaluation does not use nearest-grid interpolation.

...

Unused additional arguments.

Value

A glbfp_model object, accepted by compute_Di() and predict().

Details

For delta = b/m and anchor a = min_vals, cell k (zero-based) is [a + k*delta, a + (k+1)*delta), with center a + (k+1/2)*delta. ASH uses triangular weighted fine-cell counts. GLBFP interpolates ASH heights at fine-cell centers. LBFP is GLBFP with m=1. The lattice is unbounded; finite sample support is completed by zero counts, without extrapolation. Exact boundary assignment uses floating-point floor((x-a)/delta) without an undocumented snapping tolerance. Extremely small cells or unrepresentable integer indices are rejected.

Examples

set.seed(1)
x <- matrix(rnorm(100), ncol = 1)
model <- prepare_glbfp(x, b = 0.8, m = 2)
predict(model, matrix(c(-1, 0, 1), ncol = 1))
#> [1] 0.1969656 0.4252297 0.2733016
compute_Di(model)
#> Leave-one-out D_i scores
#> Method: GLBFP 
#> Observations: 100 
#> Dimension: 1 
#> Bandwidths (b): 0.8 
#> Shifts (m): 2 
#> D_i range: 0.0120804088705777 to 0.500262832263295