kinextract.fit_joint
- kinextract.fit_joint(st: FitState, n_interior_knots: int = 10, degree: int = 3, xlam_cont: float = 3.0, cont_diff_order: int = 2, maxiter: int = 50000, ftol: float = 1e-12, maxfun: int = 500000, use_jax: bool = True, auto_recenter_v: bool = False, fit_continuum: bool = True, w_bounds: tuple = (1e-05, 1.0))[source]
Run the joint LOSVD + template + continuum-P-spline MAP fit.
- Parameters:
st (FitState) – Fit state to optimize (not modified unless auto_recenter_v).
n_interior_knots (optional) – Passed to
build_pspline_design(). Defaults (10 interior knots, cubic -> 14 coefficients) give enough local flexibility to track realistic continuum structure without approaching the LOSVD’s own 29 degrees of freedom.degree (optional) – Passed to
build_pspline_design(). Defaults (10 interior knots, cubic -> 14 coefficients) give enough local flexibility to track realistic continuum structure without approaching the LOSVD’s own 29 degrees of freedom.xlam_cont (float, optional) – P-spline roughness penalty weight, applied to the continuum coefficients normalized by their own initial-guess scale (see
objective_joint()) – portable across datasets with very different absolute flux units.cont_diff_order (int, optional) – Order of the discrete difference penalty on the continuum coefficients (see
difference_penalty_matrix()). Default 2 (penalizes curvature, i.e. a straight-line continuum is free), matching the standard P-spline convention.maxiter (optional) – Passed through to
scipy.optimize.minimize(method="L-BFGS-B").ftol (optional) – Passed through to
scipy.optimize.minimize(method="L-BFGS-B").maxfun (optional) – Passed through to
scipy.optimize.minimize(method="L-BFGS-B").use_jax (bool, optional) – If True (default), use exact analytic gradients via
build_jax_objective_value_and_grad()instead of scipy’s finite-difference approximation. Falls back to finite differences automatically if JAX isn’t installed.auto_recenter_v (bool, optional) – If True, recenter the wing-taper’s regularization on
kinextract.numerics.estimate_velocity_xcorr(st)instead of the fixedv_center=0.0the shipped MAP path always uses. This substantially reduces V-recovery bias in the regime it matters (clean/high-S/N data, xlam already tuned high). Default False here becausefit_joint_auto_xlam()always recenters itself as a prerequisite step (see its docstring) – this flag only matters for callers invokingfit_joint()directly at a single, fixed xlam.fit_continuum (bool, optional) – If False (default True), no continuum is fit at all – the continuum is fixed at 1.0 (see
build_initial_guess()’s fit_continuum parameter andevaluate_model_gp_joint()). Use this for pre-normalized input, where the data’s own continuum has already been divided out and there is nothing genuine for a free P-spline to fit.w_bounds (tuple, optional) – Per-element template-weight bounds, passed through to
build_initial_guess(). Default non-negative; widen to allow negative values (e.g.(-1.0, 1.0)) when fitting withkinextract.templates.reduce_templates_svd()eigen-templates.
- Returns:
result (scipy.optimize.OptimizeResult) –
result.xis in physical (unscaled) units.design (ndarray) – Continuum B-spline design matrix used for this fit.