Skip to main content

Module smooth

Module smooth 

Source

Re-exports§

pub use penalty_priors::CoefficientGroupSpec;
pub use penalty_priors::CoefficientSelector;
pub use penalty_priors::PenaltyBlockGammaPriorMetadata;
pub use penalty_priors::RealizedCoefficientGroups;
pub use self::structure_analysis::SmoothStructureAnalysis;
pub use self::structure_analysis::analyze_smooth_ownership;
pub use self::structure_analysis::smooth_term_feature_cols;

Modules§

input_standardization
Per-axis input standardization and length-scale compensation helpers for the spatial smooth arm.
penalty_priors
Penalty-block Gamma hyperprior realization and coefficient-group resolution for the term collection.
shape_constraints
Shape-constraint (monotone / convex / concave) machinery for the 1-D smooth arm.
structure_analysis

Structs§

AdaptiveRegularizationDiagnostics
AdaptiveSpatialMap
BlockwisePenalty
A penalty matrix stored at its natural block size together with the column range it occupies in the global coefficient vector.
DroppedPenaltyBlockInfo
FactorSmoothSpec
JointSpatialCenterGroupKey
KroneckerPenaltySystem
Factored representation of tensor-product penalties with precomputed marginal eigensystems for O(∏q_j) logdet and penalty operations.
LinearColumnConditioning
LinearFitConditioning
LinearTermSpec
LocalSmoothTermBuild
PcaScoresMemmapDesignOperator
PenaltyBlockInfo
RandomEffectBlock
RandomEffectTermSpec
Random-effects term specification.
RawSmoothDesign
SmoothDesign
SmoothTerm
SmoothTermSpec
SpatialLengthScaleOptimizationOptions
SpatialLogKappaCoords
SpatialPsiDerivative
StandardLatentCoordConfig
TensorBSplineSpec
TensorMarginRangeNullProjectors
TermCollectionDesign
TermCollectionSpec

Enums§

AnisoBoundEnd
Which end of the ψ bound the shared aniso_bounds_from_data helper is computing. The lower end uses -max_length_scale.ln() as the pure-Duchon fallback and the .0 element of spatial_term_psi_bounds; the upper end uses -min_length_scale.ln() and .1. Everything else is identical.
BoundedCoefficientPriorSpec
BySmoothKind
ByVarKind
ByVariableSpec
FactorSmoothFlavour
LinearCoefficientGeometry
PenaltyStructureHint
ShapeConstraint
SmoothBasisSpec
SmoothError
Typed errors emitted by smooth-term helpers in the smooth module.
TensorBSplineIdentifiability
TensorBSplinePenaltyDecomposition

Constants§

