Quadratic Programming with Oracle R Enterprise
Posted
by Jeff Taylor-Oracle
on Oracle Blogs
See other posts from Oracle Blogs
or by Jeff Taylor-Oracle
Published on Wed, 20 Aug 2014 18:18:37 +0000
Indexed on
2014/08/20
22:26 UTC
Read the original article
Hit count: 242
/Analytics
For background, see:
- Oracle SPARC T4-2
- Oracle Solaris 11.2
- quadprog: Functions to solve Quadratic Programming Problems
- Oracle R Enterprise 1.4 ("ORE") 1.4
Problem: path to Solaris Studio doesn't match my installation:
$ ORE CMD INSTALL quadprog_1.5-5.tar.gz
* installing to library \u2018/u01/app/oracle/product/12.1.0/dbhome_1/R/library\u2019
* installing *source* package \u2018quadprog\u2019 ...
** package \u2018quadprog\u2019 successfully unpacked and MD5 sums checked
** libs
/opt/SunProd/studio12u3/solarisstudio12.3/bin/f95 -m64 -PIC -g -c aind.f -o aind.o
bash: /opt/SunProd/studio12u3/solarisstudio12.3/bin/f95: No such file or directory
*** Error code 1
make: Fatal error: Command failed for target `aind.o'
ERROR: compilation failed for package \u2018quadprog\u2019
* removing \u2018/u01/app/oracle/product/12.1.0/dbhome_1/R/library/quadprog\u2019
$ ls -l /opt/solarisstudio12.3/bin/f95
lrwxrwxrwx 1 root root 15 Aug 19 17:36 /opt/solarisstudio12.3/bin/f95 -> ../prod/bin/f90
Solution: a symbolic link:
$ sudo mkdir -p /opt/SunProd/studio12u3
$ sudo ln -s /opt/solarisstudio12.3 /opt/SunProd/studio12u3/
Now, it is all good:
$ ORE CMD INSTALL quadprog_1.5-5.tar.gz
* installing to library \u2018/u01/app/oracle/product/12.1.0/dbhome_1/R/library\u2019
* installing *source* package \u2018quadprog\u2019 ...
** package \u2018quadprog\u2019 successfully unpacked and MD5 sums checked
** libs
/opt/SunProd/studio12u3/solarisstudio12.3/bin/f95 -m64 -PIC -g -c aind.f -o aind.o
/opt/SunProd/studio12u3/solarisstudio12.3/bin/ cc -xc99 -m64 -I/usr/lib/64/R/include -DNDEBUG -KPIC -xlibmieee -c init.c -o init.o
/opt/SunProd/studio12u3/solarisstudio12.3/bin/f95 -m64 -PIC -g -c -o solve.QP.compact.o solve.QP.compact.f
/opt/SunProd/studio12u3/solarisstudio12.3/bin/f95 -m64 -PIC -g -c -o solve.QP.o solve.QP.f
/opt/SunProd/studio12u3/solarisstudio12.3/bin/f95 -m64 -PIC -g -c util.f -o util.o
/opt/SunProd/studio12u3/solarisstudio12.3/bin/ cc -xc99 -m64 -G -o quadprog.so aind.o init.o solve.QP.compact.o solve.QP.o util.o -xlic_lib=sunperf -lsunmath -lifai -lsunimath -lfai -lfai2 -lfsumai -lfprodai -lfminlai -lfmaxlai -lfminvai -lfmaxvai -lfui -lfsu -lsunmath -lmtsk -lm -lifai -lsunimath -lfai -lfai2 -lfsumai -lfprodai -lfminlai -lfmaxlai -lfminvai -lfmaxvai -lfui -lfsu -lsunmath -lmtsk -lm -L/usr/lib/64/R/lib -lR
installing to /u01/app/oracle/product/12.1.0/dbhome_1/R/library/quadprog/libs
** R
** preparing package for lazy loading
** help
*** installing help indices
converting help for package \u2018quadprog\u2019
finding HTML links ... done
solve.QP html
solve.QP.compact html
** building package indices
** testing if installed package can be loaded
* DONE (quadprog)
======
Here is an example from http://cran.r-project.org/web/packages/quadprog/quadprog.pdf
> require(quadprog)
> Dmat <- matrix(0,3,3)
> diag(Dmat) <- 1
> dvec <- c(0,5,0)
> Amat <- matrix(c(-4,-3,0,2,1,0,0,-2,1),3,3)
> bvec <- c(-8,2,0)
> solve.QP(Dmat,dvec,Amat,bvec=bvec)
$solution
[1] 0.4761905 1.0476190 2.0952381
$value
[1] -2.380952
$unconstrained.solution
[1] 0 5 0
$iterations
[1] 3 0
$Lagrangian
[1] 0.0000000 0.2380952 2.0952381
$iact
[1] 3 2
Here, the standard example is modified to work with Oracle R Enterprise
require(ORE)
ore.connect("my-name", "my-sid", "my-host", "my-pass", 1521)
ore.doEval(
function () {
require(quadprog)
}
)
ore.doEval(
function () {
Dmat <- matrix(0,3,3)
diag(Dmat) <- 1
dvec <- c(0,5,0)
Amat <- matrix(c(-4,-3,0,2,1,0,0,-2,1),3,3)
bvec <- c(-8,2,0)
solve.QP(Dmat,dvec,Amat,bvec=bvec)
}
)
$solution
[1] 0.4761905 1.0476190 2.0952381
$value
[1] -2.380952
$unconstrained.solution
[1] 0 5 0
$iterations
[1] 3 0
$Lagrangian
[1] 0.0000000 0.2380952 2.0952381
$iact
[1] 3 2
Now I can combine the quadprog compute algorithms with the Oracle R Enterprise Database engine functionality:
- Scale to large datasets
- Access to tables, views, and external tables in the database, as well as those accessible through database links
- Use SQL query parallel execution
- Use in-database statistical and data mining functionality
© Oracle Blogs or respective owner