Hurst Fractional Gaussian Noise Basis: PyTorch Architecture

Navigation:

Overview & Formula Tokens

The Hurst memory basis is exposed via hurst():

# Fractional Gaussian noise Hurst memory basis
formula = "Y ~ hurst(Load_d1, k=12, H=0.75)"

Parameter Specification

HurstEffect (hurst())

Parameter

Type

Default

Description

k

int

16

Number of columns (\(k/2\) sine and \(k/2\) cosine harmonics); harmonic \(j\) is penalized by \(j^{2H-1}\), the inverse spectrum of fractional Gaussian noise.

H

float

0.75

Hurst exponent \(H \in (0, 1)\).

period

float

None

Optional fixed cycle period.

Complexity & Performance

  • Pointwise in the value: \(\mathcal{O}(B\,T\,k)\) time and memory; the training span is frozen at initialization.

State, Complexity and Limits

  • Class and file: HurstEffect, src/tam/model/spectrum/_hurst.py; formula token hurst(). Label: (BETA).

  • State: none. Layout: (B, T) or (T,); one column.

  • Extrapolation: all modes of the router are available.

  • Limits: the penalty is a prior, not an estimate of the memory of the series; \(H\) is clipped to \([0.05, 0.95]\).

Code

Feature map of HurstEffect (build_feature_map):

    def build_feature_map(self, x_col: torch.Tensor, state_in: Optional[Dict[str, Any]] = None) -> torch.Tensor:
        r"""Constructs harmonic Fourier basis functions of each value: ``(B, T)`` in, ``(B, T, k)`` out (pointwise, no state)."""
        x3, shape, layout = to_btd(x_col, False)
        x = x3[..., 0].reshape(-1)
        device = x_col.device
        dtype = x_col.dtype

        # Period from the frozen training span if not explicitly fixed
        if self.period is not None:
            P = self.period
        elif self._fitted_period is not None:
            P = self._fitted_period
        else:
            self.initialize(x_col)
            P = self._fitted_period if self._fitted_period is not None else 1.0

        freqs = torch.arange(1, self.m + 1, device=device, dtype=dtype)  # (m,)
        phases = (2.0 * np.pi / P) * torch.outer(x, freqs)  # (N, m)

        phi = torch.cat([torch.sin(phases), torch.cos(phases)], dim=-1)  # (N, 2m)
        return from_btk(phi.reshape(x3.shape[0], x3.shape[1], self.k), shape, layout)

Penalty of HurstEffect (build_penalty_matrix):

    def build_penalty_matrix(self) -> torch.Tensor:
        r"""Constructs inverse fGn spectral precision penalty:

        .. math::

            P = \lambda_p\, I_2 \otimes \operatorname{diag}\big( j^{2H - 1} \big)_{j=1}^m
        """
        j_vec = torch.arange(1, self.m + 1, device=TORCH_DEVICE, dtype=torch.get_default_dtype())
        # Power law weight j^(2H - 1)
        power_weights = j_vec ** (2.0 * self.H - 1.0)
        # Duplicate for sin and cos
        diag_weights = torch.cat([power_weights, power_weights])
        return torch.diag(diag_weights) * self.lambda_p

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

        elif ttype == 'hurst':
            k = int(params_resolved.get('k', 16))
            H = float(params_resolved.get('H', params_resolved.get('h', 0.75)))
            period = params_resolved.get('period', None)
            period_val = float(period) if period is not None else None
            extrap_val = params_resolved.get('extrapolate', 'continue')
            effects_list.append(HurstEffect(
                feature_name=feature_name,
                k=k,
                H=H,
                period=period_val,
                lambda_p=lambda_p,
                extrapolate=extrap_val,
            ))