Skip to content

PredictionWrapper

Wraps KFLSTMModel for both the dynamic evaluation loop and the fixed-length ONNX-compatible circuit forwards. Source: src/PredictionWrapper.py.


PredictionWrapper

PredictionWrapper(model, SD, MD, ht_test, D)

Bases: Module

Wraps a KFLSTMModel to run the EKF prediction loop over a DVAL interval.

Provides multiple forward methods corresponding to fixed-length unrolled EKF passes (forward1, forward2, forward4, ...) and a dynamic loop variant (forward_Dloop). The fixed-length variants are compiled into ONNX and used as the prediction zkSNARK circuit. All fixed-length forwards append one column of ezkl nonce values to each output tensor to maintain consistent ONNX shapes across different DVAL configurations.

Parameters:

Name Type Description Default
model KFLSTMModel

The underlying EKF-LSTM model.

required
SD int

State space dimension.

required
MD int

Measurement space dimension.

required
ht_test Tensor

Full test dataset tensor; rows are indexed by time step.

required
D int

DVAL interval length (number of EKF steps per proof interval).

required
Source code in src/PredictionWrapper.py
def __init__(self, model,  SD, MD, ht_test,D):
    super(PredictionWrapper, self).__init__()
    self.model = model
    self.period_start = 0
    self.SD = SD
    self.MD = MD
    self.ht_test = ht_test
    self.jac_fh = []
    self.jac_Ch = []
    self.D = D

forward1

forward1(h, P, delta_y, CPCT_cov, y, jac_fh, jac_Ch, Kt, KCR_status, nonce_h, nonce_P, nonce_dy, nonce_CPCT_cov, nonce_KCR_status, nonce_kalman_diff, nonce_kalman_threshold)

ONNX-compatible forward pass for exactly 1 EKF timestep. Compiled into the prediction zkSNARK circuit when DVAL=1.

Accepts padded inputs (extra trailing columns) to match the fixed ONNX tensor shapes used by ezkl, strips the padding before computation, runs one EKF step via model.forward(), then appends nonce columns to each output for ezkl's Poseidon hash commitment scheme.

Parameters:

Name Type Description Default
h Tensor

Padded initial hidden state (1, 1, SD+1).

required
P Tensor

Padded initial covariance (1, SD, SD+1).

required
delta_y Tensor

Padded initial residual accumulator (1, 1, MD+1).

required
CPCT_cov Tensor

Padded initial innovation covariance (1, MD, MD+1).

required
y Tensor

Observation for 1 timestep (1, 1, MD+1).

required
jac_fh Tensor

State transition Jacobian (1, SD, SD+1).

required
jac_Ch Tensor

Observation Jacobian (1, MD, MD+1).

required
Kt Tensor

Transposed Kalman gain (1, MD, SD+1).

required
KCR_status Tensor

Kalman check status carry-in (1, 1, 2).

required
nonce_h Tensor

Nonce column for h output (1, 1, 1).

required
nonce_P Tensor

Nonce column for P output (1, SD, 1).

required
nonce_dy Tensor

Nonce column for delta_y output (1, 1, 1).

required
nonce_CPCT_cov Tensor

Nonce column for CPCT_cov output (1, MD, 1).

required
nonce_KCR_status Tensor

Nonce column for KCR_status output (1, 1, 1).

required
nonce_kalman_diff Tensor

Nonce row for kalman_diff output (1, 1, SD).

required
nonce_kalman_threshold Tensor

Nonce row for kalman_threshold output (1, 1, SD).

required

Returns:

Type Description

Tuple[torch.Tensor, ...]: - h_current: Updated hidden state with nonce appended (1, 1, SD+1). - P_current: Updated covariance with nonce appended (1, SD, SD+1). - delta_y_current: Accumulated residual with nonce appended (1, 1, MD+1). - CPCT_cov_current: Accumulated innovation covariance with nonce appended (1, MD, MD+1). - KCR_status: Kalman check status with nonce appended (1, 1, 2). - kalman_diff: Kalman gain check diff with nonce row appended (1, 2, SD). - kalman_threshold: Kalman gain check threshold with nonce row appended (1, 2, SD).

Source code in src/PredictionWrapper.py
def forward1(self,h,P,delta_y,CPCT_cov,y,jac_fh,jac_Ch,Kt,KCR_status,
             nonce_h,nonce_P,nonce_dy,nonce_CPCT_cov,nonce_KCR_status,nonce_kalman_diff,nonce_kalman_threshold,): #nonce_P,nonce_delta_y,nonce_CPCT_cov,nonce_y,
    """
    ONNX-compatible forward pass for exactly 1 EKF timestep. Compiled into the
    prediction zkSNARK circuit when DVAL=1.

    Accepts padded inputs (extra trailing columns) to match the fixed ONNX tensor
    shapes used by ezkl, strips the padding before computation, runs one EKF step
    via model.forward(), then appends nonce columns to each output for ezkl's
    Poseidon hash commitment scheme.

    Args:
        h (torch.Tensor): Padded initial hidden state (1, 1, SD+1).
        P (torch.Tensor): Padded initial covariance (1, SD, SD+1).
        delta_y (torch.Tensor): Padded initial residual accumulator (1, 1, MD+1).
        CPCT_cov (torch.Tensor): Padded initial innovation covariance (1, MD, MD+1).
        y (torch.Tensor): Observation for 1 timestep (1, 1, MD+1).
        jac_fh (torch.Tensor): State transition Jacobian (1, SD, SD+1).
        jac_Ch (torch.Tensor): Observation Jacobian (1, MD, MD+1).
        Kt (torch.Tensor): Transposed Kalman gain (1, MD, SD+1).
        KCR_status (torch.Tensor): Kalman check status carry-in (1, 1, 2).
        nonce_h (torch.Tensor): Nonce column for h output (1, 1, 1).
        nonce_P (torch.Tensor): Nonce column for P output (1, SD, 1).
        nonce_dy (torch.Tensor): Nonce column for delta_y output (1, 1, 1).
        nonce_CPCT_cov (torch.Tensor): Nonce column for CPCT_cov output (1, MD, 1).
        nonce_KCR_status (torch.Tensor): Nonce column for KCR_status output (1, 1, 1).
        nonce_kalman_diff (torch.Tensor): Nonce row for kalman_diff output (1, 1, SD).
        nonce_kalman_threshold (torch.Tensor): Nonce row for kalman_threshold output (1, 1, SD).

    Returns:
        Tuple[torch.Tensor, ...]:
            - h_current: Updated hidden state with nonce appended (1, 1, SD+1).
            - P_current: Updated covariance with nonce appended (1, SD, SD+1).
            - delta_y_current: Accumulated residual with nonce appended (1, 1, MD+1).
            - CPCT_cov_current: Accumulated innovation covariance with nonce appended (1, MD, MD+1).
            - KCR_status: Kalman check status with nonce appended (1, 1, 2).
            - kalman_diff: Kalman gain check diff with nonce row appended (1, 2, SD).
            - kalman_threshold: Kalman gain check threshold with nonce row appended (1, 2, SD).
    """
    h_current = h[0:1, :, :self.SD].reshape(1, 1, self.SD)
    P_current = P[0:1, :, :self.SD].reshape(1, self.SD, self.SD)

    delta_y_current = delta_y.reshape(1, 1, self.MD + 1)
    CPCT_cov_current = CPCT_cov.reshape(1, self.MD, self.MD + 1)

    delta_y_current = delta_y_current[0:1, :, :self.MD].reshape(1, 1, self.MD)
    CPCT_cov_current = CPCT_cov_current[0:1, :, :self.MD].reshape(1, self.MD, self.MD)
    y = y[:, :, :self.MD]
    jac_fh = jac_fh[:, :, :self.SD]
    jac_Ch = jac_Ch[:, :, :self.MD]
    Kt = Kt[:, :, :self.SD]
    KCR_status = KCR_status[:, :, 0:1].reshape(1, 1, 1)

    nonce_h = nonce_h.reshape((1, 1, 1))
    nonce_dy = nonce_dy.reshape((1, 1, 1))
    nonce_KCR_status = nonce_KCR_status.reshape((1, 1, 1))
    nonce_P = nonce_P.reshape((1, self.SD, 1))
    nonce_CPCT_cov = nonce_CPCT_cov.reshape((1, self.MD, 1))
    nonce_kalman_diff = nonce_kalman_diff.reshape((1, 1, self.SD))
    nonce_kalman_threshold = nonce_kalman_threshold.reshape((1, 1, self.SD))

    assert h_current.shape[2] == self.SD
    assert nonce_h.shape == (1, 1, 1)
    assert nonce_KCR_status.shape == (1, 1, 1)
    assert nonce_dy.shape == (1, 1, 1)
    assert nonce_P.shape == (1, self.SD, 1)
    assert nonce_CPCT_cov.shape == (1, self.MD, 1)
    assert nonce_kalman_diff.shape == (1, 1, self.SD)
    assert nonce_kalman_threshold.shape == (1, 1, self.SD)


    outputs = self.model.forward(h_current,
                                 y[0:1,:,:],
                                 jac_fh[0:1,:,:].reshape(1,self.SD,self.SD),
                                 jac_Ch[0:1,:,:].reshape(1,self.MD,self.SD),
                                 P_current,
                                 Kt[0:1,:,:].reshape(1,self.MD,self.SD))

    h_current = outputs[0].reshape(1,1,self.SD)
    delta_y_current = delta_y_current + outputs[2]
    CPCT_cov_current = CPCT_cov_current + outputs[5]
    P_current = outputs[6].reshape(1,self.SD,self.SD)
    KCR_status = KCR_status*outputs[7]
    kalman_diff = outputs[8]
    kalman_threshold = outputs[9]

    h_current = torch.cat([h_current,nonce_h],dim=2)
    P_current = torch.cat([P_current,nonce_P],dim=2)
    delta_y_current = torch.cat([delta_y_current,nonce_dy],dim=2)
    CPCT_cov_current = torch.cat([CPCT_cov_current, nonce_CPCT_cov],dim=2)
    KCR_status = torch.cat([KCR_status, nonce_KCR_status], dim=2)
    kalman_diff = torch.cat([kalman_diff, nonce_kalman_diff], dim=1)
    kalman_threshold = torch.cat([kalman_threshold, nonce_kalman_threshold], dim=1)

    return h_current, P_current, delta_y_current, CPCT_cov_current, KCR_status, kalman_diff, kalman_threshold

forward16

forward16(h, P, delta_y, CPCT_cov, y, jac_fh, jac_Ch, Kt, KCR_status, nonce_h, nonce_P, nonce_dy, nonce_CPCT_cov, nonce_KCR_status, nonce_kalman_diff, nonce_kalman_threshold)

Forward pass with exactly 16 timesteps

Parameters:

Name Type Description Default
h

Initial hidden state [1, 1, SD]

required
P

Initial covariance matrix [1, SD, SD]

required
delta_y

Initial residual [1, 1, is_r]

required
CPCT_cov

Initial residual covariance [1, is_r, is_r]

required
y

Observations for 16 timesteps [16, obs_dim]

required
jac_fh

Jacobian fh for 16 timesteps [16, ...]

required
jac_Ch

Jacobian Ch for 16 timesteps [16, ...]

required
Kt

Kalman gain for 16 timesteps [16, ...]

