Formula reference: regularized profiles
Generated from the docstrings of vaft.formula.regularized_profiles:
3 public functions. Each entry is what
vaft.formula.describe("regularized_profiles.<name>") prints.
All formula categories
Overview
The coordinate is psi_N = rho_pol**2, never rho_tor. Finite dF/dpsi_N
therefore implies dP/drho_pol(0)=0, without constraining dF/dpsi_N(0).
The legacy utils.fit_profile interface and all its modes are unchanged.
Functions
evaluate_regularized_profile | Evaluate a positive regular flux profile or its flux derivative. |
fit_regularized_profile | Fit independent samples with Huber residuals and quadratic curvature. |
profile_basis | Evaluate the positive profile basis or its flux-coordinate derivatives. |
No function matches.
evaluate_regularized_profile
source
evaluate_regularized_profile(psi_n, parameters, config, *, derivative=0, allow_extrapolation=False)
Show source vaft/formula/regularized_profiles.py, lines 119–164
def evaluate_regularized_profile(psi_n, parameters, config, *, derivative=0,
allow_extrapolation=False):
r"""Evaluate a positive regular flux profile or its flux derivative.
$$F(x)=s\sum_j B_j(x/d)\,[f+\log(1+\exp(\theta_j))]$$
Parameter order and basis [1]_ are shared with the offline fit. Finite
F' implies dF(rho_pol squared)/drho_pol=0 on axis without fixing F'(0).
Parameters
----------
psi_n : array_like
Finite normalized poloidal flux coordinates [-].
parameters : array_like
Finite unconstrained softplus parameters in basis order [-].
config : RegularizedProfileConfig
Basis, floor and domain declaration, with physical scale s [-].
derivative : int, optional
Flux derivative order, zero, one or two [-].
allow_extrapolation : bool, optional
Enable diagnostic evaluations outside the positivity domain [-].
Returns
-------
values : ndarray
Profile or derivative in the physical unit y of config.scale [y].
Limitations
-----------
Outside the declared domain the default is NaN. Explicit extrapolation
carries no positivity guarantee. Numerical overflow is not clipped.
References
----------
.. [1] C. de Boor, A Practical Guide to Splines, revised edition (2001),
Chapters IX-X, B-spline representation and differentiation.
"""
x = np.asarray(psi_n, float)
theta = np.asarray(parameters, float)
if theta.shape != (config.coefficient_count,) or not np.isfinite(theta).all():
raise ValueError("finite parameter vector of the declared size required")
out = config.scale * (profile_basis(x, config, derivative) @
(config.floor + np.logaddexp(0., theta)))
if not allow_extrapolation:
out = np.where((x >= 0) & (x <= config.domain_max), out, np.nan)
return outEvaluate a positive regular flux profile or its flux derivative.
\[F(x)=s\sum_j B_j(x/d)\,[f+\log(1+\exp(\theta_j))]\]Parameter order and basis [1] are shared with the offline fit. Finite F’ implies dF(rho_pol squared)/drho_pol=0 on axis without fixing F’(0).
| Name | Type | Unit | Description |
|---|---|---|---|
psi_n | array_like | - | Finite normalized poloidal flux coordinates. |
parameters | array_like | - | Finite unconstrained softplus parameters in basis order. |
config | RegularizedProfileConfig | - | Basis, floor and domain declaration, with physical scale s. |
derivative | int, optional | - | Flux derivative order, zero, one or two. |
allow_extrapolation | bool, optional | - | Enable diagnostic evaluations outside the positivity domain. |
| Returns | |||
values | ndarray | y | Profile or derivative in the physical unit y of config.scale. |
Limitations · References
Limitations
Outside the declared domain the default is NaN. Explicit extrapolation carries no positivity guarantee. Numerical overflow is not clipped.
References
- C. de Boor, A Practical Guide to Splines, revised edition (2001), Chapters IX-X, B-spline representation and differentiation.
fit_regularized_profile
source
fit_regularized_profile(psi_n, values, *, config=None)
Fit independent samples with Huber residuals and quadratic curvature.
\[J=\frac{1}{N}\sum_i H_\delta((F(x_i)-y_i)/s) +\frac{\lambda}{2}\int_0^1 [d^2(F/s)/du^2]^2\,du\]The Huber term [1] is quadratic within delta and linear outside it; the curvature term remains separately quadratic in u=psi_N/domain_max. Reuses VAFT’s legacy free-polynomial fit for initialization and SciPy’s least-squares kernel. No boundary anchor or post-fit clipping is applied.
| Name | Type | Unit | Description |
|---|---|---|---|
psi_n | array_like | - | One-dimensional finite samples within the declared flux domain. |
values | array_like | y | Independent quantity samples in the physical unit of config.scale. |
config | RegularizedProfileConfig or None, optional | - | Serialized numerical objective, basis and convergence assumptions. |
| Returns | |||
fit | RegularizedProfileFit | - | Parameters, status and diagnostics; completion is not accuracy proof. |
Limitations · References
Limitations
Sigma weighting is not implemented. Scale and robust weights are numerical assumptions, never diagnostic sigma. Invalid inputs are rejected, not dropped. Callers own independent masks, branch grouping and support.
References
- P. J. Huber, Robust Estimation of a Location Parameter, Annals of Mathematical Statistics 35 (1964), 73-101.
profile_basis
source
profile_basis(psi_n, config, derivative=0)
Show source vaft/formula/regularized_profiles.py, lines 69–116
def profile_basis(psi_n, config, derivative=0):
r"""Evaluate the positive profile basis or its flux-coordinate derivatives.
$$B_j(u)={n\choose j}u^j(1-u)^{n-j},\qquad u=\psi_N/d$$
The spline alternative uses six clamped cubic B-splines [1]_. Ordering is
ascending Bernstein index or spline index; derivatives are in psi_N.
Parameters
----------
psi_n : array_like
Finite normalized poloidal flux coordinates [-].
config : RegularizedProfileConfig
Basis, domain and knot declaration; scale is unused here [-].
derivative : int, optional
Derivative order, zero, one or two [-].
Returns
-------
basis : ndarray
Coordinates by ordered basis coefficients, with flux derivatives [-].
Limitations
-----------
Extrapolated basis values are mathematical evaluations only. Positive
partition-of-unity controls guarantee positivity only on the declared domain.
References
----------
.. [1] C. de Boor, A Practical Guide to Splines, revised edition (2001),
Chapters IX-X, B-spline representation and differentiation.
"""
x = np.asarray(psi_n, dtype=float)
if not np.isfinite(x).all() or derivative not in (0, 1, 2):
raise ValueError("finite coordinates and derivative 0, 1 or 2 required")
u = x / config.domain_max
if config.basis == "bspline6":
knots = [0.] * 4 + list(config.knot_fractions) + [1.] * 4
b = BSpline(knots, np.eye(6), 3, extrapolate=True)
return b(u, nu=derivative) / config.domain_max**derivative
n = config.coefficient_count - 1
# Polynomial coefficients give exact derivatives including both endpoints.
from numpy.polynomial import Polynomial
cols = []
for j in range(n + 1):
p = comb(n, j) * Polynomial([0., 1.])**j * Polynomial([1., -1.])**(n-j)
cols.append(p.deriv(derivative)(u) / config.domain_max**derivative)
return np.stack(cols, axis=-1)Evaluate the positive profile basis or its flux-coordinate derivatives.
\[B_j(u)={n\choose j}u^j(1-u)^{n-j},\qquad u=\psi_N/d\]The spline alternative uses six clamped cubic B-splines [1]. Ordering is ascending Bernstein index or spline index; derivatives are in psi_N.
| Name | Type | Unit | Description |
|---|---|---|---|
psi_n | array_like | - | Finite normalized poloidal flux coordinates. |
config | RegularizedProfileConfig | - | Basis, domain and knot declaration; scale is unused here. |
derivative | int, optional | - | Derivative order, zero, one or two. |
| Returns | |||
basis | ndarray | - | Coordinates by ordered basis coefficients, with flux derivatives. |
Limitations · References
Limitations
Extrapolated basis values are mathematical evaluations only. Positive partition-of-unity controls guarantee positivity only on the declared domain.
References
- C. de Boor, A Practical Guide to Splines, revised edition (2001), Chapters IX-X, B-spline representation and differentiation.