Caputo Fractional Physics Penalties: PyTorch Architecture

Navigation:

Overview & Formula Tokens

Fractional derivative orders extend the phys() penalty (integer orders are unchanged):

# Fractional Caputo derivative physics operator
formula = "Y ~ phys(x, basis='fourier', n_coeffs=16, D0_5=1.0)"

Parameter Specification

phys(x, basis=..., D0_5=1.0, ...) keeps the parameters of phys(); non-integer derivative orders select the Caputo operator.

Complexity & Performance

  • Same cost as the integer-order penalty of phys(); the Grünwald–Letnikov weights are built once per penalty matrix.

State, Complexity and Limits

  • Class and file: the fractional orders are in UniversalPhysicsEffect (src/tam/model/spectrum/_physics.py); formula token phys() with a non-integer order. Label: (BETA).

  • State: none. Integer orders: unchanged, bit for bit.

  • Spelling in a formula: phys(t, basis='fourier', n_coeffs=16, D0_5=1.0) sets the order 0.5; D0.5=1.0 is refused by the generic term parser (a dot is not allowed in an argument name). show_syntax() gives the example.

Code

Parsing of the phys(...) token in the factory:

        elif ttype == 'phys':
            basis = params_resolved.get('basis', 'spline')
            n_coeffs = int(params_resolved.get('k', 20) if basis != 'fourier' else params_resolved.get('n_coeffs', 20))
            
            # An order is `D<integer>` or `D<integer>_<digits>` (the underscore is the decimal point: `D0_5` is the order 0.5)
            diff_weights = {}
            derivative_keys = set()
            for pk, pv in params_resolved.items():
                if re.fullmatch(r'D\d+(_\d+)?', pk):
                    diff_weights[pk.replace('_', '.')] = float(pv)
                    derivative_keys.add(pk)
            if not diff_weights: diff_weights = {'D2': 1.0}
                
            reserved_keys = ['k', 'n_coeffs', 'ap', 'basis', 'extrapolate']
            basis_kwargs = {k: v for k, v in params_resolved.items() if k not in reserved_keys and k not in derivative_keys}
            extrap_val = params_resolved.get('extrapolate', 'continue')
            effects_list.append(UniversalPhysicsEffect(
                feature_name, basis, n_coeffs, diff_weights, lambda_p, extrap_val, **basis_kwargs
            ))