Skip to content

Gramian Matrix

The Gramian

API Reference

ondil.gram.init_forget_vector

init_forget_vector(forget: float, size: int) -> np.ndarray

Initialise an exponentially discounted vector of weights.

Recursively initialise a vector of exponentially discounted weights of size N.

The weight for \(n\)-th observation is defined as \((1 - \text{forget})^{(N - n)}\)

Note that this functions assumes that the first observation is the oldest observation and the last observation is the newest observation. This is in line with the standard pandas way of sorting pd.DataFrames with Datetime-indices.

Numba

This function uses numba just-in-time-compilation.

Parameters:

  • forget (float) –

    Forget factor.

  • size (int) –

    Length of the output vector.

Returns:

  • ndarray

    np.ndarray: Vector of exponentially discounted weights.

ondil.gram.init_gram

init_gram(
    X: ndarray, w: ndarray, forget: float = 0
) -> np.ndarray

Initialise the Gramian Matrix.

The Gramian Matrix is defined as $$ G = X^T \Gamma WX $$ where \(X\) is the design matrix, \(W\) is a diagonal, user-defined weight matrix, \(\Gamma\) is a diagonal matrix of exponentially discounting weights.

Numba

This function uses numba just-in-time-compilation.

Parameters:

  • X (ndarray) –

    Design matrix \(X\)

  • w (ndarray) –

    Weights vector

  • forget (float, default: 0 ) –

    Forget factor. Defaults to 0.

Returns:

  • ndarray

    np.ndarray: Gramian Matrix.

ondil.gram.init_y_gram

init_y_gram(
    X: ndarray, y: ndarray, w: ndarray, forget: float = 0
) -> np.ndarray

Initialise the y-Gramian Matrix.

The Gramian Matrix is defined as $$ H = X^T \Gamma WY $$ where \(X\) is the design matrix, \(Y\) is the response variable, \(W\) is a diagonal, user-defined weight matrix, \(\Gamma\) is a diagonal matrix of exponentially discounting weights.

Numba

This function uses numba just-in-time-compilation.

Parameters:

  • X (ndarray) –

    Design matrix \(X\)

  • y (ndarray) –

    Response variable \(Y\)

  • w (ndarray) –

    Weights vector

  • forget (float, default: 0 ) –

    Forget factor. Defaults to 0.

Returns:

  • ndarray

    np.ndarray: y-Gramian Matrix.

ondil.gram.init_inverted_gram

init_inverted_gram(
    X: ndarray, w: ndarray, forget: float = 0
) -> np.ndarray

Initialise the inverted Gramian Matrix.

The inverted Gramian Matrix is defined as $$ G = (X^T \Gamma WX)^{-1} $$ where \(X\) is the design matrix, \(W\) is a diagonal, user-defined weight matrix, \(\Gamma\) is a diagonal matrix of exponentially discounting weights.

Numba

This function uses numba just-in-time-compilation.

Parameters:

  • X (ndarray) –

    Design matrix \(X\)

  • w (ndarray) –

    Weights vector

  • forget (float, default: 0 ) –

    Forget factor. Defaults to 0.

Returns:

  • ndarray

    np.ndarray: Gramian Matrix.

Raises:

  • ValueError

    If the matrix is not invertible (if rank(X.T @ X) < X.shape[0]).

ondil.gram.update_gram

update_gram(
    gram: ndarray,
    X: ndarray,
    forget: float = 0,
    w: float = 1,
) -> np.ndarray

Update the Gramian Matrix.

Numba

This function uses numba just-in-time-compilation.

Parameters:

  • gram (ndarray) –

    Gramian Matrix

  • X (ndarray) –

    New observations for \(X\)

  • forget (float, default: 0 ) –

    Forget factor. Defaults to 0.

  • w (float, default: 1 ) –

    Weights for the new observations. Defaults to 1.

Returns:

  • ndarray

    np.ndarray: Updated Gramian Matrix.

ondil.gram.update_y_gram

update_y_gram(
    gram: ndarray,
    X: ndarray,
    y: ndarray,
    forget: float = 0,
    w: float = 1,
) -> np.ndarray

Update the Y-Gramian Matrix.

Numba

This function uses numba just-in-time-compilation.

Parameters:

  • gram (ndarray) –

    Gramian Matrix

  • X (ndarray) –

    New Observations for \(X\)

  • y (ndarray) –

    New Observations for \(Y\)

  • forget (float, default: 0 ) –

    Forget Factor. Defaults to 0.

  • w (float, default: 1 ) –

    Weights for the new observations. Defaults to 1.

Returns:

  • ndarray

    np.ndarray: Updated Gramian Matrix.

ondil.gram.update_inverted_gram

update_inverted_gram(
    gram: ndarray,
    X: ndarray,
    forget: float = 0,
    w: float = 1,
) -> np.ndarray

Update the inverted Gramian Matrix.

Numba

This function uses numba just-in-time-compilation.

Parameters:

  • gram (ndarray) –

    Inverted Gramian Matrix.

  • X (ndarray) –

    New observations for \(X\).

  • forget (float, default: 0 ) –

    Forget Factor. Defaults to 0.

  • w (float, default: 1 ) –

    Weights for new observations. Defaults to 1.

Returns:

  • ndarray

    np.ndarray: Updated inverted Gramian matrix.