use gam_terms::basis::{
BasisError, BasisMetadata, BasisPsiDerivativeResult, BasisPsiSecondDerivativeResult,
BasisWorkspace, CenterStrategy, MaternIdentifiability, PenaltySource,
build_constant_curvature_basis_kappa_derivatives,
build_matern_basis_log_kappa_aniso_derivatives, build_matern_basis_log_kappa_derivatives,
build_matern_collocation_operator_matrices, build_measure_jet_basis_psi_derivatives,
build_thin_plate_basis_log_kappa_derivatives, estimate_penalty_nullity,
initial_aniso_contrasts,
};
use gam_custom_family::{
BlockEffectiveJacobian, BlockGeometryDirectionalDerivative, BlockWorkingSet,
BlockwiseFitOptions, CustomFamily, CustomFamilyBlockPsiDerivative, CustomFamilyOwnedMode,
CustomFamilyWarmStart, ExactNewtonOuterObjective, FamilyEvaluation, FamilyLinearizationState,
ParameterBlockSpec, ParameterBlockState, PenaltyMatrix,
evaluate_custom_family_joint_hyper_efs_owned, evaluate_custom_family_joint_hyper_owned,
fit_custom_family, fit_custom_family_fixed_log_lambdas_from_owned_mode,
};
use gam_solve::estimate::{
EstimationError, ExternalOptimOptions, FitInference, FitOptions, FittedLinkState, PenaltySpec,
UnifiedFitResult, UnifiedFitResultParts, fit_gamwith_heuristic_lambdas,
};
use gam_solve::estimate::reml::DirectionalHyperParam;
pub use gam_terms::smooth::freeze_term_collection_from_design;
use gam_solve::mixture_link::{
inverse_link_jet_for_inverse_link, logit_inverse_link_jet5, state_from_beta_logisticspec,
state_from_sasspec, state_fromspec,
};
use gam_math::quantile::quantile_from_sorted;
use gam_linalg::faer_ndarray::{fast_ab, fast_atb, fast_atv};
use gam_linalg::matrix::{DesignBlock, DesignMatrix, RandomEffectOperator, SymmetricMatrix};
use gam_problem::{ConstraintSet, ExactNewtonJointPsiTerms, LinearInequalityConstraints};
use gam_spec::{
InverseLink, LatentCLogLogState, LikelihoodSpec, MixtureLinkState, ResponseFamily,
SasLinkState, StandardLink,
};
use gam_terms::smooth::penalty_priors::{
realize_keyed_penalty_block_gamma_priors, realize_penalty_block_gamma_priors,
};
use gam_terms::smooth::shape_constraints::{
linear_constraints_from_lower_bounds_global, merge_linear_constraints_global,
shape_lower_bounds_local,
};
use gam_terms::smooth::*;
use ndarray::{Array1, Array2, ArrayView1, ArrayView2, Axis, s};
use std::collections::BTreeSet;
use std::ops::Range;
use std::sync::atomic::AtomicUsize;
use std::sync::{Arc, Mutex};
#[derive(Clone)]
pub struct FittedTermCollection {
pub fit: UnifiedFitResult,
pub design: TermCollectionDesign,
pub adaptive_diagnostics: Option<AdaptiveRegularizationDiagnostics>,
}
#[derive(Clone, Copy, Debug, Default)]
pub struct SpatialLengthScaleOptimizationTiming {
pub log_kappa_dim: usize,
pub cost_calls: usize,
pub cost_total_s: f64,
pub eval_calls: usize,
pub eval_total_s: f64,
pub efs_calls: usize,
pub efs_total_s: f64,
pub slow_path_resets: u64,
pub design_revision_delta: u64,
pub nfree_skip_row_touches: u64,
pub nfree_miss_shape: u64,
pub nfree_miss_value: u64,
pub nfree_miss_gradient: u64,
pub nfree_miss_penalty: u64,
pub nfree_miss_revision: u64,
pub nfree_miss_second_order: u64,
pub nfree_miss_other: u64,
pub optim_total_s: f64,
}
impl SpatialLengthScaleOptimizationTiming {
pub fn trial_total_s(self) -> f64 {
self.cost_total_s + self.eval_total_s + self.efs_total_s
}
}
#[derive(Clone)]
pub struct FittedTermCollectionWithSpec {
pub fit: UnifiedFitResult,
pub design: TermCollectionDesign,
pub resolvedspec: TermCollectionSpec,
pub adaptive_diagnostics: Option<AdaptiveRegularizationDiagnostics>,
pub kappa_timing: Option<SpatialLengthScaleOptimizationTiming>,
}
include!("design_construction.rs");
include!("spatial_optimization.rs");
#[cfg(test)]
mod test_support {
use super::*;
pub(super) trait SingleBlockExactJointDesignCacheTestExt<'d>: Sized {
fn new(
data: ArrayView2<'d, f64>,
spec: TermCollectionSpec,
design: TermCollectionDesign,
spatial_terms: Vec<usize>,
rho_dim: usize,
dims_per_term: Vec<usize>,
) -> Result<Self, String>;
}
impl<'d> SingleBlockExactJointDesignCacheTestExt<'d> for SingleBlockExactJointDesignCache<'d> {
fn new(
data: ArrayView2<'d, f64>,
spec: TermCollectionSpec,
design: TermCollectionDesign,
spatial_terms: Vec<usize>,
rho_dim: usize,
dims_per_term: Vec<usize>,
) -> Result<Self, String> {
let policy = gam_runtime::resource::ResourcePolicy::default_library();
Self::new_with_policy(
data,
spec,
design,
spatial_terms,
rho_dim,
dims_per_term,
&policy,
)
}
}
}
include!("iso_kappa_reml_gradient_fd_tests.rs");
include!("spatial_length_scale_monotone_tests.rs");
include!("psi_gram_tensor_fast_path_tests.rs");
include!("spatial_adaptive_hyper_fd_tests.rs");
include!("matern_nfree_rekey_topology_tests.rs");
include!("design_assembly_constraint_tests.rs");
include!("adaptive_bounded_duchon_tests.rs");
include!("zz_measure_2425_kappa_tests.rs");
include!("zz_measure_2450_rho_prior_criterion_tests.rs");