-
Notifications
You must be signed in to change notification settings - Fork 7
/
demo_2.m
51 lines (38 loc) · 1.17 KB
/
demo_2.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
%%%%%%%%%% Gaussian Process Regression (GPR) %%%%%%%%%
% Demo: prediction using GPR
% ---------------------------------------------------------------------%
clc
close all
clear all
addpath(genpath(pwd))
% load data
%{
x : training inputs
y : training targets
xt: testing inputs
yt: testing targets
%}
% multiple input-multiple output
load('./data/data_2.mat')
% Set the mean function, covariance function and likelihood function
% Take meanConst, covRQiso and likGauss as examples
meanfunc = @meanConst;
covfunc = @covRQiso;
likfunc = @likGauss;
% Initialization of hyperparameters
hyp = struct('mean', 3, 'cov', [2 2 2], 'lik', -1);
% meanfunc = [];
% covfunc = @covSEiso;
% likfunc = @likGauss;
%
% hyp = struct('mean', [], 'cov', [0 0], 'lik', -1);
% Optimization of hyperparameters
hyp2 = minimize(hyp, @gp, -5, @infGaussLik, meanfunc, covfunc, likfunc,x, y);
% Regression using GPR
% yfit is the predicted mean, and ys is the predicted variance
[yfit ys] = gp(hyp2, @infGaussLik, meanfunc, covfunc, likfunc,x, y, xt);
% Visualization of prediction results
% First output
plotResult(yt(:,1), yfit(:,1))
% Second output
plotResult(yt(:,2), yfit(:,2))