Skip to content

Gramian Matrix

The Gramian

API Reference

rolch.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:

Name Type Description Default
forget float

Forget factor.

required
size int

Length of the output vector.

required

Returns:

Type Description
ndarray

np.ndarray: Vector of exponentially discounted weights.

rolch.init_gram

init_gram(X: np.ndarray, w: np.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:

Name Type Description Default
X ndarray

Design matrix \(X\)

required
w ndarray

Weights vector

required
forget float

Forget factor. Defaults to 0.

0

Returns:

Type Description
ndarray

np.ndarray: Gramian Matrix.

rolch.init_y_gram

init_y_gram(X: np.ndarray, y: np.ndarray, w: np.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:

Name Type Description Default
X ndarray

Design matrix \(X\)

required
y ndarray

Response variable \(Y\)

required
w ndarray

Weights vector

required
forget float

Forget factor. Defaults to 0.

0

Returns:

Type Description
ndarray

np.ndarray: y-Gramian Matrix.

rolch.init_inverted_gram

init_inverted_gram(X: np.ndarray, w: np.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:

Name Type Description Default
X ndarray

Design matrix \(X\)

required
w ndarray

Weights vector

required
forget float

Forget factor. Defaults to 0.

0

Returns:

Type Description
ndarray

np.ndarray: Gramian Matrix.

rolch.update_gram

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

Update the Gramian Matrix.

Numba

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

Parameters:

Name Type Description Default
gram ndarray

Gramian Matrix

required
X ndarray

New observations for \(X\)

required
forget float

Forget factor. Defaults to 0.

0
w float

Weights for the new observations. Defaults to 1.

1

Returns:

Type Description
ndarray

np.ndarray: Updated Gramian Matrix.

rolch.update_y_gram

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

Update the Y-Gramian Matrix.

Numba

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

Parameters:

Name Type Description Default
gram ndarray

Gramian Matrix

required
X ndarray

New Observations for \(X\)

required
y ndarray

New Observations for \(Y\)

required
forget float

Forget Factor. Defaults to 0.

0
w float

Weights for the new observations. Defaults to 1.

1

Returns:

Type Description
ndarray

np.ndarray: Updated Gramian Matrix.

rolch.update_inverted_gram

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

Update the inverted Gramian Matrix.

Numba

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

Parameters:

Name Type Description Default
gram ndarray

Inverted Gramian Matrix.

required
X ndarray

New observations for \(X\).

required
forget float

Forget Factor. Defaults to 0.

0
w float

Weights for new observations. Defaults to 1.

1

Returns:

Type Description
ndarray

np.ndarray: Updated inverted Gramian matrix.