In this vignette, we illustrate
the use of the sequential quadratic programming (SQP) algorithm
implemented in mixsqp
.
Load the mixsqp
package.
Next, initialize the sequence of pseudorandom numbers.
We begin with a small example to show how mixsqp
works.
This call to simulatemixdata
created an n × m conditional
likelihood matrix for a mixture of zero-centered normals, with n = 1000 and m = 20. By default,
simulatemixdata
normalizes the rows of the likelihood
matrix so that the maximum entry in each row is 1.
Now we fit the mixture model using the SQP algorithm:
fit.sqp <- mixsqp(L)
# Running mix-SQP algorithm 0.3-54 on 1000 x 20 matrix
# convergence tol. (SQP): 1.0e-08
# conv. tol. (active-set): 1.0e-10
# zero threshold (solution): 1.0e-08
# zero thresh. (search dir.): 1.0e-14
# l.s. sufficient decrease: 1.0e-02
# step size reduction factor: 7.5e-01
# minimum step size: 1.0e-08
# max. iter (SQP): 1000
# max. iter (active-set): 20
# number of EM iterations: 10
# Computing SVD of 1000 x 20 matrix.
# Matrix is not low-rank; falling back to full matrix.
# iter objective max(rdual) nnz stepsize max.diff nqp nls
# 1 +6.825854400e-01 -- EM -- 20 1.00e+00 3.43e-02 -- --
# 2 +6.608901094e-01 -- EM -- 20 1.00e+00 1.12e-02 -- --
# 3 +6.501637569e-01 -- EM -- 20 1.00e+00 8.83e-03 -- --
# 4 +6.441429345e-01 -- EM -- 20 1.00e+00 7.64e-03 -- --
# 5 +6.405379612e-01 -- EM -- 20 1.00e+00 6.44e-03 -- --
# 6 +6.382623445e-01 -- EM -- 20 1.00e+00 5.36e-03 -- --
# 7 +6.367520429e-01 -- EM -- 20 1.00e+00 4.46e-03 -- --
# 8 +6.357009493e-01 -- EM -- 20 1.00e+00 3.75e-03 -- --
# 9 +6.349366492e-01 -- EM -- 20 1.00e+00 3.18e-03 -- --
# 10 +6.343584376e-01 -- EM -- 20 1.00e+00 2.73e-03 -- --
# 1 +6.339053898e-01 +1.856e-02 20 ------ ------ -- --
# 2 +6.283479290e-01 +1.696e-03 4 1.00e+00 4.44e-01 20 1
# 3 +6.281978248e-01 +1.463e-05 4 1.00e+00 4.98e-01 5 1
# 4 +6.281978243e-01 -1.843e-08 4 1.00e+00 1.06e-04 2 1
# Optimization took 0.00 seconds.
# Convergence criteria met---optimal solution found.
In this example, the SQP algorithm converged to a solution in a small number of iterations.
By default, mixsqp
outputs information on its progress.
It begins by summarizing the optimization problem and the algorithm
settings used. (Since we did not change these settings in the
mixsqp
call, all the settings shown here are the default
settings.)
After that, it outputs, at each iteration, information about the current solution, such as the value of the objective (“objective”) and the number of nonzeros (“nnz”).
The “max(rdual)” column shows the quantity used to assess
convergence. It reports the maximum value of the “dual residual”; the
SQP solver terminates when the maximum dual residual is less than
conv.tol
, which by default is 10−8. In this example, we see that
the dual residual shrinks rapidly toward zero.
Another useful indicator of convergence is the “max.diff” column—it reports the maximum difference between the solution estimates at two successive iterations. We normally expect these differences to shrink as we approach the solution, which is precisely what we see in this example.
This information is also provided in the return value, which we can use, for example, to create a plot of the objective value at each iteration of the SQP algorithm:
This next code chunk gives information about the computing environment used to generate the results contained in this vignette, including the version of R and the packages used.
sessionInfo()
# R version 4.4.2 (2024-10-31)
# Platform: x86_64-pc-linux-gnu
# Running under: Ubuntu 24.04.1 LTS
#
# Matrix products: default
# BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
# LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so; LAPACK version 3.12.0
#
# locale:
# [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
# [3] LC_TIME=en_US.UTF-8 LC_COLLATE=C
# [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
# [7] LC_PAPER=en_US.UTF-8 LC_NAME=C
# [9] LC_ADDRESS=C LC_TELEPHONE=C
# [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
#
# time zone: Etc/UTC
# tzcode source: system (glibc)
#
# attached base packages:
# [1] stats graphics grDevices utils datasets methods base
#
# other attached packages:
# [1] mixsqp_0.3-54 rmarkdown_2.29
#
# loaded via a namespace (and not attached):
# [1] digest_0.6.37 R6_2.5.1 fastmap_1.2.0 Matrix_1.7-1
# [5] xfun_0.49 lattice_0.22-6 maketools_1.3.1 cachem_1.1.0
# [9] knitr_1.49 htmltools_0.5.8.1 buildtools_1.0.0 lifecycle_1.0.4
# [13] cli_3.6.3 grid_4.4.2 sass_0.4.9 jquerylib_0.1.4
# [17] compiler_4.4.2 sys_3.4.3 tools_4.4.2 irlba_2.3.5.1
# [21] evaluate_1.0.1 bslib_0.8.0 Rcpp_1.0.13-1 yaml_2.3.10
# [25] jsonlite_1.8.9 rlang_1.1.4