MWPCA Procedure
Example 24.2 Comparing the Incremental SVD Solver with the Full SVD Solver
This example compares the speed and accuracy of the incremental SVD solver with that of the full SVD solver.
First, the following code is used to generate a simulation data set. The data set contains 3,000 observations and 10 variables.
proc iml;
call randseed(2022);
M = j(3000, 10); /* allocate (3000 x 10) vector */
call randgen(M, "Normal"); /* fill it */
create M from M;
append from M;
close M;
quit;
Next, the simulated data set is loaded into the mylib library, and the MWPCA procedure is run using the incremental SVD solver on the simulated data set. The results are shown in Output 24.2.1.
data mylib.M;
set M;
id = _N_;
run;
proc mwpca data=mylib.M windowsize=100 stepsize=1;
id id;
svd incremental maxrank=3;
output out=mylib.incremental_res nPC=1;
run;
Output 24.2.1: Incremental SVD Solver Results
| Model Information | |
|---|---|
| Data Source | M |
| Window Size | 100 |
| Step Size | 1 |
| SVD Method | Eigenvalue Decomposition |
| Cumulative Eigenvalue Percent Tolerance | 1 |
| Number of Observations | 3000 |
|---|---|
| Number of Variables | 10 |
| Results Summary | |
|---|---|
| Number of Windows | 2901 |
| Solution Status | Optimal |
| Run Time (Seconds) | 0.08 |
Then the MWPCA procedure is run using the full SVD solver on the simulated data set. The results are shown in Output 24.2.2.
proc mwpca data=mylib.M windowsize=100 stepsize=1;
id id;
svd MaxRank=3;
output out=mylib.full_res nPC=1;
run;
proc mwpca data=mylib.M windowsize=100 stepsize=1;
id id;
svd MaxRank=3;
output out=mylib.full_res nPC=1;
run;
Output 24.2.2: Full SVD Solver Results
| Model Information | |
|---|---|
| Data Source | M |
| Window Size | 100 |
| Step Size | 1 |
| SVD Method | Eigenvalue Decomposition |
| Cumulative Eigenvalue Percent Tolerance | 1 |
| Number of Observations | 3000 |
|---|---|
| Number of Variables | 10 |
| Results Summary | |
|---|---|
| Number of Windows | 2901 |
| Solution Status | Optimal |
| Run Time (Seconds) | 4.00 |
From Output 24.2.1 and Output 24.2.2, you can see that in this case, the incremental SVD solver is much faster than the full SVD solver.
Finally, the accuracy of the incremental SVD solver is evaluated. The following code extracts the singular values from the incremental SVD and full SVD results, and then it computes the relative error of the singular values:
data eigvals;
merge
mylib.incremental_res(rename=(eigen_value=inc_eig))
mylib.full_res(rename=(eigen_value=full_eig));
keep window_id inc_eig full_eig;
run;
data eigvals;
set eigvals;
relative_err=abs(inc_eig-full_eig)/full_eig;
run;
proc sgplot data=eigvals;
series x=window_id y=relative_err/lineattrs=(thickness=0.1);
yaxis label='Relative Error';
run;
data eigvals;
merge
mylib.incremental_res(rename=(eigen_value=inc_eig))
mylib.full_res(rename=(eigen_value=full_eig));
keep window_id inc_eig full_eig;
run;
data eigvals;
set eigvals;
relative_err=abs(inc_eig-full_eig)/full_eig;
run;
proc sgplot data=eigvals;
series x=window_id y=relative_err/lineattrs=(thickness=0.1);
yaxis label='Relative Error';
run;
From Output 24.2.3, you can see that the relative error is always less than . This means that by using the incremental SVD solver, the MWPCA procedure is much faster without losing much accuracy.
Output 24.2.3: Full SVD Solver Results