required
Source code in src/PredictionWrapper.py
def forward16(self, h, P, delta_y, CPCT_cov, y, jac_fh, jac_Ch, Kt, KCR_status,
             nonce_h,nonce_P,nonce_dy,nonce_CPCT_cov,nonce_KCR_status,nonce_kalman_diff,nonce_kalman_threshold,):
    """
    Forward pass with exactly 16 timesteps

    Args:
        h: Initial hidden state [1, 1, SD]
        P: Initial covariance matrix [1, SD, SD]
        delta_y: Initial residual [1, 1, is_r]
        CPCT_cov: Initial residual covariance [1, is_r, is_r]
        y: Observations for 16 timesteps [16, obs_dim]
        jac_fh: Jacobian fh for 16 timesteps [16, ...]
        jac_Ch: Jacobian Ch for 16 timesteps [16, ...]
        Kt: Kalman gain for 16 timesteps [16, ...]
    """

    h_current = h[0:1, :, :self.SD].reshape(1, 1, self.SD)
    P_current = P[0:1, :, :self.SD].reshape(1, self.SD, self.SD)

    delta_y_current = delta_y.reshape(1, 1, self.MD+1)
    CPCT_cov_current = CPCT_cov.reshape(1, self.MD, self.MD+1)

    delta_y_current = delta_y_current[0:1, :, :self.MD].reshape(1, 1, self.MD)
    CPCT_cov_current = CPCT_cov_current[0:1, :, :self.MD].reshape(1, self.MD, self.MD)
    y = y[:, :, :self.MD]
    jac_fh = jac_fh[:, :, :self.SD]
    jac_Ch = jac_Ch[:, :, :self.MD]
    Kt = Kt[:, :, :self.SD]
    KCR_status = KCR_status[:,:,0:1].reshape(1,1,1)

    nonce_h = nonce_h.reshape((1, 1, 1))
    nonce_dy = nonce_dy.reshape((1, 1, 1))
    nonce_KCR_status = nonce_KCR_status.reshape((1, 1, 1))
    nonce_P = nonce_P.reshape((1, self.SD, 1))
    nonce_CPCT_cov = nonce_CPCT_cov.reshape((1, self.MD, 1))
    nonce_kalman_diff = nonce_kalman_diff.reshape((1, 1, self.SD))
    nonce_kalman_threshold = nonce_kalman_threshold.reshape((1, 1, self.SD))

    assert h_current.shape[2] == self.SD
    assert nonce_h.shape == (1, 1, 1)
    assert nonce_KCR_status.shape == (1, 1, 1)
    assert nonce_dy.shape == (1, 1, 1)
    assert nonce_P.shape == (1, self.SD, 1)
    assert nonce_CPCT_cov.shape == (1, self.MD, 1)
    assert nonce_kalman_diff.shape == (1, 1, self.SD)
    assert nonce_kalman_threshold.shape == (1, 1, self.SD)

    # === TIMESTEP 0 ===
    outputs_0 = self.model.forward(h_current,
                                   y[0:1, :, :],
                                   jac_fh[0:1, :, :].reshape(1, self.SD, self.SD),
                                   jac_Ch[0:1, :, :].reshape(1, self.MD, self.SD),
                                   P_current,
                                   Kt[0:1, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_0[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_0[2]
    CPCT_cov_current = CPCT_cov_current + outputs_0[5]
    P_current = outputs_0[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status*outputs_0[7]
    kalman_diff = outputs_0[8]
    kalman_threshold = outputs_0[9]

    # === TIMESTEP 1 ===
    outputs_1 = self.model.forward(h_current,
                                   y[1:2, :, :],
                                   jac_fh[1:2, :, :].reshape(1, self.SD, self.SD),
                                   jac_Ch[1:2, :, :].reshape(1, self.MD, self.SD),
                                   P_current,
                                   Kt[1:2, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_1[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_1[2]
    CPCT_cov_current = CPCT_cov_current + outputs_1[5]
    P_current = outputs_1[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_1[7]
    kalman_diff = kalman_diff + outputs_1[8]
    kalman_threshold = kalman_threshold + outputs_1[9]

    # === TIMESTEP 2 ===
    outputs_2 = self.model.forward(h_current,
                                   y[2:3, :, :],
                                   jac_fh[2:3, :, :].reshape(1, self.SD, self.SD),
                                   jac_Ch[2:3, :, :].reshape(1, self.MD, self.SD),
                                   P_current,
                                   Kt[2:3, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_2[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_2[2]
    CPCT_cov_current = CPCT_cov_current + outputs_2[5]
    P_current = outputs_2[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_2[7]
    kalman_diff = kalman_diff + outputs_2[8]
    kalman_threshold = kalman_threshold + outputs_2[9]

    # === TIMESTEP 3 ===
    outputs_3 = self.model.forward(h_current,
                                   y[3:4, :, :],
                                   jac_fh[3:4, :, :].reshape(1, self.SD, self.SD),
                                   jac_Ch[3:4, :, :].reshape(1, self.MD, self.SD),
                                   P_current,
                                   Kt[3:4, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_3[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_3[2]
    CPCT_cov_current = CPCT_cov_current + outputs_3[5]
    P_current = outputs_3[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_3[7]
    kalman_diff = kalman_diff + outputs_3[8]
    kalman_threshold = kalman_threshold + outputs_3[9]

    # === TIMESTEP 4 ===
    outputs_4 = self.model.forward(h_current,
                                   y[4:5, :, :],
                                   jac_fh[4:5, :, :].reshape(1, self.SD, self.SD),
                                   jac_Ch[4:5, :, :].reshape(1, self.MD, self.SD),
                                   P_current,
                                   Kt[4:5, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_4[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_4[2]
    CPCT_cov_current = CPCT_cov_current + outputs_4[5]
    P_current = outputs_4[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_4[7]
    kalman_diff = kalman_diff + outputs_4[8]
    kalman_threshold = kalman_threshold + outputs_4[9]

    # === TIMESTEP 5 ===
    outputs_5 = self.model.forward(h_current,
                                   y[5:6, :, :],
                                   jac_fh[5:6, :, :].reshape(1, self.SD, self.SD),
                                   jac_Ch[5:6, :, :].reshape(1, self.MD, self.SD),
                                   P_current,
                                   Kt[5:6, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_5[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_5[2]
    CPCT_cov_current = CPCT_cov_current + outputs_5[5]
    P_current = outputs_5[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_5[7]
    kalman_diff = kalman_diff + outputs_5[8]
    kalman_threshold = kalman_threshold + outputs_5[9]

    # === TIMESTEP 6 ===
    outputs_6 = self.model.forward(h_current,
                                   y[6:7, :, :],
                                   jac_fh[6:7, :, :].reshape(1, self.SD, self.SD),
                                   jac_Ch[6:7, :, :].reshape(1, self.MD, self.SD),
                                   P_current,
                                   Kt[6:7, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_6[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_6[2]
    CPCT_cov_current = CPCT_cov_current + outputs_6[5]
    P_current = outputs_6[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_6[7]
    kalman_diff = kalman_diff + outputs_6[8]
    kalman_threshold = kalman_threshold + outputs_6[9]

    # === TIMESTEP 7 ===
    outputs_7 = self.model.forward(h_current,
                                   y[7:8, :, :],
                                   jac_fh[7:8, :, :].reshape(1, self.SD, self.SD),
                                   jac_Ch[7:8, :, :].reshape(1, self.MD, self.SD),
                                   P_current,
                                   Kt[7:8, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_7[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_7[2]
    CPCT_cov_current = CPCT_cov_current + outputs_7[5]
    P_current = outputs_7[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_7[7]
    kalman_diff = kalman_diff + outputs_7[8]
    kalman_threshold = kalman_threshold + outputs_7[9]

    # === TIMESTEP 8 ===
    outputs_8 = self.model.forward(h_current,
                                   y[8:9, :, :],
                                   jac_fh[8:9, :, :].reshape(1, self.SD, self.SD),
                                   jac_Ch[8:9, :, :].reshape(1, self.MD, self.SD),
                                   P_current,
                                   Kt[8:9, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_8[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_8[2]
    CPCT_cov_current = CPCT_cov_current + outputs_8[5]
    P_current = outputs_8[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_8[7]
    kalman_diff = kalman_diff + outputs_8[8]
    kalman_threshold = kalman_threshold + outputs_8[9]

    # === TIMESTEP 9 ===
    outputs_9 = self.model.forward(h_current,
                                   y[9:10, :, :],
                                   jac_fh[9:10, :, :].reshape(1, self.SD, self.SD),
                                   jac_Ch[9:10, :, :].reshape(1, self.MD, self.SD),
                                   P_current,
                                   Kt[9:10, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_9[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_9[2]
    CPCT_cov_current = CPCT_cov_current + outputs_9[5]
    P_current = outputs_9[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_9[7]
    kalman_diff = kalman_diff + outputs_9[8]
    kalman_threshold = kalman_threshold + outputs_9[9]

    # === TIMESTEP 10 ===
    outputs_10 = self.model.forward(h_current,
                                    y[10:11, :, :],
                                    jac_fh[10:11, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[10:11, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[10:11, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_10[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_10[2]
    CPCT_cov_current = CPCT_cov_current + outputs_10[5]
    P_current = outputs_10[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_10[7]
    kalman_diff = kalman_diff + outputs_10[8]
    kalman_threshold = kalman_threshold + outputs_10[9]

    # === TIMESTEP 11 ===
    outputs_11 = self.model.forward(h_current,
                                    y[11:12, :, :],
                                    jac_fh[11:12, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[11:12, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[11:12, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_11[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_11[2]
    CPCT_cov_current = CPCT_cov_current + outputs_11[5]
    P_current = outputs_11[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_11[7]
    kalman_diff = kalman_diff + outputs_11[8]
    kalman_threshold = kalman_threshold + outputs_11[9]

    # === TIMESTEP 12 ===
    outputs_12 = self.model.forward(h_current,
                                    y[12:13, :, :],
                                    jac_fh[12:13, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[12:13, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[12:13, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_12[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_12[2]
    CPCT_cov_current = CPCT_cov_current + outputs_12[5]
    P_current = outputs_12[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_12[7]
    kalman_diff = kalman_diff + outputs_12[8]
    kalman_threshold = kalman_threshold + outputs_12[9]

    # === TIMESTEP 13 ===
    outputs_13 = self.model.forward(h_current,
                                    y[13:14, :, :],
                                    jac_fh[13:14, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[13:14, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[13:14, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_13[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_13[2]
    CPCT_cov_current = CPCT_cov_current + outputs_13[5]
    P_current = outputs_13[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_13[7]
    kalman_diff = kalman_diff + outputs_13[8]
    kalman_threshold = kalman_threshold + outputs_13[9]

    # === TIMESTEP 14 ===
    outputs_14 = self.model.forward(h_current,
                                    y[14:15, :, :],
                                    jac_fh[14:15, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[14:15, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[14:15, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_14[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_14[2]
    CPCT_cov_current = CPCT_cov_current + outputs_14[5]
    P_current = outputs_14[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_14[7]
    kalman_diff = kalman_diff + outputs_14[8]
    kalman_threshold = kalman_threshold + outputs_14[9]

    # === TIMESTEP 15 ===
    outputs_15 = self.model.forward(h_current,
                                    y[15:16, :, :],
                                    jac_fh[15:16, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[15:16, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[15:16, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_15[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_15[2]
    CPCT_cov_current = CPCT_cov_current + outputs_15[5]
    P_current = outputs_15[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_15[7]
    kalman_diff = kalman_diff + outputs_15[8]
    kalman_threshold = kalman_threshold + outputs_15[9]

    h_current = torch.cat([h_current, nonce_h], dim=2)
    P_current = torch.cat([P_current, nonce_P], dim=2)
    delta_y_current = torch.cat([delta_y_current, nonce_dy], dim=2)
    CPCT_cov_current = torch.cat([CPCT_cov_current, nonce_CPCT_cov], dim=2)
    KCR_status = torch.cat([KCR_status, nonce_KCR_status], dim=2)
    kalman_diff = torch.cat([kalman_diff, nonce_kalman_diff], dim=1)
    kalman_threshold = torch.cat([kalman_threshold, nonce_kalman_threshold], dim=1)

    return h_current, P_current, delta_y_current, CPCT_cov_current, KCR_status, kalman_diff, kalman_threshold

forward2

forward2(h, P, delta_y, CPCT_cov, y, jac_fh, jac_Ch, Kt, KCR_status, nonce_h, nonce_P, nonce_dy, nonce_CPCT_cov, nonce_KCR_status, nonce_kalman_diff, nonce_kalman_threshold)

Forward pass with exactly 2 timesteps

Parameters:

Name Type Description Default
h

Initial hidden state [1, 1, SD]

required
P

Initial covariance matrix [1, SD, SD]

required
delta_y

Initial residual [1, 1, is_r]

required
CPCT_cov

Initial residual covariance [1, is_r, is_r]

required
y

Observations for 2 timesteps [2, obs_dim]

required
jac_fh

Jacobian fh for 2 timesteps [2, ...]

required
jac_Ch

Jacobian Ch for 2 timesteps [2, ...]

required
Kt

Kalman gain for 2 timesteps [2, ...]

required
Source code in src/PredictionWrapper.py
def forward2(self, h, P, delta_y, CPCT_cov, y, jac_fh, jac_Ch, Kt, KCR_status,
             nonce_h,nonce_P,nonce_dy,nonce_CPCT_cov,nonce_KCR_status,nonce_kalman_diff,nonce_kalman_threshold,):
    """
    Forward pass with exactly 2 timesteps

    Args:
        h: Initial hidden state [1, 1, SD]
        P: Initial covariance matrix [1, SD, SD]
        delta_y: Initial residual [1, 1, is_r]
        CPCT_cov: Initial residual covariance [1, is_r, is_r]
        y: Observations for 2 timesteps [2, obs_dim]
        jac_fh: Jacobian fh for 2 timesteps [2, ...]
        jac_Ch: Jacobian Ch for 2 timesteps [2, ...]
        Kt: Kalman gain for 2 timesteps [2, ...]
    """

    h_current = h[0:1, :, :self.SD].reshape(1, 1, self.SD)
    P_current = P[0:1, :, :self.SD].reshape(1, self.SD, self.SD)

    delta_y_current = delta_y.reshape(1, 1, self.MD+1)
    CPCT_cov_current = CPCT_cov.reshape(1, self.MD, self.MD+1)

    delta_y_current = delta_y_current[0:1, :, :self.MD].reshape(1, 1, self.MD)
    CPCT_cov_current = CPCT_cov_current[0:1, :, :self.MD].reshape(1, self.MD, self.MD)
    y = y[:,:,:self.MD]
    jac_fh = jac_fh[:,:,:self.SD]
    jac_Ch = jac_Ch[:, :, :self.MD]
    Kt = Kt[:, :, :self.SD]
    KCR_status = KCR_status[:,:,0:1].reshape(1,1,1)

    nonce_h = nonce_h.reshape((1, 1, 1))
    nonce_dy = nonce_dy.reshape((1, 1, 1))
    nonce_KCR_status = nonce_KCR_status.reshape((1, 1, 1))
    nonce_P = nonce_P.reshape((1, self.SD, 1))
    nonce_CPCT_cov = nonce_CPCT_cov.reshape((1, self.MD, 1))
    nonce_kalman_diff = nonce_kalman_diff.reshape((1, 1, self.SD))
    nonce_kalman_threshold = nonce_kalman_threshold.reshape((1, 1, self.SD))

    assert h_current.shape[2] == self.SD
    assert nonce_h.shape == (1, 1, 1)
    assert nonce_KCR_status.shape == (1, 1, 1)
    assert nonce_dy.shape == (1, 1, 1)
    assert nonce_P.shape == (1, self.SD, 1)
    assert nonce_CPCT_cov.shape == (1, self.MD, 1)
    assert nonce_kalman_diff.shape == (1, 1, self.SD)
    assert nonce_kalman_threshold.shape == (1, 1, self.SD)

    # === TIMESTEP 0 ===
    outputs_0 = self.model.forward(h_current,
                                 y[0:1, :, :],
                                 jac_fh[0:1, :, :].reshape(1, self.SD, self.SD),
                                 jac_Ch[0:1, :, :].reshape(1, self.MD, self.SD),
                                 P_current,
                                 Kt[0:1, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_0[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_0[2]
    CPCT_cov_current = CPCT_cov_current + outputs_0[5]
    P_current = outputs_0[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status*outputs_0[7]
    kalman_diff = outputs_0[8]
    kalman_threshold = outputs_0[9]

    # === TIMESTEP 1 ===
    outputs_1 = self.model.forward(h_current,
                                   y[1:2, :, :],
                                   jac_fh[1:2, :, :].reshape(1, self.SD, self.SD),
                                   jac_Ch[1:2, :, :].reshape(1, self.MD, self.SD),
                                   P_current,
                                   Kt[1:2, :, :].reshape(1, self.MD, self.SD))

    h_current = outputs_1[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_1[2]
    CPCT_cov_current = CPCT_cov_current + outputs_1[5]
    P_current = outputs_1[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status*outputs_1[7]
    kalman_diff = kalman_diff + outputs_1[8]
    kalman_threshold = kalman_threshold + outputs_1[9]

    h_current = torch.cat([h_current, nonce_h], dim=2)
    P_current = torch.cat([P_current, nonce_P], dim=2)
    delta_y_current = torch.cat([delta_y_current, nonce_dy], dim=2)
    CPCT_cov_current = torch.cat([CPCT_cov_current, nonce_CPCT_cov], dim=2)
    KCR_status = torch.cat([KCR_status, nonce_KCR_status], dim=2)
    kalman_diff = torch.cat([kalman_diff, nonce_kalman_diff], dim=1)
    kalman_threshold = torch.cat([kalman_threshold, nonce_kalman_threshold], dim=1)

    return h_current, P_current, delta_y_current, CPCT_cov_current, KCR_status, kalman_diff, kalman_threshold

forward32

forward32(h, P, delta_y, CPCT_cov, y, jac_fh, jac_Ch, Kt, KCR_status, nonce_h, nonce_P, nonce_dy, nonce_CPCT_cov, nonce_KCR_status, nonce_kalman_diff, nonce_kalman_threshold)

Forward pass with exactly 16 timesteps

Parameters:

Name Type Description Default
h

Initial hidden state [1, 1, SD]

required
P

Initial covariance matrix [1, SD, SD]

required
delta_y

Initial residual [1, 1, is_r]

required
CPCT_cov

Initial residual covariance [1, is_r, is_r]

required
y

Observations for 16 timesteps [16, obs_dim]

required
jac_fh

Jacobian fh for 16 timesteps [16, ...]

required
jac_Ch

Jacobian Ch for 16 timesteps [16, ...]

required
Kt

Kalman gain for 16 timesteps [16, ...]

required
Source code in src/PredictionWrapper.py
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
def forward32(self, h, P, delta_y, CPCT_cov, y, jac_fh, jac_Ch, Kt, KCR_status,
             nonce_h,nonce_P,nonce_dy,nonce_CPCT_cov,nonce_KCR_status,nonce_kalman_diff,nonce_kalman_threshold,):
    """
    Forward pass with exactly 16 timesteps

    Args:
        h: Initial hidden state [1, 1, SD]
        P: Initial covariance matrix [1, SD, SD]
        delta_y: Initial residual [1, 1, is_r]
        CPCT_cov: Initial residual covariance [1, is_r, is_r]
        y: Observations for 16 timesteps [16, obs_dim]
        jac_fh: Jacobian fh for 16 timesteps [16, ...]
        jac_Ch: Jacobian Ch for 16 timesteps [16, ...]
        Kt: Kalman gain for 16 timesteps [16, ...]
    """

    h_current = h[0:1, :, :self.SD].reshape(1, 1, self.SD)
    P_current = P[0:1, :, :self.SD].reshape(1, self.SD, self.SD)

    delta_y_current = delta_y.reshape(1, 1, self.MD+1)
    CPCT_cov_current = CPCT_cov.reshape(1, self.MD, self.MD+1)

    delta_y_current = delta_y_current[0:1, :, :self.MD].reshape(1, 1, self.MD)
    CPCT_cov_current = CPCT_cov_current[0:1, :, :self.MD].reshape(1, self.MD, self.MD)
    y = y[:, :, :self.MD]
    jac_fh = jac_fh[:, :, :self.SD]
    jac_Ch = jac_Ch[:, :, :self.MD]
    Kt = Kt[:, :, :self.SD]
    KCR_status = KCR_status[:,:,0:1].reshape(1,1,1)

    nonce_h = nonce_h.reshape((1, 1, 1))
    nonce_dy = nonce_dy.reshape((1, 1, 1))
    nonce_KCR_status = nonce_KCR_status.reshape((1, 1, 1))
    nonce_P = nonce_P.reshape((1, self.SD, 1))
    nonce_CPCT_cov = nonce_CPCT_cov.reshape((1, self.MD, 1))
    nonce_kalman_diff = nonce_kalman_diff.reshape((1, 1, self.SD))
    nonce_kalman_threshold = nonce_kalman_threshold.reshape((1, 1, self.SD))

    assert h_current.shape[2] == self.SD
    assert nonce_h.shape == (1, 1, 1)
    assert nonce_KCR_status.shape == (1, 1, 1)
    assert nonce_dy.shape == (1, 1, 1)
    assert nonce_P.shape == (1, self.SD, 1)
    assert nonce_CPCT_cov.shape == (1, self.MD, 1)
    assert nonce_kalman_diff.shape == (1, 1, self.SD)
    assert nonce_kalman_threshold.shape == (1, 1, self.SD)

    # === TIMESTEP 0 ===
    outputs_0 = self.model.forward(h_current,
                                   y[0:1, :, :],
                                   jac_fh[0:1, :, :].reshape(1, self.SD, self.SD),
                                   jac_Ch[0:1, :, :].reshape(1, self.MD, self.SD),
                                   P_current,
                                   Kt[0:1, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_0[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_0[2]
    CPCT_cov_current = CPCT_cov_current + outputs_0[5]
    P_current = outputs_0[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status*outputs_0[7]
    kalman_diff = outputs_0[8]
    kalman_threshold = outputs_0[9]

    # === TIMESTEP 1 ===
    outputs_1 = self.model.forward(h_current,
                                   y[1:2, :, :],
                                   jac_fh[1:2, :, :].reshape(1, self.SD, self.SD),
                                   jac_Ch[1:2, :, :].reshape(1, self.MD, self.SD),
                                   P_current,
                                   Kt[1:2, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_1[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_1[2]
    CPCT_cov_current = CPCT_cov_current + outputs_1[5]
    P_current = outputs_1[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_1[7]
    kalman_diff = kalman_diff + outputs_1[8]
    kalman_threshold = kalman_threshold + outputs_1[9]

    # === TIMESTEP 2 ===
    outputs_2 = self.model.forward(h_current,
                                   y[2:3, :, :],
                                   jac_fh[2:3, :, :].reshape(1, self.SD, self.SD),
                                   jac_Ch[2:3, :, :].reshape(1, self.MD, self.SD),
                                   P_current,
                                   Kt[2:3, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_2[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_2[2]
    CPCT_cov_current = CPCT_cov_current + outputs_2[5]
    P_current = outputs_2[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_2[7]
    kalman_diff = kalman_diff + outputs_2[8]
    kalman_threshold = kalman_threshold + outputs_2[9]

    # === TIMESTEP 3 ===
    outputs_3 = self.model.forward(h_current,
                                   y[3:4, :, :],
                                   jac_fh[3:4, :, :].reshape(1, self.SD, self.SD),
                                   jac_Ch[3:4, :, :].reshape(1, self.MD, self.SD),
                                   P_current,
                                   Kt[3:4, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_3[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_3[2]
    CPCT_cov_current = CPCT_cov_current + outputs_3[5]
    P_current = outputs_3[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_3[7]
    kalman_diff = kalman_diff + outputs_3[8]
    kalman_threshold = kalman_threshold + outputs_3[9]

    # === TIMESTEP 4 ===
    outputs_4 = self.model.forward(h_current,
                                   y[4:5, :, :],
                                   jac_fh[4:5, :, :].reshape(1, self.SD, self.SD),
                                   jac_Ch[4:5, :, :].reshape(1, self.MD, self.SD),
                                   P_current,
                                   Kt[4:5, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_4[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_4[2]
    CPCT_cov_current = CPCT_cov_current + outputs_4[5]
    P_current = outputs_4[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_4[7]
    kalman_diff = kalman_diff + outputs_4[8]
    kalman_threshold = kalman_threshold + outputs_4[9]

    # === TIMESTEP 5 ===
    outputs_5 = self.model.forward(h_current,
                                   y[5:6, :, :],
                                   jac_fh[5:6, :, :].reshape(1, self.SD, self.SD),
                                   jac_Ch[5:6, :, :].reshape(1, self.MD, self.SD),
                                   P_current,
                                   Kt[5:6, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_5[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_5[2]
    CPCT_cov_current = CPCT_cov_current + outputs_5[5]
    P_current = outputs_5[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_5[7]
    kalman_diff = kalman_diff + outputs_5[8]
    kalman_threshold = kalman_threshold + outputs_5[9]

    # === TIMESTEP 6 ===
    outputs_6 = self.model.forward(h_current,
                                   y[6:7, :, :],
                                   jac_fh[6:7, :, :].reshape(1, self.SD, self.SD),
                                   jac_Ch[6:7, :, :].reshape(1, self.MD, self.SD),
                                   P_current,
                                   Kt[6:7, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_6[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_6[2]
    CPCT_cov_current = CPCT_cov_current + outputs_6[5]
    P_current = outputs_6[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_6[7]
    kalman_diff = kalman_diff + outputs_6[8]
    kalman_threshold = kalman_threshold + outputs_6[9]

    # === TIMESTEP 7 ===
    outputs_7 = self.model.forward(h_current,
                                   y[7:8, :, :],
                                   jac_fh[7:8, :, :].reshape(1, self.SD, self.SD),
                                   jac_Ch[7:8, :, :].reshape(1, self.MD, self.SD),
                                   P_current,
                                   Kt[7:8, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_7[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_7[2]
    CPCT_cov_current = CPCT_cov_current + outputs_7[5]
    P_current = outputs_7[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_7[7]
    kalman_diff = kalman_diff + outputs_7[8]
    kalman_threshold = kalman_threshold + outputs_7[9]

    # === TIMESTEP 8 ===
    outputs_8 = self.model.forward(h_current,
                                   y[8:9, :, :],
                                   jac_fh[8:9, :, :].reshape(1, self.SD, self.SD),
                                   jac_Ch[8:9, :, :].reshape(1, self.MD, self.SD),
                                   P_current,
                                   Kt[8:9, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_8[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_8[2]
    CPCT_cov_current = CPCT_cov_current + outputs_8[5]
    P_current = outputs_8[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_8[7]
    kalman_diff = kalman_diff + outputs_8[8]
    kalman_threshold = kalman_threshold + outputs_8[9]

    # === TIMESTEP 9 ===
    outputs_9 = self.model.forward(h_current,
                                   y[9:10, :, :],
                                   jac_fh[9:10, :, :].reshape(1, self.SD, self.SD),
                                   jac_Ch[9:10, :, :].reshape(1, self.MD, self.SD),
                                   P_current,
                                   Kt[9:10, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_9[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_9[2]
    CPCT_cov_current = CPCT_cov_current + outputs_9[5]
    P_current = outputs_9[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_9[7]
    kalman_diff = kalman_diff + outputs_9[8]
    kalman_threshold = kalman_threshold + outputs_9[9]

    # === TIMESTEP 10 ===
    outputs_10 = self.model.forward(h_current,
                                    y[10:11, :, :],
                                    jac_fh[10:11, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[10:11, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[10:11, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_10[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_10[2]
    CPCT_cov_current = CPCT_cov_current + outputs_10[5]
    P_current = outputs_10[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_10[7]
    kalman_diff = kalman_diff + outputs_10[8]
    kalman_threshold = kalman_threshold + outputs_10[9]

    # === TIMESTEP 11 ===
    outputs_11 = self.model.forward(h_current,
                                    y[11:12, :, :],
                                    jac_fh[11:12, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[11:12, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[11:12, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_11[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_11[2]
    CPCT_cov_current = CPCT_cov_current + outputs_11[5]
    P_current = outputs_11[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_11[7]
    kalman_diff = kalman_diff + outputs_11[8]
    kalman_threshold = kalman_threshold + outputs_11[9]

    # === TIMESTEP 12 ===
    outputs_12 = self.model.forward(h_current,
                                    y[12:13, :, :],
                                    jac_fh[12:13, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[12:13, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[12:13, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_12[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_12[2]
    CPCT_cov_current = CPCT_cov_current + outputs_12[5]
    P_current = outputs_12[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_12[7]
    kalman_diff = kalman_diff + outputs_12[8]
    kalman_threshold = kalman_threshold + outputs_12[9]

    # === TIMESTEP 13 ===
    outputs_13 = self.model.forward(h_current,
                                    y[13:14, :, :],
                                    jac_fh[13:14, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[13:14, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[13:14, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_13[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_13[2]
    CPCT_cov_current = CPCT_cov_current + outputs_13[5]
    P_current = outputs_13[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_13[7]
    kalman_diff = kalman_diff + outputs_13[8]
    kalman_threshold = kalman_threshold + outputs_13[9]

    # === TIMESTEP 14 ===
    outputs_14 = self.model.forward(h_current,
                                    y[14:15, :, :],
                                    jac_fh[14:15, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[14:15, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[14:15, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_14[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_14[2]
    CPCT_cov_current = CPCT_cov_current + outputs_14[5]
    P_current = outputs_14[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_14[7]
    kalman_diff = kalman_diff + outputs_14[8]
    kalman_threshold = kalman_threshold + outputs_14[9]

    # === TIMESTEP 15 ===
    outputs_15 = self.model.forward(h_current,
                                    y[15:16, :, :],
                                    jac_fh[15:16, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[15:16, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[15:16, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_15[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_15[2]
    CPCT_cov_current = CPCT_cov_current + outputs_15[5]
    P_current = outputs_15[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_15[7]
    kalman_diff = kalman_diff + outputs_15[8]
    kalman_threshold = kalman_threshold + outputs_15[9]

    # === TIMESTEP 16 ===
    outputs_16 = self.model.forward(h_current,
                                    y[16:17, :, :],
                                    jac_fh[16:17, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[16:17, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[16:17, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_16[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_16[2]
    CPCT_cov_current = CPCT_cov_current + outputs_16[5]
    P_current = outputs_16[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_16[7]
    kalman_diff = kalman_diff + outputs_16[8]
    kalman_threshold = kalman_threshold + outputs_16[9]

    # === TIMESTEP 17 ===
    outputs_17 = self.model.forward(h_current,
                                    y[17:18, :, :],
                                    jac_fh[17:18, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[17:18, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[17:18, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_17[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_17[2]
    CPCT_cov_current = CPCT_cov_current + outputs_17[5]
    P_current = outputs_17[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_17[7]
    kalman_diff = kalman_diff + outputs_17[8]
    kalman_threshold = kalman_threshold + outputs_17[9]

    # === TIMESTEP 18 ===
    outputs_18 = self.model.forward(h_current,
                                    y[18:19, :, :],
                                    jac_fh[18:19, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[18:19, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[18:19, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_18[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_18[2]
    CPCT_cov_current = CPCT_cov_current + outputs_18[5]
    P_current = outputs_18[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_18[7]
    kalman_diff = kalman_diff + outputs_18[8]
    kalman_threshold = kalman_threshold + outputs_18[9]

    # === TIMESTEP 19 ===
    outputs_19 = self.model.forward(h_current,
                                    y[19:20, :, :],
                                    jac_fh[19:20, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[19:20, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[19:20, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_19[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_19[2]
    CPCT_cov_current = CPCT_cov_current + outputs_19[5]
    P_current = outputs_19[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_19[7]
    kalman_diff = kalman_diff + outputs_19[8]
    kalman_threshold = kalman_threshold + outputs_19[9]

    # === TIMESTEP 20 ===
    outputs_20 = self.model.forward(h_current,
                                    y[20:21, :, :],
                                    jac_fh[20:21, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[20:21, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[20:21, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_20[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_20[2]
    CPCT_cov_current = CPCT_cov_current + outputs_20[5]
    P_current = outputs_20[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_20[7]
    kalman_diff = kalman_diff + outputs_20[8]
    kalman_threshold = kalman_threshold + outputs_20[9]

    # === TIMESTEP 21 ===
    outputs_21 = self.model.forward(h_current,
                                    y[21:22, :, :],
                                    jac_fh[21:22, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[21:22, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[21:22, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_21[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_21[2]
    CPCT_cov_current = CPCT_cov_current + outputs_21[5]
    P_current = outputs_21[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_21[7]
    kalman_diff = kalman_diff + outputs_21[8]
    kalman_threshold = kalman_threshold + outputs_21[9]

    # === TIMESTEP 22 ===
    outputs_22 = self.model.forward(h_current,
                                    y[22:23, :, :],
                                    jac_fh[22:23, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[22:23, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[22:23, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_22[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_22[2]
    CPCT_cov_current = CPCT_cov_current + outputs_22[5]
    P_current = outputs_22[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_22[7]
    kalman_diff = kalman_diff + outputs_22[8]
    kalman_threshold = kalman_threshold + outputs_22[9]

    # === TIMESTEP 23 ===
    outputs_23 = self.model.forward(h_current,
                                    y[23:24, :, :],
                                    jac_fh[23:24, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[23:24, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[23:24, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_23[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_23[2]
    CPCT_cov_current = CPCT_cov_current + outputs_23[5]
    P_current = outputs_23[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_23[7]
    kalman_diff = kalman_diff + outputs_23[8]
    kalman_threshold = kalman_threshold + outputs_23[9]

    # === TIMESTEP 24 ===
    outputs_24 = self.model.forward(h_current,
                                    y[24:25, :, :],
                                    jac_fh[24:25, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[24:25, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[24:25, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_24[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_24[2]
    CPCT_cov_current = CPCT_cov_current + outputs_24[5]
    P_current = outputs_24[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_24[7]
    kalman_diff = kalman_diff + outputs_24[8]
    kalman_threshold = kalman_threshold + outputs_24[9]

    # === TIMESTEP 25 ===
    outputs_25 = self.model.forward(h_current,
                                    y[25:26, :, :],
                                    jac_fh[25:26, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[25:26, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[25:26, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_25[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_25[2]
    CPCT_cov_current = CPCT_cov_current + outputs_25[5]
    P_current = outputs_25[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_25[7]
    kalman_diff = kalman_diff + outputs_25[8]
    kalman_threshold = kalman_threshold + outputs_25[9]

    # === TIMESTEP 26 ===
    outputs_26 = self.model.forward(h_current,
                                    y[26:27, :, :],
                                    jac_fh[26:27, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[26:27, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[26:27, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_26[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_26[2]
    CPCT_cov_current = CPCT_cov_current + outputs_26[5]
    P_current = outputs_26[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_26[7]
    kalman_diff = kalman_diff + outputs_26[8]
    kalman_threshold = kalman_threshold + outputs_26[9]

    # === TIMESTEP 27 ===
    outputs_27 = self.model.forward(h_current,
                                    y[27:28, :, :],
                                    jac_fh[27:28, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[27:28, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[27:28, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_27[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_27[2]
    CPCT_cov_current = CPCT_cov_current + outputs_27[5]
    P_current = outputs_27[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_27[7]
    kalman_diff = kalman_diff + outputs_27[8]
    kalman_threshold = kalman_threshold + outputs_27[9]

    # === TIMESTEP 28 ===
    outputs_28 = self.model.forward(h_current,
                                    y[28:29, :, :],
                                    jac_fh[28:29, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[28:29, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[28:29, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_28[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_28[2]
    CPCT_cov_current = CPCT_cov_current + outputs_28[5]
    P_current = outputs_28[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_28[7]
    kalman_diff = kalman_diff + outputs_28[8]
    kalman_threshold = kalman_threshold + outputs_28[9]

    # === TIMESTEP 29 ===
    outputs_29 = self.model.forward(h_current,
                                    y[29:30, :, :],
                                    jac_fh[29:30, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[29:30, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[29:30, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_29[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_29[2]
    CPCT_cov_current = CPCT_cov_current + outputs_29[5]
    P_current = outputs_29[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_29[7]
    kalman_diff = kalman_diff + outputs_29[8]
    kalman_threshold = kalman_threshold + outputs_29[9]

    # === TIMESTEP 30 ===
    outputs_30 = self.model.forward(h_current,
                                    y[30:31, :, :],
                                    jac_fh[30:31, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[30:31, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[30:31, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_30[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_30[2]
    CPCT_cov_current = CPCT_cov_current + outputs_30[5]
    P_current = outputs_30[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_30[7]
    kalman_diff = kalman_diff + outputs_30[8]
    kalman_threshold = kalman_threshold + outputs_30[9]

    # === TIMESTEP 31 ===
    outputs_31 = self.model.forward(h_current,
                                    y[31:32, :, :],
                                    jac_fh[31:32, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[31:32, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[31:32, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_31[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_31[2]
    CPCT_cov_current = CPCT_cov_current + outputs_31[5]
    P_current = outputs_31[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_31[7]
    kalman_diff = kalman_diff + outputs_31[8]
    kalman_threshold = kalman_threshold + outputs_31[9]

    h_current = torch.cat([h_current, nonce_h], dim=2)
    P_current = torch.cat([P_current, nonce_P], dim=2)
    delta_y_current = torch.cat([delta_y_current, nonce_dy], dim=2)
    CPCT_cov_current = torch.cat([CPCT_cov_current, nonce_CPCT_cov], dim=2)
    KCR_status = torch.cat([KCR_status, nonce_KCR_status], dim=2)
    kalman_diff = torch.cat([kalman_diff, nonce_kalman_diff], dim=1)
    kalman_threshold = torch.cat([kalman_threshold, nonce_kalman_threshold], dim=1)

    return h_current, P_current, delta_y_current, CPCT_cov_current, KCR_status, kalman_diff, kalman_threshold

forward4

forward4(h, P, delta_y, CPCT_cov, y, jac_fh, jac_Ch, Kt, KCR_status, nonce_h, nonce_P, nonce_dy, nonce_CPCT_cov, nonce_KCR_status, nonce_kalman_diff, nonce_kalman_threshold)

Forward pass with exactly 4 timesteps (EZKL-compatible)

Parameters:

Name Type Description Default
h

Initial hidden state [1, 1, SD]

required
P

Initial covariance matrix [1, SD, SD]

required
delta_y

Initial residual [1, 1, is_r]

required
CPCT_cov

Initial residual covariance [1, is_r, is_r]

required
y

Observations for 4 timesteps [4, obs_dim]

required
jac_fh

Jacobian fh for 4 timesteps [4, ...]

required
jac_Ch

Jacobian Ch for 4 timesteps [4, ...]

required
Kt

Kalman gain for 4 timesteps [4, ...]

required
Source code in src/PredictionWrapper.py
def forward4(self, h, P, delta_y, CPCT_cov, y, jac_fh, jac_Ch, Kt, KCR_status,
             nonce_h,nonce_P,nonce_dy,nonce_CPCT_cov,nonce_KCR_status,nonce_kalman_diff,nonce_kalman_threshold,):
    """
    Forward pass with exactly 4 timesteps (EZKL-compatible)

    Args:
        h: Initial hidden state [1, 1, SD]
        P: Initial covariance matrix [1, SD, SD]
        delta_y: Initial residual [1, 1, is_r]
        CPCT_cov: Initial residual covariance [1, is_r, is_r]
        y: Observations for 4 timesteps [4, obs_dim]
        jac_fh: Jacobian fh for 4 timesteps [4, ...]
        jac_Ch: Jacobian Ch for 4 timesteps [4, ...]
        Kt: Kalman gain for 4 timesteps [4, ...]
    """

    h_current = h[0:1, :, :self.SD].reshape(1, 1, self.SD)
    P_current = P[0:1, :, :self.SD].reshape(1, self.SD, self.SD)

    delta_y_current = delta_y.reshape(1, 1, self.MD+1)
    CPCT_cov_current = CPCT_cov.reshape(1, self.MD, self.MD+1)

    delta_y_current = delta_y_current[0:1, :, :self.MD].reshape(1, 1, self.MD)
    CPCT_cov_current = CPCT_cov_current[0:1, :, :self.MD].reshape(1, self.MD, self.MD)
    y = y[:, :, :self.MD]
    jac_fh = jac_fh[:, :, :self.SD]
    jac_Ch = jac_Ch[:, :, :self.MD]
    Kt = Kt[:, :, :self.SD]
    KCR_status = KCR_status[:,:,0:1].reshape(1,1,1)

    nonce_h = nonce_h.reshape((1, 1, 1))
    nonce_dy = nonce_dy.reshape((1, 1, 1))
    nonce_KCR_status = nonce_KCR_status.reshape((1, 1, 1))
    nonce_P = nonce_P.reshape((1, self.SD, 1))
    nonce_CPCT_cov = nonce_CPCT_cov.reshape((1, self.MD, 1))
    nonce_kalman_diff = nonce_kalman_diff.reshape((1, 1, self.SD))
    nonce_kalman_threshold = nonce_kalman_threshold.reshape((1, 1, self.SD))

    assert h_current.shape[2] == self.SD
    assert nonce_h.shape == (1, 1, 1)
    assert nonce_KCR_status.shape == (1, 1, 1)
    assert nonce_dy.shape == (1, 1, 1)
    assert nonce_P.shape == (1, self.SD, 1)
    assert nonce_CPCT_cov.shape == (1, self.MD, 1)
    assert nonce_kalman_diff.shape == (1, 1, self.SD)
    assert nonce_kalman_threshold.shape == (1, 1, self.SD)


    outputs_0 = self.model.forward(h_current,
                                 y[0:1,:,:],
                                 jac_fh[0:1,:,:].reshape(1,self.SD,self.SD),
                                 jac_Ch[0:1,:,:].reshape(1,self.MD,self.SD),
                                 P_current,
                                 Kt[0:1,:,:].reshape(1,self.MD,self.SD))
    h_current = outputs_0[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_0[2]
    CPCT_cov_current = CPCT_cov_current + outputs_0[5]
    P_current = outputs_0[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status*outputs_0[7]
    kalman_diff = outputs_0[8]
    kalman_threshold = outputs_0[9]

    # === TIMESTEP 1 ===
    outputs_1 = self.model.forward(h_current,
                                   y[1:2, :, :],
                                   jac_fh[1:2, :, :].reshape(1, self.SD, self.SD),
                                   jac_Ch[1:2, :, :].reshape(1, self.MD, self.SD),
                                   P_current,
                                   Kt[1:2, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_1[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_1[2]
    CPCT_cov_current = CPCT_cov_current + outputs_1[5]
    P_current = outputs_1[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status*outputs_1[7]
    kalman_diff = kalman_diff + outputs_1[8]
    kalman_threshold = kalman_threshold + outputs_1[9]

    # === TIMESTEP 2 ===
    outputs_2 = self.model.forward(h_current,
                                   y[2:3, :, :],
                                   jac_fh[2:3, :, :].reshape(1, self.SD, self.SD),
                                   jac_Ch[2:3, :, :].reshape(1, self.MD, self.SD),
                                   P_current,
                                   Kt[2:3, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_2[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_2[2]
    CPCT_cov_current = CPCT_cov_current + outputs_2[5]
    P_current = outputs_2[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status*outputs_2[7]
    kalman_diff = kalman_diff + outputs_2[8]
    kalman_threshold = kalman_threshold + outputs_2[9]

    # === TIMESTEP 2 ===
    outputs_3 = self.model.forward(h_current,
                                   y[3:4, :, :],
                                   jac_fh[3:4, :, :].reshape(1, self.SD, self.SD),
                                   jac_Ch[3:4, :, :].reshape(1, self.MD, self.SD),
                                   P_current,
                                   Kt[3:4, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_3[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_3[2]
    CPCT_cov_current = CPCT_cov_current + outputs_3[5]
    P_current = outputs_3[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status*outputs_3[7]
    kalman_diff = kalman_diff + outputs_3[8]
    kalman_threshold = kalman_threshold + outputs_3[9]

    h_current = torch.cat([h_current, nonce_h], dim=2)
    P_current = torch.cat([P_current, nonce_P], dim=2)
    delta_y_current = torch.cat([delta_y_current, nonce_dy], dim=2)
    CPCT_cov_current = torch.cat([CPCT_cov_current, nonce_CPCT_cov], dim=2)
    KCR_status = torch.cat([KCR_status, nonce_KCR_status], dim=2)
    kalman_diff = torch.cat([kalman_diff, nonce_kalman_diff], dim=1)
    kalman_threshold = torch.cat([kalman_threshold, nonce_kalman_threshold], dim=1)

    return h_current, P_current, delta_y_current, CPCT_cov_current, KCR_status, kalman_diff, kalman_threshold

forward64

forward64(h, P, delta_y, CPCT_cov, y, jac_fh, jac_Ch, Kt, KCR_status, nonce_h, nonce_P, nonce_dy, nonce_CPCT_cov, nonce_KCR_status, nonce_kalman_diff, nonce_kalman_threshold)

Forward pass with exactly 64 timesteps

Parameters:

Name Type Description Default
h

Initial hidden state [1, 1, SD]

required
P

Initial covariance matrix [1, SD, SD]

required
delta_y

Initial residual [1, 1, is_r]

required
CPCT_cov

Initial residual covariance [1, is_r, is_r]

required
y

Observations for 16 timesteps [16, obs_dim]

required
jac_fh

Jacobian fh for 16 timesteps [16, ...]

required
jac_Ch

Jacobian Ch for 16 timesteps [16, ...]

required
Kt

Kalman gain for 16 timesteps [16, ...]

required
Source code in src/PredictionWrapper.py
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
def forward64(self, h, P, delta_y, CPCT_cov, y, jac_fh, jac_Ch, Kt, KCR_status,
             nonce_h,nonce_P,nonce_dy,nonce_CPCT_cov,nonce_KCR_status,nonce_kalman_diff,nonce_kalman_threshold,):
    """
    Forward pass with exactly 64 timesteps

    Args:
        h: Initial hidden state [1, 1, SD]
        P: Initial covariance matrix [1, SD, SD]
        delta_y: Initial residual [1, 1, is_r]
        CPCT_cov: Initial residual covariance [1, is_r, is_r]
        y: Observations for 16 timesteps [16, obs_dim]
        jac_fh: Jacobian fh for 16 timesteps [16, ...]
        jac_Ch: Jacobian Ch for 16 timesteps [16, ...]
        Kt: Kalman gain for 16 timesteps [16, ...]
    """

    h_current = h[0:1, :, :self.SD].reshape(1, 1, self.SD)
    P_current = P[0:1, :, :self.SD].reshape(1, self.SD, self.SD)

    delta_y_current = delta_y.reshape(1, 1, self.MD+1)
    CPCT_cov_current = CPCT_cov.reshape(1, self.MD, self.MD+1)

    delta_y_current = delta_y_current[0:1, :, :self.MD].reshape(1, 1, self.MD)
    CPCT_cov_current = CPCT_cov_current[0:1, :, :self.MD].reshape(1, self.MD, self.MD)
    y = y[:, :, :self.MD]
    jac_fh = jac_fh[:, :, :self.SD]
    jac_Ch = jac_Ch[:, :, :self.MD]
    Kt = Kt[:, :, :self.SD]
    KCR_status = KCR_status[:,:,0:1].reshape(1,1,1)

    nonce_h = nonce_h.reshape((1, 1, 1))
    nonce_dy = nonce_dy.reshape((1, 1, 1))
    nonce_KCR_status = nonce_KCR_status.reshape((1, 1, 1))
    nonce_P = nonce_P.reshape((1, self.SD, 1))
    nonce_CPCT_cov = nonce_CPCT_cov.reshape((1, self.MD, 1))
    nonce_kalman_diff = nonce_kalman_diff.reshape((1, 1, self.SD))
    nonce_kalman_threshold = nonce_kalman_threshold.reshape((1, 1, self.SD))

    assert h_current.shape[2] == self.SD
    assert nonce_h.shape == (1, 1, 1)
    assert nonce_KCR_status.shape == (1, 1, 1)
    assert nonce_dy.shape == (1, 1, 1)
    assert nonce_P.shape == (1, self.SD, 1)
    assert nonce_CPCT_cov.shape == (1, self.MD, 1)
    assert nonce_kalman_diff.shape == (1, 1, self.SD)
    assert nonce_kalman_threshold.shape == (1, 1, self.SD)


    # === TIMESTEP 0 ===
    outputs_0 = self.model.forward(h_current,
                                   y[0:1, :, :],
                                   jac_fh[0:1, :, :].reshape(1, self.SD, self.SD),
                                   jac_Ch[0:1, :, :].reshape(1, self.MD, self.SD),
                                   P_current,
                                   Kt[0:1, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_0[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_0[2]
    CPCT_cov_current = CPCT_cov_current + outputs_0[5]
    P_current = outputs_0[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status*outputs_0[7]
    kalman_diff = outputs_0[8]
    kalman_threshold = outputs_0[9]

    # === TIMESTEP 1 ===
    outputs_1 = self.model.forward(h_current,
                                   y[1:2, :, :],
                                   jac_fh[1:2, :, :].reshape(1, self.SD, self.SD),
                                   jac_Ch[1:2, :, :].reshape(1, self.MD, self.SD),
                                   P_current,
                                   Kt[1:2, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_1[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_1[2]
    CPCT_cov_current = CPCT_cov_current + outputs_1[5]
    P_current = outputs_1[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_1[7]
    kalman_diff = kalman_diff + outputs_1[8]
    kalman_threshold = kalman_threshold + outputs_1[9]

    # === TIMESTEP 2 ===
    outputs_2 = self.model.forward(h_current,
                                   y[2:3, :, :],
                                   jac_fh[2:3, :, :].reshape(1, self.SD, self.SD),
                                   jac_Ch[2:3, :, :].reshape(1, self.MD, self.SD),
                                   P_current,
                                   Kt[2:3, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_2[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_2[2]
    CPCT_cov_current = CPCT_cov_current + outputs_2[5]
    P_current = outputs_2[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_2[7]
    kalman_diff = kalman_diff + outputs_2[8]
    kalman_threshold = kalman_threshold + outputs_2[9]

    # === TIMESTEP 3 ===
    outputs_3 = self.model.forward(h_current,
                                   y[3:4, :, :],
                                   jac_fh[3:4, :, :].reshape(1, self.SD, self.SD),
                                   jac_Ch[3:4, :, :].reshape(1, self.MD, self.SD),
                                   P_current,
                                   Kt[3:4, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_3[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_3[2]
    CPCT_cov_current = CPCT_cov_current + outputs_3[5]
    P_current = outputs_3[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_3[7]
    kalman_diff = kalman_diff + outputs_3[8]
    kalman_threshold = kalman_threshold + outputs_3[9]

    # === TIMESTEP 4 ===
    outputs_4 = self.model.forward(h_current,
                                   y[4:5, :, :],
                                   jac_fh[4:5, :, :].reshape(1, self.SD, self.SD),
                                   jac_Ch[4:5, :, :].reshape(1, self.MD, self.SD),
                                   P_current,
                                   Kt[4:5, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_4[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_4[2]
    CPCT_cov_current = CPCT_cov_current + outputs_4[5]
    P_current = outputs_4[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_4[7]
    kalman_diff = kalman_diff + outputs_4[8]
    kalman_threshold = kalman_threshold + outputs_4[9]

    # === TIMESTEP 5 ===
    outputs_5 = self.model.forward(h_current,
                                   y[5:6, :, :],
                                   jac_fh[5:6, :, :].reshape(1, self.SD, self.SD),
                                   jac_Ch[5:6, :, :].reshape(1, self.MD, self.SD),
                                   P_current,
                                   Kt[5:6, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_5[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_5[2]
    CPCT_cov_current = CPCT_cov_current + outputs_5[5]
    P_current = outputs_5[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_5[7]
    kalman_diff = kalman_diff + outputs_5[8]
    kalman_threshold = kalman_threshold + outputs_5[9]

    # === TIMESTEP 6 ===
    outputs_6 = self.model.forward(h_current,
                                   y[6:7, :, :],
                                   jac_fh[6:7, :, :].reshape(1, self.SD, self.SD),
                                   jac_Ch[6:7, :, :].reshape(1, self.MD, self.SD),
                                   P_current,
                                   Kt[6:7, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_6[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_6[2]
    CPCT_cov_current = CPCT_cov_current + outputs_6[5]
    P_current = outputs_6[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_6[7]
    kalman_diff = kalman_diff + outputs_6[8]
    kalman_threshold = kalman_threshold + outputs_6[9]

    # === TIMESTEP 7 ===
    outputs_7 = self.model.forward(h_current,
                                   y[7:8, :, :],
                                   jac_fh[7:8, :, :].reshape(1, self.SD, self.SD),
                                   jac_Ch[7:8, :, :].reshape(1, self.MD, self.SD),
                                   P_current,
                                   Kt[7:8, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_7[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_7[2]
    CPCT_cov_current = CPCT_cov_current + outputs_7[5]
    P_current = outputs_7[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_7[7]
    kalman_diff = kalman_diff + outputs_7[8]
    kalman_threshold = kalman_threshold + outputs_7[9]

    # === TIMESTEP 8 ===
    outputs_8 = self.model.forward(h_current,
                                   y[8:9, :, :],
                                   jac_fh[8:9, :, :].reshape(1, self.SD, self.SD),
                                   jac_Ch[8:9, :, :].reshape(1, self.MD, self.SD),
                                   P_current,
                                   Kt[8:9, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_8[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_8[2]
    CPCT_cov_current = CPCT_cov_current + outputs_8[5]
    P_current = outputs_8[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_8[7]
    kalman_diff = kalman_diff + outputs_8[8]
    kalman_threshold = kalman_threshold + outputs_8[9]

    # === TIMESTEP 9 ===
    outputs_9 = self.model.forward(h_current,
                                   y[9:10, :, :],
                                   jac_fh[9:10, :, :].reshape(1, self.SD, self.SD),
                                   jac_Ch[9:10, :, :].reshape(1, self.MD, self.SD),
                                   P_current,
                                   Kt[9:10, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_9[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_9[2]
    CPCT_cov_current = CPCT_cov_current + outputs_9[5]
    P_current = outputs_9[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_9[7]
    kalman_diff = kalman_diff + outputs_9[8]
    kalman_threshold = kalman_threshold + outputs_9[9]

    # === TIMESTEP 10 ===
    outputs_10 = self.model.forward(h_current,
                                    y[10:11, :, :],
                                    jac_fh[10:11, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[10:11, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[10:11, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_10[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_10[2]
    CPCT_cov_current = CPCT_cov_current + outputs_10[5]
    P_current = outputs_10[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_10[7]
    kalman_diff = kalman_diff + outputs_10[8]
    kalman_threshold = kalman_threshold + outputs_10[9]

    # === TIMESTEP 11 ===
    outputs_11 = self.model.forward(h_current,
                                    y[11:12, :, :],
                                    jac_fh[11:12, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[11:12, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[11:12, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_11[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_11[2]
    CPCT_cov_current = CPCT_cov_current + outputs_11[5]
    P_current = outputs_11[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_11[7]
    kalman_diff = kalman_diff + outputs_11[8]
    kalman_threshold = kalman_threshold + outputs_11[9]

    # === TIMESTEP 12 ===
    outputs_12 = self.model.forward(h_current,
                                    y[12:13, :, :],
                                    jac_fh[12:13, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[12:13, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[12:13, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_12[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_12[2]
    CPCT_cov_current = CPCT_cov_current + outputs_12[5]
    P_current = outputs_12[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_12[7]
    kalman_diff = kalman_diff + outputs_12[8]
    kalman_threshold = kalman_threshold + outputs_12[9]

    # === TIMESTEP 13 ===
    outputs_13 = self.model.forward(h_current,
                                    y[13:14, :, :],
                                    jac_fh[13:14, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[13:14, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[13:14, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_13[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_13[2]
    CPCT_cov_current = CPCT_cov_current + outputs_13[5]
    P_current = outputs_13[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_13[7]
    kalman_diff = kalman_diff + outputs_13[8]
    kalman_threshold = kalman_threshold + outputs_13[9]

    # === TIMESTEP 14 ===
    outputs_14 = self.model.forward(h_current,
                                    y[14:15, :, :],
                                    jac_fh[14:15, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[14:15, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[14:15, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_14[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_14[2]
    CPCT_cov_current = CPCT_cov_current + outputs_14[5]
    P_current = outputs_14[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_14[7]
    kalman_diff = kalman_diff + outputs_14[8]
    kalman_threshold = kalman_threshold + outputs_14[9]

    # === TIMESTEP 15 ===
    outputs_15 = self.model.forward(h_current,
                                    y[15:16, :, :],
                                    jac_fh[15:16, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[15:16, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[15:16, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_15[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_15[2]
    CPCT_cov_current = CPCT_cov_current + outputs_15[5]
    P_current = outputs_15[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_15[7]
    kalman_diff = kalman_diff + outputs_15[8]
    kalman_threshold = kalman_threshold + outputs_15[9]

    # === TIMESTEP 16 ===
    outputs_16 = self.model.forward(h_current,
                                    y[16:17, :, :],
                                    jac_fh[16:17, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[16:17, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[16:17, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_16[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_16[2]
    CPCT_cov_current = CPCT_cov_current + outputs_16[5]
    P_current = outputs_16[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_16[7]
    kalman_diff = kalman_diff + outputs_16[8]
    kalman_threshold = kalman_threshold + outputs_16[9]

    # === TIMESTEP 17 ===
    outputs_17 = self.model.forward(h_current,
                                    y[17:18, :, :],
                                    jac_fh[17:18, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[17:18, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[17:18, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_17[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_17[2]
    CPCT_cov_current = CPCT_cov_current + outputs_17[5]
    P_current = outputs_17[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_17[7]
    kalman_diff = kalman_diff + outputs_17[8]
    kalman_threshold = kalman_threshold + outputs_17[9]

    # === TIMESTEP 18 ===
    outputs_18 = self.model.forward(h_current,
                                    y[18:19, :, :],
                                    jac_fh[18:19, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[18:19, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[18:19, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_18[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_18[2]
    CPCT_cov_current = CPCT_cov_current + outputs_18[5]
    P_current = outputs_18[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_18[7]
    kalman_diff = kalman_diff + outputs_18[8]
    kalman_threshold = kalman_threshold + outputs_18[9]

    # === TIMESTEP 19 ===
    outputs_19 = self.model.forward(h_current,
                                    y[19:20, :, :],
                                    jac_fh[19:20, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[19:20, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[19:20, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_19[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_19[2]
    CPCT_cov_current = CPCT_cov_current + outputs_19[5]
    P_current = outputs_19[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_19[7]
    kalman_diff = kalman_diff + outputs_19[8]
    kalman_threshold = kalman_threshold + outputs_19[9]

    # === TIMESTEP 20 ===
    outputs_20 = self.model.forward(h_current,
                                    y[20:21, :, :],
                                    jac_fh[20:21, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[20:21, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[20:21, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_20[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_20[2]
    CPCT_cov_current = CPCT_cov_current + outputs_20[5]
    P_current = outputs_20[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_20[7]
    kalman_diff = kalman_diff + outputs_20[8]
    kalman_threshold = kalman_threshold + outputs_20[9]

    # === TIMESTEP 21 ===
    outputs_21 = self.model.forward(h_current,
                                    y[21:22, :, :],
                                    jac_fh[21:22, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[21:22, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[21:22, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_21[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_21[2]
    CPCT_cov_current = CPCT_cov_current + outputs_21[5]
    P_current = outputs_21[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_21[7]
    kalman_diff = kalman_diff + outputs_21[8]
    kalman_threshold = kalman_threshold + outputs_21[9]

    # === TIMESTEP 22 ===
    outputs_22 = self.model.forward(h_current,
                                    y[22:23, :, :],
                                    jac_fh[22:23, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[22:23, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[22:23, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_22[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_22[2]
    CPCT_cov_current = CPCT_cov_current + outputs_22[5]
    P_current = outputs_22[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_22[7]
    kalman_diff = kalman_diff + outputs_22[8]
    kalman_threshold = kalman_threshold + outputs_22[9]

    # === TIMESTEP 23 ===
    outputs_23 = self.model.forward(h_current,
                                    y[23:24, :, :],
                                    jac_fh[23:24, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[23:24, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[23:24, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_23[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_23[2]
    CPCT_cov_current = CPCT_cov_current + outputs_23[5]
    P_current = outputs_23[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_23[7]
    kalman_diff = kalman_diff + outputs_23[8]
    kalman_threshold = kalman_threshold + outputs_23[9]

    # === TIMESTEP 24 ===
    outputs_24 = self.model.forward(h_current,
                                    y[24:25, :, :],
                                    jac_fh[24:25, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[24:25, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[24:25, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_24[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_24[2]
    CPCT_cov_current = CPCT_cov_current + outputs_24[5]
    P_current = outputs_24[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_24[7]
    kalman_diff = kalman_diff + outputs_24[8]
    kalman_threshold = kalman_threshold + outputs_24[9]

    # === TIMESTEP 25 ===
    outputs_25 = self.model.forward(h_current,
                                    y[25:26, :, :],
                                    jac_fh[25:26, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[25:26, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[25:26, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_25[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_25[2]
    CPCT_cov_current = CPCT_cov_current + outputs_25[5]
    P_current = outputs_25[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_25[7]
    kalman_diff = kalman_diff + outputs_25[8]
    kalman_threshold = kalman_threshold + outputs_25[9]

    # === TIMESTEP 26 ===
    outputs_26 = self.model.forward(h_current,
                                    y[26:27, :, :],
                                    jac_fh[26:27, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[26:27, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[26:27, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_26[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_26[2]
    CPCT_cov_current = CPCT_cov_current + outputs_26[5]
    P_current = outputs_26[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_26[7]
    kalman_diff = kalman_diff + outputs_26[8]
    kalman_threshold = kalman_threshold + outputs_26[9]

    # === TIMESTEP 27 ===
    outputs_27 = self.model.forward(h_current,
                                    y[27:28, :, :],
                                    jac_fh[27:28, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[27:28, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[27:28, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_27[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_27[2]
    CPCT_cov_current = CPCT_cov_current + outputs_27[5]
    P_current = outputs_27[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_27[7]
    kalman_diff = kalman_diff + outputs_27[8]
    kalman_threshold = kalman_threshold + outputs_27[9]

    # === TIMESTEP 28 ===
    outputs_28 = self.model.forward(h_current,
                                    y[28:29, :, :],
                                    jac_fh[28:29, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[28:29, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[28:29, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_28[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_28[2]
    CPCT_cov_current = CPCT_cov_current + outputs_28[5]
    P_current = outputs_28[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_28[7]
    kalman_diff = kalman_diff + outputs_28[8]
    kalman_threshold = kalman_threshold + outputs_28[9]

    # === TIMESTEP 29 ===
    outputs_29 = self.model.forward(h_current,
                                    y[29:30, :, :],
                                    jac_fh[29:30, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[29:30, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[29:30, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_29[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_29[2]
    CPCT_cov_current = CPCT_cov_current + outputs_29[5]
    P_current = outputs_29[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_29[7]
    kalman_diff = kalman_diff + outputs_29[8]
    kalman_threshold = kalman_threshold + outputs_29[9]

    # === TIMESTEP 30 ===
    outputs_30 = self.model.forward(h_current,
                                    y[30:31, :, :],
                                    jac_fh[30:31, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[30:31, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[30:31, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_30[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_30[2]
    CPCT_cov_current = CPCT_cov_current + outputs_30[5]
    P_current = outputs_30[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_30[7]
    kalman_diff = kalman_diff + outputs_30[8]
    kalman_threshold = kalman_threshold + outputs_30[9]

    # === TIMESTEP 31 ===
    outputs_31 = self.model.forward(h_current,
                                    y[31:32, :, :],
                                    jac_fh[31:32, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[31:32, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[31:32, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_31[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_31[2]
    CPCT_cov_current = CPCT_cov_current + outputs_31[5]
    P_current = outputs_31[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_31[7]
    kalman_diff = kalman_diff + outputs_31[8]
    kalman_threshold = kalman_threshold + outputs_31[9]

    # === TIMESTEP 32 ===
    outputs_32 = self.model.forward(h_current,
                                    y[32:33, :, :],
                                    jac_fh[32:33, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[32:33, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[32:33, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_32[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_32[2]
    CPCT_cov_current = CPCT_cov_current + outputs_32[5]
    P_current = outputs_32[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_32[7]
    kalman_diff = kalman_diff + outputs_32[8]
    kalman_threshold = kalman_threshold + outputs_32[9]

    # === TIMESTEP 33 ===
    outputs_33 = self.model.forward(h_current,
                                    y[33:34, :, :],
                                    jac_fh[33:34, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[33:34, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[33:34, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_33[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_33[2]
    CPCT_cov_current = CPCT_cov_current + outputs_33[5]
    P_current = outputs_33[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_33[7]
    kalman_diff = kalman_diff + outputs_33[8]
    kalman_threshold = kalman_threshold + outputs_33[9]

    # === TIMESTEP 34 ===
    outputs_34 = self.model.forward(h_current,
                                    y[34:35, :, :],
                                    jac_fh[34:35, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[34:35, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[34:35, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_34[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_34[2]
    CPCT_cov_current = CPCT_cov_current + outputs_34[5]
    P_current = outputs_34[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_34[7]
    kalman_diff = kalman_diff + outputs_34[8]
    kalman_threshold = kalman_threshold + outputs_34[9]

    # === TIMESTEP 35 ===
    outputs_35 = self.model.forward(h_current,
                                    y[35:36, :, :],
                                    jac_fh[35:36, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[35:36, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[35:36, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_35[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_35[2]
    CPCT_cov_current = CPCT_cov_current + outputs_35[5]
    P_current = outputs_35[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_35[7]
    kalman_diff = kalman_diff + outputs_35[8]
    kalman_threshold = kalman_threshold + outputs_35[9]

    # === TIMESTEP 36 ===
    outputs_36 = self.model.forward(h_current,
                                    y[36:37, :, :],
                                    jac_fh[36:37, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[36:37, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[36:37, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_36[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_36[2]
    CPCT_cov_current = CPCT_cov_current + outputs_36[5]
    P_current = outputs_36[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_36[7]
    kalman_diff = kalman_diff + outputs_36[8]
    kalman_threshold = kalman_threshold + outputs_36[9]

    # === TIMESTEP 37 ===
    outputs_37 = self.model.forward(h_current,
                                    y[37:38, :, :],
                                    jac_fh[37:38, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[37:38, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[37:38, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_37[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_37[2]
    CPCT_cov_current = CPCT_cov_current + outputs_37[5]
    P_current = outputs_37[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_37[7]
    kalman_diff = kalman_diff + outputs_37[8]
    kalman_threshold = kalman_threshold + outputs_37[9]

    # === TIMESTEP 38 ===
    outputs_38 = self.model.forward(h_current,
                                    y[38:39, :, :],
                                    jac_fh[38:39, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[38:39, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[38:39, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_38[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_38[2]
    CPCT_cov_current = CPCT_cov_current + outputs_38[5]
    P_current = outputs_38[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_38[7]
    kalman_diff = kalman_diff + outputs_38[8]
    kalman_threshold = kalman_threshold + outputs_38[9]

    # === TIMESTEP 39 ===
    outputs_39 = self.model.forward(h_current,
                                    y[39:40, :, :],
                                    jac_fh[39:40, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[39:40, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[39:40, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_39[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_39[2]
    CPCT_cov_current = CPCT_cov_current + outputs_39[5]
    P_current = outputs_39[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_39[7]
    kalman_diff = kalman_diff + outputs_39[8]
    kalman_threshold = kalman_threshold + outputs_39[9]

    # === TIMESTEP 40 ===
    outputs_40 = self.model.forward(h_current,
                                    y[40:41, :, :],
                                    jac_fh[40:41, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[40:41, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[40:41, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_40[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_40[2]
    CPCT_cov_current = CPCT_cov_current + outputs_40[5]
    P_current = outputs_40[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_40[7]
    kalman_diff = kalman_diff + outputs_40[8]
    kalman_threshold = kalman_threshold + outputs_40[9]

    # === TIMESTEP 41 ===
    outputs_41 = self.model.forward(h_current,
                                    y[41:42, :, :],
                                    jac_fh[41:42, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[41:42, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[41:42, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_41[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_41[2]
    CPCT_cov_current = CPCT_cov_current + outputs_41[5]
    P_current = outputs_41[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_41[7]
    kalman_diff = kalman_diff + outputs_41[8]
    kalman_threshold = kalman_threshold + outputs_41[9]

    # === TIMESTEP 42 ===
    outputs_42 = self.model.forward(h_current,
                                    y[42:43, :, :],
                                    jac_fh[42:43, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[42:43, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[42:43, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_42[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_42[2]
    CPCT_cov_current = CPCT_cov_current + outputs_42[5]
    P_current = outputs_42[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_42[7]
    kalman_diff = kalman_diff + outputs_42[8]
    kalman_threshold = kalman_threshold + outputs_42[9]

    # === TIMESTEP 43 ===
    outputs_43 = self.model.forward(h_current,
                                    y[43:44, :, :],
                                    jac_fh[43:44, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[43:44, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[43:44, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_43[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_43[2]
    CPCT_cov_current = CPCT_cov_current + outputs_43[5]
    P_current = outputs_43[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_43[7]
    kalman_diff = kalman_diff + outputs_43[8]
    kalman_threshold = kalman_threshold + outputs_43[9]

    # === TIMESTEP 44 ===
    outputs_44 = self.model.forward(h_current,
                                    y[44:45, :, :],
                                    jac_fh[44:45, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[44:45, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[44:45, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_44[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_44[2]
    CPCT_cov_current = CPCT_cov_current + outputs_44[5]
    P_current = outputs_44[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_44[7]
    kalman_diff = kalman_diff + outputs_43[8]
    kalman_threshold = kalman_threshold + outputs_43[9]

    # === TIMESTEP 45 ===
    outputs_45 = self.model.forward(h_current,
                                    y[45:46, :, :],
                                    jac_fh[45:46, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[45:46, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[45:46, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_45[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_45[2]
    CPCT_cov_current = CPCT_cov_current + outputs_45[5]
    P_current = outputs_45[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_45[7]
    kalman_diff = kalman_diff + outputs_45[8]
    kalman_threshold = kalman_threshold + outputs_45[9]

    # === TIMESTEP 46 ===
    outputs_46 = self.model.forward(h_current,
                                    y[46:47, :, :],
                                    jac_fh[46:47, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[46:47, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[46:47, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_46[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_46[2]
    CPCT_cov_current = CPCT_cov_current + outputs_46[5]
    P_current = outputs_46[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_46[7]
    kalman_diff = kalman_diff + outputs_46[8]
    kalman_threshold = kalman_threshold + outputs_46[9]

    # === TIMESTEP 47 ===
    outputs_47 = self.model.forward(h_current,
                                    y[47:48, :, :],
                                    jac_fh[47:48, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[47:48, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[47:48, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_47[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_47[2]
    CPCT_cov_current = CPCT_cov_current + outputs_47[5]
    P_current = outputs_47[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_47[7]
    kalman_diff = kalman_diff + outputs_47[8]
    kalman_threshold = kalman_threshold + outputs_47[9]

    # === TIMESTEP 48 ===
    outputs_48 = self.model.forward(h_current,
                                    y[48:49, :, :],
                                    jac_fh[48:49, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[48:49, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[48:49, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_48[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_48[2]
    CPCT_cov_current = CPCT_cov_current + outputs_48[5]
    P_current = outputs_48[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_48[7]
    kalman_diff = kalman_diff + outputs_48[8]
    kalman_threshold = kalman_threshold + outputs_48[9]

    # === TIMESTEP 49 ===
    outputs_49 = self.model.forward(h_current,
                                    y[49:50, :, :],
                                    jac_fh[49:50, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[49:50, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[49:50, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_49[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_49[2]
    CPCT_cov_current = CPCT_cov_current + outputs_49[5]
    P_current = outputs_49[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_49[7]
    kalman_diff = kalman_diff + outputs_49[8]
    kalman_threshold = kalman_threshold + outputs_49[9]

    # === TIMESTEP 50 ===
    outputs_50 = self.model.forward(h_current,
                                    y[50:51, :, :],
                                    jac_fh[50:51, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[50:51, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[50:51, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_50[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_50[2]
    CPCT_cov_current = CPCT_cov_current + outputs_50[5]
    P_current = outputs_50[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_50[7]
    kalman_diff = kalman_diff + outputs_50[8]
    kalman_threshold = kalman_threshold + outputs_50[9]

    # === TIMESTEP 51 ===
    outputs_51 = self.model.forward(h_current,
                                    y[51:52, :, :],
                                    jac_fh[51:52, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[51:52, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[51:52, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_51[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_51[2]
    CPCT_cov_current = CPCT_cov_current + outputs_51[5]
    P_current = outputs_51[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_51[7]
    kalman_diff = kalman_diff + outputs_51[8]
    kalman_threshold = kalman_threshold + outputs_51[9]

    # === TIMESTEP 52 ===
    outputs_52 = self.model.forward(h_current,
                                    y[52:53, :, :],
                                    jac_fh[52:53, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[52:53, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[52:53, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_52[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_52[2]
    CPCT_cov_current = CPCT_cov_current + outputs_52[5]
    P_current = outputs_52[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_52[7]
    kalman_diff = kalman_diff + outputs_52[8]
    kalman_threshold = kalman_threshold + outputs_52[9]

    # === TIMESTEP 53 ===
    outputs_53 = self.model.forward(h_current,
                                    y[53:54, :, :],
                                    jac_fh[53:54, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[53:54, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[53:54, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_53[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_53[2]
    CPCT_cov_current = CPCT_cov_current + outputs_53[5]
    P_current = outputs_53[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_53[7]
    kalman_diff = kalman_diff + outputs_53[8]
    kalman_threshold = kalman_threshold + outputs_53[9]

    # === TIMESTEP 54 ===
    outputs_54 = self.model.forward(h_current,
                                    y[54:55, :, :],
                                    jac_fh[54:55, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[54:55, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[54:55, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_54[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_54[2]
    CPCT_cov_current = CPCT_cov_current + outputs_54[5]
    P_current = outputs_54[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_54[7]
    kalman_diff = kalman_diff + outputs_54[8]
    kalman_threshold = kalman_threshold + outputs_54[9]

    # === TIMESTEP 55 ===
    outputs_55 = self.model.forward(h_current,
                                    y[55:56, :, :],
                                    jac_fh[55:56, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[55:56, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[55:56, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_55[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_55[2]
    CPCT_cov_current = CPCT_cov_current + outputs_55[5]
    P_current = outputs_55[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_55[7]
    kalman_diff = kalman_diff + outputs_55[8]
    kalman_threshold = kalman_threshold + outputs_55[9]

    # === TIMESTEP 56 ===
    outputs_56 = self.model.forward(h_current,
                                    y[56:57, :, :],
                                    jac_fh[56:57, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[56:57, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[56:57, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_56[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_56[2]
    CPCT_cov_current = CPCT_cov_current + outputs_56[5]
    P_current = outputs_56[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_56[7]
    kalman_diff = kalman_diff + outputs_56[8]
    kalman_threshold = kalman_threshold + outputs_56[9]

    # === TIMESTEP 57 ===
    outputs_57 = self.model.forward(h_current,
                                    y[57:58, :, :],
                                    jac_fh[57:58, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[57:58, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[57:58, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_57[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_57[2]
    CPCT_cov_current = CPCT_cov_current + outputs_57[5]
    P_current = outputs_57[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_57[7]
    kalman_diff = kalman_diff + outputs_57[8]
    kalman_threshold = kalman_threshold + outputs_57[9]

    # === TIMESTEP 58 ===
    outputs_58 = self.model.forward(h_current,
                                    y[58:59, :, :],
                                    jac_fh[58:59, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[58:59, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[58:59, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_58[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_58[2]
    CPCT_cov_current = CPCT_cov_current + outputs_58[5]
    P_current = outputs_58[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_58[7]
    kalman_diff = kalman_diff + outputs_58[8]
    kalman_threshold = kalman_threshold + outputs_58[9]

    # === TIMESTEP 59 ===
    outputs_59 = self.model.forward(h_current,
                                    y[59:60, :, :],
                                    jac_fh[59:60, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[59:60, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[59:60, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_59[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_59[2]
    CPCT_cov_current = CPCT_cov_current + outputs_59[5]
    P_current = outputs_59[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_59[7]
    kalman_diff = kalman_diff + outputs_59[8]
    kalman_threshold = kalman_threshold + outputs_59[9]

    # === TIMESTEP 60 ===
    outputs_60 = self.model.forward(h_current,
                                    y[60:61, :, :],
                                    jac_fh[60:61, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[60:61, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[60:61, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_60[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_60[2]
    CPCT_cov_current = CPCT_cov_current + outputs_60[5]
    P_current = outputs_60[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_60[7]
    kalman_diff = kalman_diff + outputs_60[8]
    kalman_threshold = kalman_threshold + outputs_60[9]

    # === TIMESTEP 61 ===
    outputs_61 = self.model.forward(h_current,
                                    y[61:62, :, :],
                                    jac_fh[61:62, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[61:62, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[61:62, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_61[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_61[2]
    CPCT_cov_current = CPCT_cov_current + outputs_61[5]
    P_current = outputs_61[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_61[7]
    kalman_diff = kalman_diff + outputs_61[8]
    kalman_threshold = kalman_threshold + outputs_61[9]

    # === TIMESTEP 62 ===
    outputs_62 = self.model.forward(h_current,
                                    y[62:63, :, :],
                                    jac_fh[62:63, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[62:63, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[62:63, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_62[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_62[2]
    CPCT_cov_current = CPCT_cov_current + outputs_62[5]
    P_current = outputs_62[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_62[7]
    kalman_diff = kalman_diff + outputs_62[8]
    kalman_threshold = kalman_threshold + outputs_62[9]

    # === TIMESTEP 63 ===
    outputs_63 = self.model.forward(h_current,
                                    y[63:64, :, :],
                                    jac_fh[63:64, :, :].reshape(1, self.SD, self.SD),
                                    jac_Ch[63:64, :, :].reshape(1, self.MD, self.SD),
                                    P_current,
                                    Kt[63:64, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_63[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_63[2]
    CPCT_cov_current = CPCT_cov_current + outputs_63[5]
    P_current = outputs_63[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_63[7]
    kalman_diff = kalman_diff + outputs_63[8]
    kalman_threshold = kalman_threshold + outputs_63[9]

    h_current = torch.cat([h_current, nonce_h], dim=2)
    P_current = torch.cat([P_current, nonce_P], dim=2)
    delta_y_current = torch.cat([delta_y_current, nonce_dy], dim=2)
    CPCT_cov_current = torch.cat([CPCT_cov_current, nonce_CPCT_cov], dim=2)
    KCR_status = torch.cat([KCR_status, nonce_KCR_status], dim=2)
    kalman_diff = torch.cat([kalman_diff, nonce_kalman_diff], dim=1)
    kalman_threshold = torch.cat([kalman_threshold, nonce_kalman_threshold], dim=1)

    return h_current, P_current, delta_y_current, CPCT_cov_current, KCR_status, kalman_diff, kalman_threshold

forward8

forward8(h, P, delta_y, CPCT_cov, y, jac_fh, jac_Ch, Kt, KCR_status, nonce_h, nonce_P, nonce_dy, nonce_CPCT_cov, nonce_KCR_status, nonce_kalman_diff, nonce_kalman_threshold)

Forward pass with exactly 8 timesteps (EZKL-compatible)

Parameters:

Name Type Description Default
h

Initial hidden state [1, 1, SD]

required
P

Initial covariance matrix [1, SD, SD]

required
delta_y

Initial residual [1, 1, is_r]

required
CPCT_cov

Initial residual covariance [1, is_r, is_r]

required
y

Observations for 8 timesteps [8, obs_dim]

required
jac_fh

Jacobian fh for 8 timesteps [8, ...]

required
jac_Ch

Jacobian Ch for 8 timesteps [8, ...]

required
Kt

Kalman gain for 8 timesteps [8, ...]

required
Source code in src/PredictionWrapper.py
def forward8(self, h, P, delta_y, CPCT_cov, y, jac_fh, jac_Ch, Kt, KCR_status,
             nonce_h,nonce_P,nonce_dy,nonce_CPCT_cov,nonce_KCR_status,nonce_kalman_diff,nonce_kalman_threshold,):
    """
    Forward pass with exactly 8 timesteps (EZKL-compatible)

    Args:
        h: Initial hidden state [1, 1, SD]
        P: Initial covariance matrix [1, SD, SD]
        delta_y: Initial residual [1, 1, is_r]
        CPCT_cov: Initial residual covariance [1, is_r, is_r]
        y: Observations for 8 timesteps [8, obs_dim]
        jac_fh: Jacobian fh for 8 timesteps [8, ...]
        jac_Ch: Jacobian Ch for 8 timesteps [8, ...]
        Kt: Kalman gain for 8 timesteps [8, ...]
    """

    h_current = h[0:1, :, :self.SD].reshape(1, 1, self.SD)
    P_current = P[0:1, :, :self.SD].reshape(1, self.SD, self.SD)

    delta_y_current = delta_y.reshape(1, 1, self.MD+1)
    CPCT_cov_current = CPCT_cov.reshape(1, self.MD, self.MD+1)

    delta_y_current = delta_y_current[0:1, :, :self.MD].reshape(1, 1, self.MD)
    CPCT_cov_current = CPCT_cov_current[0:1, :, :self.MD].reshape(1, self.MD, self.MD)
    y = y[:, :, :self.MD]
    jac_fh = jac_fh[:, :, :self.SD]
    jac_Ch = jac_Ch[:, :, :self.MD]
    Kt = Kt[:, :, :self.SD]
    KCR_status = KCR_status[:,:,0:1].reshape(1,1,1)

    nonce_h = nonce_h.reshape((1, 1, 1))
    nonce_dy = nonce_dy.reshape((1, 1, 1))
    nonce_KCR_status = nonce_KCR_status.reshape((1, 1, 1))
    nonce_P = nonce_P.reshape((1, self.SD, 1))
    nonce_CPCT_cov = nonce_CPCT_cov.reshape((1, self.MD, 1))
    nonce_kalman_diff = nonce_kalman_diff.reshape((1, 1, self.SD))
    nonce_kalman_threshold = nonce_kalman_threshold.reshape((1, 1, self.SD))

    assert h_current.shape[2] == self.SD
    assert nonce_h.shape == (1, 1, 1)
    assert nonce_KCR_status.shape == (1, 1, 1)
    assert nonce_dy.shape == (1, 1, 1)
    assert nonce_P.shape == (1, self.SD, 1)
    assert nonce_CPCT_cov.shape == (1, self.MD, 1)
    assert nonce_kalman_diff.shape == (1, 1, self.SD)
    assert nonce_kalman_threshold.shape == (1, 1, self.SD)

    outputs_0 = self.model.forward(h_current,
                                   y[0:1, :, :],
                                   jac_fh[0:1, :, :].reshape(1, self.SD, self.SD),
                                   jac_Ch[0:1, :, :].reshape(1, self.MD, self.SD),
                                   P_current,
                                   Kt[0:1, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_0[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_0[2]
    CPCT_cov_current = CPCT_cov_current + outputs_0[5]
    P_current = outputs_0[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status*outputs_0[7]
    kalman_diff = outputs_0[8]
    kalman_threshold = outputs_0[9]

    # === TIMESTEP 1 ===
    outputs_1 = self.model.forward(h_current,
                                   y[1:2, :, :],
                                   jac_fh[1:2, :, :].reshape(1, self.SD, self.SD),
                                   jac_Ch[1:2, :, :].reshape(1, self.MD, self.SD),
                                   P_current,
                                   Kt[1:2, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_1[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_1[2]
    CPCT_cov_current = CPCT_cov_current + outputs_1[5]
    P_current = outputs_1[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_1[7]
    kalman_diff = kalman_diff + outputs_1[8]
    kalman_threshold = kalman_threshold + outputs_1[9]

    # === TIMESTEP 2 ===
    outputs_2 = self.model.forward(h_current,
                                   y[2:3, :, :],
                                   jac_fh[2:3, :, :].reshape(1, self.SD, self.SD),
                                   jac_Ch[2:3, :, :].reshape(1, self.MD, self.SD),
                                   P_current,
                                   Kt[2:3, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_2[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_2[2]
    CPCT_cov_current = CPCT_cov_current + outputs_2[5]
    P_current = outputs_2[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_2[7]
    kalman_diff = kalman_diff + outputs_2[8]
    kalman_threshold = kalman_threshold + outputs_2[9]

    # === TIMESTEP 2 ===
    outputs_3 = self.model.forward(h_current,
                                   y[3:4, :, :],
                                   jac_fh[3:4, :, :].reshape(1, self.SD, self.SD),
                                   jac_Ch[3:4, :, :].reshape(1, self.MD, self.SD),
                                   P_current,
                                   Kt[3:4, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_3[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_3[2]
    CPCT_cov_current = CPCT_cov_current + outputs_3[5]
    P_current = outputs_3[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status * outputs_3[7]
    kalman_diff = kalman_diff + outputs_3[8]
    kalman_threshold = kalman_threshold + outputs_3[9]

    # === TIMESTEP 4 ===
    outputs_4 = self.model.forward(h_current,
                                   y[4:5, :, :],
                                   jac_fh[4:5, :, :].reshape(1, self.SD, self.SD),
                                   jac_Ch[4:5, :, :].reshape(1, self.MD, self.SD),
                                   P_current,
                                   Kt[4:5, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_4[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_4[2]
    CPCT_cov_current = CPCT_cov_current + outputs_4[5]
    P_current = outputs_4[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status*outputs_4[7]
    kalman_diff = kalman_diff + outputs_4[8]
    kalman_threshold = kalman_threshold + outputs_4[9]

    # === TIMESTEP 5 ===
    outputs_5 = self.model.forward(h_current,
                                   y[5:6, :, :],
                                   jac_fh[5:6, :, :].reshape(1, self.SD, self.SD),
                                   jac_Ch[5:6, :, :].reshape(1, self.MD, self.SD),
                                   P_current,
                                   Kt[5:6, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_5[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_5[2]
    CPCT_cov_current = CPCT_cov_current + outputs_5[5]
    P_current = outputs_5[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status*outputs_5[7]
    kalman_diff = kalman_diff + outputs_5[8]
    kalman_threshold = kalman_threshold + outputs_5[9]

    # === TIMESTEP 6 ===
    outputs_6 = self.model.forward(h_current,
                                   y[6:7, :, :],
                                   jac_fh[6:7, :, :].reshape(1, self.SD, self.SD),
                                   jac_Ch[6:7, :, :].reshape(1, self.MD, self.SD),
                                   P_current,
                                   Kt[6:7, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_6[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_6[2]
    CPCT_cov_current = CPCT_cov_current + outputs_6[5]
    P_current = outputs_6[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status*outputs_6[7]
    kalman_diff = kalman_diff + outputs_6[8]
    kalman_threshold = kalman_threshold + outputs_6[9]

    # === TIMESTEP 7 ===
    outputs_7 = self.model.forward(h_current,
                                   y[7:8, :, :],
                                   jac_fh[7:8, :, :].reshape(1, self.SD, self.SD),
                                   jac_Ch[7:8, :, :].reshape(1, self.MD, self.SD),
                                   P_current,
                                   Kt[7:8, :, :].reshape(1, self.MD, self.SD))
    h_current = outputs_7[0].reshape(1, 1, self.SD)
    delta_y_current = delta_y_current + outputs_7[2]
    CPCT_cov_current = CPCT_cov_current + outputs_7[5]
    P_current = outputs_7[6].reshape(1, self.SD, self.SD)
    KCR_status = KCR_status*outputs_7[7]
    kalman_diff = kalman_diff + outputs_6[8]
    kalman_threshold = kalman_threshold + outputs_6[9]

    h_current = torch.cat([h_current, nonce_h], dim=2)
    P_current = torch.cat([P_current, nonce_P], dim=2)
    delta_y_current = torch.cat([delta_y_current, nonce_dy], dim=2)
    CPCT_cov_current = torch.cat([CPCT_cov_current, nonce_CPCT_cov], dim=2)
    KCR_status = torch.cat([KCR_status, nonce_KCR_status], dim=2)
    kalman_diff = torch.cat([kalman_diff, nonce_kalman_diff], dim=1)
    kalman_threshold = torch.cat([kalman_threshold, nonce_kalman_threshold], dim=1)

    return h_current, P_current, delta_y_current, CPCT_cov_current, KCR_status, kalman_diff, kalman_threshold

forward_Dloop

forward_Dloop(h, P, delta_y, CPCT_cov)

Dynamically unrolled EKF loop over D timesteps. Used during non-ZKP training and evaluation; not compiled into ONNX.

Iterates from period_start to period_start + D, accumulating the DVAL-summed residual (delta_y) and innovation covariance (CPCT_cov) across all timesteps. The Jacobians and Kalman gains must be precomputed via forward_yield_jacobians before calling this method.

Parameters:

Name Type Description Default
h Tensor

Initial hidden state (1, 1, SD).

required
P Tensor

Initial state error covariance (1, SD, SD).

required
delta_y Tensor

Initial (zero) residual accumulator (1, 1, MD).

required
CPCT_cov Tensor

Initial (zero) covariance accumulator (1, MD, MD).

required

Returns:

Type Description

Tuple[torch.Tensor, ...]: - h_current: Updated hidden state after D steps (1, 1, SD). - P: Updated state covariance after D steps (1, SD, SD). - delta_y_tensor: DVAL-summed innovation vector (1, 1, MD). - CPCT_cov_tensor: DVAL-summed innovation covariance (1, MD, MD). - KCR_status_check: Product of per-step Kalman check results (scalar).

Source code in src/PredictionWrapper.py
def forward_Dloop(self, h, P, delta_y, CPCT_cov, ):
    """
    Dynamically unrolled EKF loop over D timesteps. Used during non-ZKP training
    and evaluation; not compiled into ONNX.

    Iterates from period_start to period_start + D, accumulating the DVAL-summed
    residual (delta_y) and innovation covariance (CPCT_cov) across all timesteps.
    The Jacobians and Kalman gains must be precomputed via forward_yield_jacobians
    before calling this method.

    Args:
        h (torch.Tensor): Initial hidden state (1, 1, SD).
        P (torch.Tensor): Initial state error covariance (1, SD, SD).
        delta_y (torch.Tensor): Initial (zero) residual accumulator (1, 1, MD).
        CPCT_cov (torch.Tensor): Initial (zero) covariance accumulator (1, MD, MD).

    Returns:
        Tuple[torch.Tensor, ...]:
            - h_current: Updated hidden state after D steps (1, 1, SD).
            - P: Updated state covariance after D steps (1, SD, SD).
            - delta_y_tensor: DVAL-summed innovation vector (1, 1, MD).
            - CPCT_cov_tensor: DVAL-summed innovation covariance (1, MD, MD).
            - KCR_status_check: Product of per-step Kalman check results (scalar).
    """
    h_current = h.clone()

    delta_y_tensor = delta_y.reshape(1, 1, self.model.is_r)  # torch.zeros(1, 1, self.model.is_r, device=h.device)
    CPCT_cov_tensor = CPCT_cov.reshape(1, self.model.is_r,self.model.is_r)  # torch.zeros(1, 1, self.model.is_r, self.model.is_r, device=h.device)
    cov_h_tensor = torch.zeros(1, self.D, self.model.is_f, self.model.is_f, device=h.device)
    cov_r_tensor = torch.zeros(1, self.D, self.model.is_r, self.model.is_r, device=h.device)
    KCR_status_check = torch.tensor([1.0])

    for i in range(self.D):
        start = i + self.period_start
        end = start + 1

        y = self.ht_test[start:end, :, self.SD:self.SD + self.MD].reshape(1, 1, self.MD)

        outputs = self.model.forward(h_current, y, self.jac_fh[i], self.jac_Ch[i], P, self.Kt[i])
        # outputs = self.model.forward(h, y, self.jac_fh[i], self.jac_Ch[i], self.P[i], self.Kt[i])

        h_current = outputs[0].reshape(1, 1, self.SD)  # Update hidden state
        delta_y_tensor = delta_y_tensor + outputs[2]
        cov_h_tensor = cov_h_tensor + outputs[3]
        cov_r_tensor = cov_r_tensor + outputs[4]
        CPCT_cov_tensor = CPCT_cov_tensor + outputs[5]
        P = outputs[6].reshape(1, self.SD, self.SD)
        KCR_status_check = KCR_status_check * outputs[7]

    return h_current, P, delta_y_tensor, CPCT_cov_tensor, KCR_status_check  # , CPCT_cov_corr_tensor

forward_yield_jacobians

forward_yield_jacobians(h)

Runs the EKF linearization pass over D timesteps to populate per-step Jacobians and Kalman gains stored on the instance.

Calls model.forward_yield_jacobians at each step starting from period_start, building lists self.jac_fh, self.jac_Ch, self.P, and self.Kt. These are consumed by forward_Dloop and the fixed-length forward methods.

Parameters:

Name Type Description Default
h Tensor

Initial hidden state (1, 1, SD).

required
Source code in src/PredictionWrapper.py
def forward_yield_jacobians(self,h,):
    """
    Runs the EKF linearization pass over D timesteps to populate per-step
    Jacobians and Kalman gains stored on the instance.

    Calls model.forward_yield_jacobians at each step starting from period_start,
    building lists self.jac_fh, self.jac_Ch, self.P, and self.Kt. These are
    consumed by forward_Dloop and the fixed-length forward methods.

    Args:
        h (torch.Tensor): Initial hidden state (1, 1, SD).
    """
    self.jac_Ch = []
    self.jac_fh = []
    self.P = []
    self.Kt = []

    forecast_horizon = self.D
    for i in range(forecast_horizon):
        start = i + self.period_start
        end = start + 1

        y = self.ht_test[start:end, :, self.SD:self.SD + self.MD].reshape(1, 1, self.MD)

        h,jac_fh,jac_Ch,P,Kt = self.model.forward_yield_jacobians(h, y)
        self.jac_fh.append(jac_fh)
        self.jac_Ch.append(jac_Ch)
        self.P.append(P)
        # print(start,end,torch.linalg.norm(Kt),torch.linalg.norm(jac_Ch),)
        self.Kt.append(Kt)