BLOCK_SPARSE_MAX_DENSITY
BLOCK_SPARSE_ZERO_EPS
CONSTANT_CURVATURE_KAPPA_CHART_FRACTION
Hard positive cap on |κ| relative to the data’s inverse squared chart radius. The κ-stereographic chart is valid for 1 + κ‖x‖² > 0; at |κ| = 1/R² (R² = max squared chart radius) the gauge 1 + κ‖x‖² reaches the chart edge for the farthest data point, so the optimizer is boxed to a safe fraction of that scale on both sides. κ = 0 (flat) is the centre of the window, an interior point of the S^d ← ℝ^d → H^d family — exactly the reachability the raw-κ (not log-κ) coordinate exists to preserve.
CONSTANT_CURVATURE_MIN_CHART_RADIUS2
Floor on the data’s squared chart radius used to scale the κ window, so a degenerate (near-origin) point cloud still yields a finite, usable bracket rather than an unbounded one.
KERNEL_RANGE_MAX_SPACING_MULTIPLE
Upper edge of the data-derived kernel-range window, as a multiple of the minimum pairwise distance r_min: beyond 100/r_min the radial columns go nearly collinear with the polynomial nullspace, so the kernel range is capped here to keep the basis geometry well-conditioned.
KERNEL_RANGE_MIN_DIAMETER_FRACTION
Per-term data-derived ψ = log κ bounds.
MEASURE_JET_PSI_ALPHA_BOUNDS
Measure-jet ψ dial boxes. The dials are NOT log-kernel-scales, so the κ-window machinery never applies: α spans density-weighted (0) through past-Coifman–Lafon (>1) normalization, and lnτ covers the ridge from numerically-exact-projection to heavy noise-floor damping. (The energy order s is the pinned explicit value or absorbed by the REML-learned per-scale amplitudes — see measure_jet_penalty_psi_dim — so it carries no dial box.)
MEASURE_JET_PSI_LN_LENGTH_SCALE_BOUNDS
Log-ℓ box for the design-moving representer length-scale dial (#1116). An ABSOLUTE window in the data coordinate scale (ln of ℓ ∈ [1e-3, 1e2]) used only when the spec explicitly enrolls the learned representer range. Absolute (not seed-relative) so the bound producer needs no data view, matching the other dial boxes. ln(1e-3) = -6.9077…, ln(1e2) = 4.6051….
MEASURE_JET_PSI_LN_TAU_BOUNDS
NULLSPACE_WELLDET_DEGENERACY_RHO_SD
Standard deviation of the wide, weakly-informative symmetric Normal prior placed on a relaxable double-penalty smooth’s DoublePenaltyNullspace selection coordinate when the fit is well-determined.
SMOOTH_HEAD_KEYWORDS
Smooth-term head keywords recognised by the formula DSL. A shape= option may be attached to any term whose head is one of these.

Functions§

all_spatial_terms_kappa_fixed
apply_by_variable_to_local_build
apply_measure_jet_psi
Write optimized ψ dials back into a measure-jet spec. Returns true when any dial actually moved. The geometry (centers, masses, band, ℓ, z) is ψ-FIXED by contract — only the dials change, so frozen-quadrature rebuilds reproduce the identical penalty layout at the new dials.
apply_response_aware_anisotropy_seed
Conservative, response-aware anisotropy seed nudge applied before the κ outer loop. For each anisotropic spatial term it adds a BOUNDED multiple of the per-axis response-structure contrast (response_aware_axis_contrasts) on top of the existing geometry seed, so the optimizer starts in the correct basin instead of at a response-blind near-symmetric point (the #1376 under-recovery where a signal axis and a nuisance axis with equal coordinate spread seed to ~[0,0]). The nudge is clamped to keep this a perturbation, never a hard override, so shared aniso Matérn/Duchon fits cannot be destabilized by it.
apply_shape_constraints_to_formula
Rewrite smooth-term calls in formula so each named smooth carries a shape=<kind> option understood by the formula DSL.
assemble_term_collection_design_matrix
auto_init_length_scale_in_basis
Replace the 0.0 auto-init length-scale sentinel with a data-derived value for any Matern / thin-plate kernel reachable from this basis — including the inner kernel of a by=/factor-smooth wrapper.
auto_init_length_scale_in_place
Walk a term and, if it is a Matern or thin-plate smooth whose length_scale was left at the auto sentinel (0.0), overwrite it with auto_initial_length_scale.
auto_initial_length_scale
Compute a data-driven initial length scale from the per-axis range of the feature columns. The heuristic max_range / sqrt(n) puts the kernel on the wiggly side of REML’s basin so the optimizer can grow it back if the signal is smooth, but is small enough that high-frequency truths remain reachable for smoother kernels (ν ≥ 5/2). Clamped to a tiny positive floor so degenerate constant-input columns can’t produce 0.
blocks_have_intrinsic_sparse_structure
bspline_basis_min_rows
Lower bound on the number of sample rows a 1D B-spline smooth needs for a well-posed penalized REML fit. Used as the per-smooth row floor in SmoothBasisSpec::min_sample_rows.
build_by_smooth_local
Build the local smooth term for a BySmooth spec, which unifies numeric-by and factor-by modulation into a single SmoothTermSpec.
build_factor_smooth
Build a factor-smooth interaction basis (bs="fs"/"sz"/"re").
build_pca_smooth_basis
build_random_effect_block
build_single_local_smooth_term
build_smooth_design
build_smooth_design_withworkspace
Like build_smooth_design, but honors the caller workspace policy while building each planned smooth term with an independent per-term workspace.
build_smooth_design_withworkspace_unvalidated
build_tensor_bspline_basis
build_term_collection_derivative_design
Build the EXACT analytic average-derivative design ∂(design row)/∂x_c of a term collection: the matrix D whose row i is ∂X[i,:]/∂x_{deriv_col}, laid out column-for-column identically to build_term_collection_design, so D · β = ∂m/∂x_{deriv_col}(x_i) for the fitted coefficient vector β (#1120).
build_term_collection_design
build_term_collection_design_inner
center_aniso_log_scales
constant_curvature_kappa_bounds
(κ_min, κ_max) outer-optimization window for a constant-curvature term, derived from the data’s maximum squared chart radius so the κ-jets never leave the κ-stereographic chart. Symmetric about κ = 0: ±CONSTANT_CURVATURE_KAPPA_CHART_FRACTION / R².
constant_curvature_term_spec
The constant-curvature smooth’s spec, when term_idx is one. Single accessor for every κ-ψ dispatch below, mirroring measure_jet_term_spec.
default_linear_term_double_penalty
default_pca_chunk_size
default_pca_smooth_penalty
default_random_effect_penalized
defer_inner_model_centering_to_factor_level_wrapper
A factor-level by= wrapper owns the model-space centering of its inner smooth: it gates the raw/structurally-constrained basis to the level rows and then centers that gated block exactly once against the level indicator (build_parametric_constraint_block_for_term in design_construction). Leaving the inner B-spline’s default pooled weighted-sum-to-zero active here would impose two generically-independent constraints — the pooled column moment m = Σ_h m_h and the per-level moment m_g — so a raw k-column basis collapses to k-2 columns per level instead of k-1, deleting one genuine nonconstant spline direction before REML runs (#1427). The group main effect carries only the constant, so it cannot restore that direction.
dense_local_margin_to_sparse
describe_thin_plate_center_request
ensure_by_variable_specs_match
factor_smooth_marginal_for_replay
Marginal B-spline spec for a factor-smooth block. The marginal always builds without an identifiability constraint (the per-level replication, not a sum-to-zero side constraint, provides identifiability against the parametric block). At predict time the marginal’s knot geometry has already been pinned into marginal.knotspec by the metadata replay, so the spec is used verbatim aside from clearing the identifiability transform.
freeze_measure_jet_length_scale_learning
freeze_raw_spatial_metadata
freeze_term_collection_from_design
get_spatial_aniso_log_scales
Get the aniso_log_scales from a spatial term, if present.
get_spatial_feature_dim
Get the number of feature columns (spatial dimensionality) for a spatial term.
get_spatial_length_scale
is_nullspace_degeneracy_prior
True iff prior is the well-determined double-penalty null-space degeneracy prior placed on a DoublePenaltyNullspace selection coordinate.
joint_unpenalized_dim
Numeric core of SmoothTerm::wald_unpenalized_dim: the dimension of the joint null space ∩_k null(S_k) = null(Σ_k S_k) of a term’s local penalty blocks, with a conservative fallback when a penalty is not materialized as a full p_local × p_local matrix (e.g. a Kronecker tensor factor).
log_spatial_aniso_scales
Log the learned per-axis spatial anisotropy for all spatial terms that have aniso_log_scales set after optimization.
matern_operator_penalty_triplet_at_length_scale
Build the canonical Matérn operator-penalty triplet (mass / tension / stiffness) at an explicit effective length scale — i.e. the σ_geom-compensated, standardized-frame scale the design’s kernel was built against (NOT the original-coordinate length_scale stored in metadata).
matern_operator_penalty_triplet_from_metadata
measure_jet_enrolls_psi
Single source for measure-jet outer-ψ enrollment: the lnτ dial is undefined in the τ = 0 pseudo-inverse oracle mode (see build_measure_jet_basis_psi_derivatives), so only a positive ridge enrolls the dial group. spatial_term_supports_hyper_optimization and spatial_term_uses_per_axis_psi both defer here so the θ-layout sources cannot disagree.
measure_jet_learns_length_scale
Whether the design-moving ℓ dial is enrolled for this term. ℓ is fixed by default and learnable in every mode only when learn_length_scale = true.
measure_jet_penalty_psi_dim
Number of multiscale PENALTY dials (excluding the design-moving ℓ): multiscale (per-scale spectral) mode carries (α, lnτ) = 2 — the order is either the pinned explicit s or absorbed by the REML-learned per-scale amplitudes, so it is NOT a dial; single-scale (the default) carries none. MUST agree with the penalty-coordinate layout of build_measure_jet_basis_psi_derivatives (its per_level branch always emits exactly the (α, lnτ) coordinate pair).
measure_jet_psi_bound_values
One end of the per-coordinate dial boxes, in producer coordinate order (ℓ first when enrolled, then the multiscale penalty dials).
measure_jet_psi_dim
ψ dimension of a measure-jet term. The design-moving ℓ dial (when enrolled) is coordinate 0; the multiscale penalty dials follow. MUST agree with the coordinate layout of build_measure_jet_basis_psi_derivatives (ℓ first).
measure_jet_psi_seed
Seed ψ from the term’s realized dials, in producer coordinate order: ℓ first (when enrolled), then the multiscale penalty dials. The ℓ seed is the realized representer range ln(length_scale) (the resolved spec carries the concrete auto value after the design build/freeze).
measure_jet_term_spec
The measure-jet term’s spec, when term_idx is a measure-jet smooth. Single accessor for every dial-plumbing dispatch below.
nonfinite_value_label
normalize_penalty_in_constrained_space
parse_f64_2d_npy_header
parse_shape_constraint
Parse a shape-constraint string into a ShapeConstraint.
pca_center_mean
plan_joint_spatial_centers_for_term_blocks
projector_from_columns
remap_smooth_basis_feature_columns
Walk a SmoothBasisSpec tree, re-resolving every column index through remap. Shared by all predict-time column realignment (see TermCollectionSpec::remap_feature_columns); kept exhaustive so a newly added index-bearing variant fails to compile until it is handled here.
resolve_factor_smooth_levels
Resolve the grouping levels for a factor smooth: replay the frozen level list when present (predict path), otherwise discover the sorted unique bit patterns of the factor column (fit path).
response_aware_axis_contrasts
Per-axis response-structure score for anisotropy seeding.
rewrite_thin_plate_knots_error
select_columns
set_constant_curvature_kappa
Write the optimized κ back into a constant-curvature term spec. Returns true when κ moved. Centers, ℓ, and the constraint transform z are κ-FIXED by the basis κ-contract, so only kappa changes.
set_measure_jet_psi_dials
Collection-level measure-jet dial write-back (the apply_tospec / realizer-side entry). Returns whether anything moved.
set_single_term_constant_curvature_kappa
Single-term κ write-back: the shared validate+apply core, also used directly on the cached per-trial build spec in the incremental realizer (whose caller has already change-checked at the collection level and rebuilds regardless of the moved flag). Mirrors set_single_term_measure_jet_psi_dials.
set_single_term_measure_jet_psi_dials
Single-term dial write-back: the shared match+apply core, also used directly on the cached per-trial build spec (whose caller has already change-checked at the collection level and rebuilds regardless of the moved flag).
set_spatial_aniso_log_scales
Set aniso_log_scales on a spatial term’s basis spec.
set_spatial_length_scale
set_spatial_term_centers
sparse_compatible_block_nnz
spatial_identifiability_policy
spatial_term_center_strategy
spatial_term_group_key
spatial_term_has_locked_kappa
Returns true when a spatial term has NO outer optimization axes — i.e. the user provided an explicit length_scale and the term does not enroll REML-side per-axis ψ contrasts, so both the scalar κ and any fixed geometry anisotropy are anchored.
spatial_term_min_center_count
spatial_term_psi_bounds
Returns ψ-space bounds (ψ_lo = ln(κ_lo), ψ_hi = ln(κ_hi)).
spatial_term_psi_seed
Data-derived ψ seed for a spatial term when the user has not set an explicit length_scale on its basis spec. Uses the geometric mean of the data-informed kappa range (i.e., the midpoint of the ψ window).
spatial_term_psi_to_length_scale_and_aniso
spatial_term_supports_hyper_optimization
spatial_term_uses_per_axis_psi
Whether a spatial term contributes per-axis ψ entries to the outer joint hyperparameter vector.
standardized_spatial_term_data
sync_aniso_contrasts_from_metadata
Sync knot-cloud-derived anisotropy contrasts from basis metadata back into the mutable spec so the optimizer starts from the correct eta values.
tensor_margin_range_null_projectors
tensor_product_design_from_marginals
tensor_product_design_from_sparse_marginals
term_collection_has_one_sided_anchored_bspline
try_build_sparse_design_from_blocks
validate_measure_jet_positive_vec_len
validate_smooth_basis_frozen
validate_smooth_terms_finite_inputs
validate_term_collection_finite_inputs
validate_term_feature_column_finite
weighted_blockwise_penalty_sum
Compute Σ_k λ_k S_k directly from blockwise penalties, accumulating into a pre-allocated p_total × p_total output without ever materializing individual global matrices.