glearn.LinearModel.update_hyperparam#
- LinearModel.update_hyperparam(cov, y)#
Manually update the posterior mean and covariance of linear model coefficient.
Note
This function is automatically called once the Gaussian process is trained after calling
glearn.GaussianProcess.train(). Hence, there is no need to call this function unless the user wants to manually update the hyperparameters.- Parameters:
- covglearn.Covariance
Covariance object of the Gaussian process regression.
- ynumpy.array
Array of training data.
See also
Notes
Before Training:
Before training the Gaussian process, the coefficient of the linear model, \(\boldsymbol{\beta}\), is unknown, however, it is specified by a prior distribution
\[\boldsymbol{\beta} \sim \mathcal{N}(\boldsymbol{b}, \sigma^2 \mathbf{B}),\]where \(\boldsymbol{b}\) and \(\mathbf{B}\) are given by the user and \(\sigma\) is unknown.
After Training:
Once the function
glearn.GaussianProcess.train()is called to train the model, a posterior distribution for the coefficient \(\boldsymbol{\beta}\) is readily available as\[\boldsymbol{\beta} \sim \mathcal{N}( \hat{\boldsymbol{\beta}}, \mathbf{C}),\]where
\(\hat{\boldsymbol{\beta}}\) is the posterior mean and can be accessed by
LinearModel.betaattribute.\(\mathbf{C}\) is the posterior covariance and can be accessed by
LinearModel.Cattribute.
The user can, however, manually update the above posterior parameters by calling this function.
Examples
>>> # Import modules >>> import glearn >>> from glearn import sample_data >>> # Generate sample points >>> x = sample_data.generate_points(num_points=50) >>> # Generate noisy data >>> y = sample_data.generate_data(x, noise_magnitude=0.05) >>> # Create a linear model >>> mean = glearn.LinearModel(x) >>> # Create a covariance model >>> cov = glearn.Covariance(x) >>> # Create a Gaussian process model >>> gp = glearn.GaussianProcess(mean, cov) >>> # Train model with data >>> gp.train(y) >>> # Update hyperparameter of the linear model >>> # Note that this is done automatically. >>> mean.update_hyperparam(cov, y) >>> # Get the updated posterior mean of beta >>> mean.beta [0.0832212] >>> # Get the updated posterior covariance of beta >>> mean.C [[0.79492599]]