GPREG Procedure
Getting Started: GPREG Procedure
Note: Input data must be in a table that is accessible in your session. You can refer to this table by using a two-level name. The first level is a libref, and the second level is the table name. For more information, see the section Using SAS Viya Workbench in Chapter 2, Shared Concepts.
This example uses the Sinewave data set to demonstrate how you can use the GPREG procedure to perform Gaussian process regression analysis and save the trained model in an analytic store. The Sinewave data set contains 1,000 noisy samples from a two-dimensional sine wave function; it has two variables, x and y.
The following DATA steps generate the Sinewave data set and upload it to your session:
data Sinewave;
keep x y;
call streaminit(123); /* set random number seed */
do i = 1 to 1000;
u = rand("Uniform");
x = u;
y = sin(6*x)+rand("Normal", 0, 0.01);
output;
end;
run;
data mylib.sinewave;
set Sinewave;
run;
The second DATA step assumes that your libref is named mylib, but you can substitute any appropriately named libref.
The following statements use PROC GPREG to perform Gaussian process regression on the data and save the data in an analytic store:
proc gpreg
data=mylib.sinewave
seed=12345
nThreads=32
nInducingPoints=10
fixInducingPoints
outInducingPoints=mylib.gpreg_ip
outVariationalCov=mylib.gpreg_cov;
target y/level=interval;
input x;
partition fraction(valid=0 test=0.2 seed=1235);
kernel rbf(
autoRelevanceDetermination
fixKernelParmFirstIter
jitterMaxIters=10
);
optimization adam(
regl1=0.5
maxiters=500
learningRate=0.05
momentum=0.8
adaptiveRate
adaptiveDecay=0.9
printfreq=200
);
savestate rstore=mylib.astore;
output out=mylib.score copyvars=(x y);
display nObs varStats modelInfo ParameterEstimates;
run;
These statements assume that your libref is named mylib, but you can substitute any appropriately defined libref.
PROC GPREG generates four ODS tables, which are shown in Figure 1 through Figure 4.
Figure 1: Number of Observations
| Number of Observations | |
|---|---|
| Number of Observations Read | 1000 |
| Number of Observations Used | 1000 |
| Number of Observations Used for Training | 815 |
| Number of Observations Used for Testing | 185 |
Figure 2: Variable Statistics
| Input Variable Statistics | ||
|---|---|---|
| Variable | Mean | Standard Deviation |
| x | 0.511767 | 0.284632 |
| y | -0.020674 | 0.724311 |
Figure 3: Model Information
| Model Information | |
|---|---|
| Seed for Random Initialization for Clustering and Optimization Parameters | 12345 |
| Number of inducing points | 10 |
| Kernel Type | RBF |
| Automatic Relevance Determination | TRUE |
| Fix Kernel Parameters in the First Iteration | FALSE |
| Fix Inducing Points in Optimization | TRUE |
| Use Simple Initialization | TRUE |
| Maximum Number of Iterations for Jitter Cholesky Decomposition | 10 |
Figure 4: Number of Observations
| Parameter Estimates | ||
|---|---|---|
| Parameter Type | Parameter Name | Parameter Value |
| Kernel | Variance | 323.367996 |
| Kernel | Inverse square of length scale for variable x | 735.930478 |
| Noise | Variance | 328.349708 |
In this example, PROC GPREG generates the score output table mylib.score. The following statements print the first 15 rows of the table, which is shown in Figure 5. The value 1 in the _ROLE_ column means that the observation has a training role, and the value 3 in the _ROLE_ column means that the observation has a testing role.
proc print noobs data=mylib.score (obs=15);
run;
Figure 5: Score Output Table
| x | y | P_y | P_yMEAN | P_ySTD | _WARN_ | _ROLE_ |
|---|---|---|---|---|---|---|
| 0.58170 | -0.35197 | -0.019638 | -0.019638 | 13.6534 | 1 | |
| 0.36159 | 0.81021 | -0.020507 | -0.020507 | 13.0249 | 1 | |
| 0.33759 | 0.88297 | 0.002292 | 0.002292 | 13.8129 | 1 | |
| 0.97680 | -0.41130 | -0.020674 | -0.020674 | 13.0249 | 1 | |
| 0.75099 | -0.96933 | -0.021611 | -0.021611 | 13.0845 | 1 | |
| 0.81052 | -0.99303 | -0.020674 | -0.020674 | 13.0249 | 1 | |
| 0.01800 | 0.10657 | -0.018723 | -0.018723 | 14.1779 | 1 | |
| 0.10503 | 0.59752 | -0.015572 | -0.015572 | 13.1166 | 1 | |
| 0.07730 | 0.43982 | -0.034881 | -0.034881 | 15.1158 | 1 | |
| 0.73482 | -0.94985 | -0.026007 | -0.026007 | 14.8356 | 1 | |
| 0.92549 | -0.65055 | -0.021292 | -0.021292 | 13.0015 | 1 | |
| 0.92680 | -0.65987 | -0.021171 | -0.021171 | 13.0097 | 3 | |
| 0.45990 | 0.38082 | -0.015619 | -0.015619 | 13.0897 | 1 | |
| 0.99078 | -0.33322 | -0.020674 | -0.020674 | 13.0249 | 1 | |
| 0.62949 | -0.60994 | -0.020674 | -0.020674 | 13.0249 | 1 |