glearn.Covariance.get_size#

Covariance.get_size()#

Returns the size of the covariance matrix.

Returns:
nint

The size \(n\) of the \(n \times n\) covariance matrix.

Examples

Create a covariance matrix based on a set of sample data with four points in \(d=2\) dimensional space.

>>> # Generate a set of points
>>> from glearn.sample_data import generate_points
>>> x = generate_points(num_points=4, dimension=2)

>>> # Create a covariance object
>>> from glearn import Covariance
>>> cov = Covariance(x)

>>> # Get the size of the covariance matrix
>>> cov.get_size()
4

The size of the covariance defined in the above is the same as the size of the training points, x.shape[0].

By providing a set of hyperparameters, the covariance matrix can be fully defined. Here we set \(\sigma=2\), \(\varsigma=3\), and \(\boldsymbol{\alpha}= (1, 2)\).

>>> # Get the covariance matrix for given hyperparameters
>>> cov.set_sigmas(2.0, 3.0)
>>> cov.set_scale([1.0, 2.0])
>>> cov.get_matrix()
array([[13.        ,  3.61643745,  3.51285267,  3.47045163],
       [ 3.61643745, 13.        ,  3.32078482,  3.14804532],
       [ 3.51285267,  3.32078482, 13.        ,  3.53448631],
       [ 3.47045163,  3.14804532,  3.53448631, 13.        ]])