Can you provide any guidance for porting code written to use optmum to optmum mt?
1 Answer
0
Probably the easiest way to learn about the differences is to look at two identical examples.
Optmum code
//Load 'optmum' library library optmum; //Include file with global variable definitions #include optmum.ext //Set global control values to defaults optset; //Create extra data for optimization function q = { 0.78 -0.02 -0.12 -0.14, -0.02 0.86 -0.04 0.06, -0.12 -0.04 0.72 -0.08, -0.14 0.06 -0.08 0.74 }; b = { 0.76, 0.08, 1.12, 0.68 }; //Define function to be optimized proc qfct(x); retp(.5*x'*q*x-x'b); endp; //Set optimization method _opstmth = "NEWTON STEPBT"; //Set starting parameter values x0 = { 1, 1, 1, 1 }; //Optimize function { x,fmin,g,retcode } = optmum(&qfct,x0); //Print results to screen call optprt(x,fmin,g,retcode);
Optmt code
//Load 'optmt' library library optmt; //Include file with structure definitions #include optmt.sdf //Declare 'd0' to be a DS struct //and reshape it to be 2x1 struct DS d0; d0 = reshape(d0,2,1); //Assign data to 'd0' structure d0[1].dataMatrix = { 0.78 -0.02 -0.12 -0.14, -0.02 0.86 -0.04 0.06, -0.12 -0.04 0.72 -0.08, -0.14 0.06 -0.08 0.74 }; d0[2].dataMatrix = { 0.76, 0.08, 1.12, 0.68 }; //Declare 'p0' to be a PV structure //to hold parameter values struct PV p0; //Fill 'p0' with a starting vector of ones p0 = pvPack(pvCreate,1|1|1|1,"x"); //Declare 'c0' to be an optmtControl structure //and fill with default values struct optmtControl c0; c0 = optmtControlCreate(); //Function to optimize proc qfct(struct PV p, struct DS d, ind); local x,q,b; struct modelResults mm; x = pvUnpack(p,"x"); q = d[1].dataMatrix; b = d[2].dataMatrix; if ind[1]; mm.function = .5*x'*q*x - x'b; endif; retp(mm); endp; //Declare 'out' to be an optmtResults structure struct optmtResults out; //Optimize function out = optmt(&qfct,p0,d0,c0); //Print results to the screen call optmtPrt(out);
Optmt
The latest version with GAUSS 16 allows some simplification of the use of OPTMT. For example, it does not require use of DS structures for extra data, it does not require the control structure if you are using default values and it also does not require the #include statement.
//Load 'optmt' library library optmt; //Create extra data for optimization function q = { 0.78 -0.02 -0.12 -0.14, -0.02 0.86 -0.04 0.06, -0.12 -0.04 0.72 -0.08, -0.14 0.06 -0.08 0.74 }; b = { 0.76, 0.08, 1.12, 0.68 }; //Function to optimize proc qfct(struct PV p, q, b, ind); local x; struct modelResults mm; x = pvUnpack(p,"x"); if ind[1]; mm.function = .5*x'*q*x - x'b; endif; retp(mm); endp; //Declare 'p0' to be a PV structure //to hold parameter values struct PV p0; //Fill 'p0' with a starting vector of ones p0 = pvPack(pvCreate,1|1|1|1,"x"); //Declare 'out' to be an optmtResults structure struct optmtResults out; //Optimize function out = optmt(&qfct, p0, q, b); //Print results to the screen call optmtPrt(out);
Your Answer
1 Answer
Probably the easiest way to learn about the differences is to look at two identical examples.
Optmum code
//Load 'optmum' library library optmum; //Include file with global variable definitions #include optmum.ext //Set global control values to defaults optset; //Create extra data for optimization function q = { 0.78 -0.02 -0.12 -0.14, -0.02 0.86 -0.04 0.06, -0.12 -0.04 0.72 -0.08, -0.14 0.06 -0.08 0.74 }; b = { 0.76, 0.08, 1.12, 0.68 }; //Define function to be optimized proc qfct(x); retp(.5*x'*q*x-x'b); endp; //Set optimization method _opstmth = "NEWTON STEPBT"; //Set starting parameter values x0 = { 1, 1, 1, 1 }; //Optimize function { x,fmin,g,retcode } = optmum(&qfct,x0); //Print results to screen call optprt(x,fmin,g,retcode);
Optmt code
//Load 'optmt' library library optmt; //Include file with structure definitions #include optmt.sdf //Declare 'd0' to be a DS struct //and reshape it to be 2x1 struct DS d0; d0 = reshape(d0,2,1); //Assign data to 'd0' structure d0[1].dataMatrix = { 0.78 -0.02 -0.12 -0.14, -0.02 0.86 -0.04 0.06, -0.12 -0.04 0.72 -0.08, -0.14 0.06 -0.08 0.74 }; d0[2].dataMatrix = { 0.76, 0.08, 1.12, 0.68 }; //Declare 'p0' to be a PV structure //to hold parameter values struct PV p0; //Fill 'p0' with a starting vector of ones p0 = pvPack(pvCreate,1|1|1|1,"x"); //Declare 'c0' to be an optmtControl structure //and fill with default values struct optmtControl c0; c0 = optmtControlCreate(); //Function to optimize proc qfct(struct PV p, struct DS d, ind); local x,q,b; struct modelResults mm; x = pvUnpack(p,"x"); q = d[1].dataMatrix; b = d[2].dataMatrix; if ind[1]; mm.function = .5*x'*q*x - x'b; endif; retp(mm); endp; //Declare 'out' to be an optmtResults structure struct optmtResults out; //Optimize function out = optmt(&qfct,p0,d0,c0); //Print results to the screen call optmtPrt(out);
Optmt
The latest version with GAUSS 16 allows some simplification of the use of OPTMT. For example, it does not require use of DS structures for extra data, it does not require the control structure if you are using default values and it also does not require the #include statement.
//Load 'optmt' library library optmt; //Create extra data for optimization function q = { 0.78 -0.02 -0.12 -0.14, -0.02 0.86 -0.04 0.06, -0.12 -0.04 0.72 -0.08, -0.14 0.06 -0.08 0.74 }; b = { 0.76, 0.08, 1.12, 0.68 }; //Function to optimize proc qfct(struct PV p, q, b, ind); local x; struct modelResults mm; x = pvUnpack(p,"x"); if ind[1]; mm.function = .5*x'*q*x - x'b; endif; retp(mm); endp; //Declare 'p0' to be a PV structure //to hold parameter values struct PV p0; //Fill 'p0' with a starting vector of ones p0 = pvPack(pvCreate,1|1|1|1,"x"); //Declare 'out' to be an optmtResults structure struct optmtResults out; //Optimize function out = optmt(&qfct, p0, q, b); //Print results to the screen call optmtPrt(out);