R Under development (unstable) (2024-10-16 r87241 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > if(!require("GNE"))stop("this test requires package GNE.") Loading required package: GNE Loading required package: alabama Loading required package: numDeriv Loading required package: nleqslv Loading required package: BB Loading required package: SQUAREM > > itermax <- 10 > > #------------------------------------------------------------------------------- > # (1) Example 5 of von Facchinei et al. (2007) > #------------------------------------------------------------------------------- > > dimx <- c(1, 1) > #Gr_x_j O_i(x) > grobj <- function(x, i, j) + { + if(i == 1) + res <- c(2*(x[1]-1), 0) + if(i == 2) + res <- c(0, 2*(x[2]-1/2)) + res[j] + } > #Gr_x_k Gr_x_j O_i(x) > heobj <- function(x, i, j, k) + 2 * (i == j && j == k) > > dimlam <- c(1, 1) > #constraint function g_i(x) > g <- function(x, i) + sum(x[1:2]) - 1 > #Gr_x_j g_i(x) > grg <- function(x, i, j) + 1 > #Gr_x_k Gr_x_j g_i(x) > heg <- function(x, i, j, k) + 0 > > > > #true value is (3/4, 1/4, 1/2, 1/2) > > z0 <- rep(0, sum(dimx)+sum(dimlam)) > > funSSR(z0, dimx, dimlam, grobj=grobj, constr=g, grconstr=grg, compl=phiFB, echo=FALSE) [1] -2 -1 0 0 > > > jacSSR(z0, dimx, dimlam, heobj=heobj, constr=g, grconstr=grg, + heconstr=heg, gcompla=GrAphiFB, gcomplb=GrBphiFB) [,1] [,2] [,3] [,4] [1,] 2 0 1 0 [2,] 0 2 0 1 [3,] 0 0 -1 0 [4,] 0 0 0 -1 > > > GNE.nseq(z0, dimx, dimlam, grobj=grobj, NULL, heobj=heobj, NULL, + constr=g, NULL, grconstr=grg, NULL, heconstr=heg, NULL, + compl=phiFB, gcompla=GrAphiFB, gcomplb=GrBphiFB, method="Newton", + control=list(trace=1, maxit=itermax)) Algorithm parameters -------------------- Method: Newton Global strategy: geometric linesearch (reduction = 0.5) Maximum stepsize = 1.79769e+308 Scaling: fixed ftol = 1e-06 xtol = 1e-08 btol = 0.001 cndtol = 1e-12 Iteration report ---------------- Iter Jac Lambda Ftarg Fnorm Largest |f| 0 2.500000e+00 2.000000e+00 1 N(3.3e-01) 1.0000 2.499500e+00 1.000000e+00 1.000000e+00 2 N(1.2e-01) 1.0000 9.998000e-01 4.244067e-02 2.060113e-01 3 N(1.3e-02) 1.0000 4.243218e-02 1.241359e-03 3.523293e-02 4 N(3.8e-04) 1.0000 1.241111e-03 1.522043e-06 1.233711e-03 5 N(4.6e-07) 1.0000 1.521739e-06 2.316580e-12 1.522032e-06 6 Ni(7.0e-13) GNE: 0.7500008 0.2500008 0.4999985 0.4999985 with optimal norm 2.152478e-06 after 6 iterations with exit code 5 . Output message: Jacobian is too ill-conditioned (1/condition=7.0e-13) (see allowSingular option) Function/grad/hessian calls: 5 6 Optimal (vector) value: -5.551115e-17 5.551115e-17 1.522032e-06 1.522032e-06 > > GNE.nseq(z0, dimx, dimlam, grobj=grobj, NULL, heobj=heobj, NULL, + constr=g, NULL, grconstr=grg, NULL, heconstr=heg, NULL, + compl=phiFB, gcompla=GrAphiFB, gcomplb=GrBphiFB, method="Broyden", + control=list(trace=1, maxit=itermax)) Algorithm parameters -------------------- Method: Broyden Global strategy: geometric linesearch (reduction = 0.5) Maximum stepsize = 1.79769e+308 Scaling: fixed ftol = 1e-06 xtol = 1e-08 btol = 0.001 cndtol = 1e-12 Iteration report ---------------- Iter Jac Lambda Ftarg Fnorm Largest |f| 0 2.500000e+00 2.000000e+00 1 N(3.3e-01) 1.0000 2.499500e+00 1.000000e+00 1.000000e+00 2 B(2.1e-01) 1.0000 9.998000e-01 1.268384e-02 1.126226e-01 3 B(2.0e-01) 1.0000 1.268130e-02 3.405143e-03 5.835360e-02 4 B(2.1e-01) 1.0000 3.404462e-03 4.006909e-05 6.330015e-03 5 B(2.3e-01) 1.0000 4.006108e-05 1.346909e-07 3.670026e-04 6 B(2.4e-01) 1.0000 1.346640e-07 5.396100e-12 2.322951e-06 7 B(2.4e-01) 1.0000 5.395021e-12 7.268052e-19 8.525287e-10 GNE: 0.75 0.25 0.5 0.5 with optimal norm 1.205658e-09 after 1 iterations with exit code 1 . Output message: Function criterion near zero Function/grad/hessian calls: 7 1 Optimal (vector) value: 5.551115e-17 5.551115e-17 8.525287e-10 8.525287e-10 > > > > #------------------------------------------------------------------------------- > # (2) Duopoly game of Krawczyk and Stanislav Uryasev (2000) > #------------------------------------------------------------------------------- > > > #constants > myarg <- list(d= 20, lambda= 4, rho= 1) > > dimx <- c(1, 1) > #Gr_x_j O_i(x) > grobj <- function(x, i, j, arg) + { + res <- -arg$rho * x[i] + if(i == j) + res <- res + arg$d - arg$lambda - arg$rho*(x[1]+x[2]) + -res + } > #Gr_x_k Gr_x_j O_i(x) > heobj <- function(x, i, j, k, arg) + arg$rho * (i == j) + arg$rho * (j == k) > > > dimlam <- c(1, 1) > #constraint function g_i(x) > g <- function(x, i) + -x[i] > #Gr_x_j g_i(x) > grg <- function(x, i, j) + -1*(i == j) > #Gr_x_k Gr_x_j g_i(x) > heg <- function(x, i, j, k) + 0 > > #true value is (16/3, 16/3, 0, 0) > > z0 <- rep(0, sum(dimx)+sum(dimlam)) > > funSSR(z0, dimx, dimlam, grobj=grobj, myarg, constr=g, grconstr=grg, compl=phiFB, echo=FALSE) [1] -16 -16 0 0 > > jacSSR(z0, dimx, dimlam, heobj=heobj, myarg, constr=g, grconstr=grg, + heconstr=heg, gcompla=GrAphiFB, gcomplb=GrBphiFB) [,1] [,2] [,3] [,4] [1,] 2.0 1.0 -1.0 0.0 [2,] 1.0 2.0 0.0 -1.0 [3,] -0.5 0.0 -0.5 0.0 [4,] 0.0 -0.5 0.0 -0.5 > > > GNE.nseq(z0, dimx, dimlam, grobj=grobj, myarg, heobj=heobj, myarg, + constr=g, NULL, grconstr=grg, NULL, heconstr=heg, NULL, + compl=phiFB, gcompla=GrAphiFB, gcomplb=GrBphiFB, method="Newton", + control=list(trace=1, maxit=itermax)) Algorithm parameters -------------------- Method: Newton Global strategy: geometric linesearch (reduction = 0.5) Maximum stepsize = 1.79769e+308 Scaling: fixed ftol = 1e-06 xtol = 1e-08 btol = 0.001 cndtol = 1e-12 Iteration report ---------------- Iter Jac Lambda Ftarg Fnorm Largest |f| 0 2.560000e+02 1.600000e+01 1 N(1.5e-01) 1.0000 2.559488e+02 3.200000e+01 5.656854e+00 2 N(2.5e-01) 1.0000 3.199360e+01 8.822238e-01 9.392677e-01 3 N(1.9e-01) 1.0000 8.820474e-01 4.333896e-03 6.583233e-02 4 N(1.6e-01) 1.0000 4.333029e-03 1.597461e-07 3.996825e-04 5 N(1.6e-01) 1.0000 1.597141e-07 2.242416e-16 1.497470e-08 GNE: 5.333333 5.333333 -1.49747e-08 -1.49747e-08 with optimal norm 2.117742e-08 after 5 iterations with exit code 1 . Output message: Function criterion near zero Function/grad/hessian calls: 5 5 Optimal (vector) value: 1.230136e-15 5.776629e-16 1.49747e-08 1.49747e-08 > > GNE.nseq(z0, dimx, dimlam, grobj=grobj, myarg, heobj=heobj, myarg, + constr=g, NULL, grconstr=grg, NULL, heconstr=heg, NULL, + compl=phiFB, gcompla=GrAphiFB, gcomplb=GrBphiFB, method="Broyden", + control=list(trace=1, maxit=itermax)) Algorithm parameters -------------------- Method: Broyden Global strategy: geometric linesearch (reduction = 0.5) Maximum stepsize = 1.79769e+308 Scaling: fixed ftol = 1e-06 xtol = 1e-08 btol = 0.001 cndtol = 1e-12 Iteration report ---------------- Iter Jac Lambda Ftarg Fnorm Largest |f| 0 2.560000e+02 1.600000e+01 1 N(1.5e-01) 1.0000 2.559488e+02 3.200000e+01 5.656854e+00 2 B(1.6e-01) 1.0000 3.199360e+01 7.883762e-01 8.879055e-01 3 B(1.5e-01) 1.0000 7.882185e-01 8.303179e-02 2.881524e-01 4 B(1.7e-01) 1.0000 8.301519e-02 7.748803e-04 2.783667e-02 5 B(1.7e-01) 1.0000 7.747253e-04 6.036541e-07 7.769518e-04 6 B(1.7e-01) 1.0000 6.035334e-07 4.083463e-12 2.020758e-06 7 B(1.7e-01) 1.0000 4.082646e-12 2.166929e-20 1.472049e-10 GNE: 5.333333 5.333333 -1.472048e-10 -1.472048e-10 with optimal norm 2.081792e-10 after 1 iterations with exit code 1 . Output message: Function criterion near zero Function/grad/hessian calls: 7 1 Optimal (vector) value: 1.695567e-15 1.650514e-15 1.472049e-10 1.472049e-10 > > > #------------------------------------------------------------------------------- > # (3) River basin pollution game of Krawczyk and Stanislav Uryasev (2000) > #------------------------------------------------------------------------------- > > myarg <- list( + C = cbind(c(.1, .12, .15), c(.01, .05, .01)), + U = cbind(c(6.5, 5, 5.5), c(4.583, 6.25, 3.75)), + K = c(100, 100), + E = c(.5, .25, .75), + D = c(3, .01) + ) > > > > dimx <- c(1, 1, 1) > #Gr_x_j O_i(x) > grobj <- function(x, i, j, arg) + { + dij <- 1*(i == j) + res <- -(-arg$D[2] - arg$C[i, 2]*dij) * x[i] + res - (arg$D[1] - arg$D[2]*sum(x[1:3]) - arg$C[i, 1] - arg$C[i, 2]*x[i]) * dij + } > #Gr_x_k Gr_x_j O_i(x) > heobj <- function(x, i, j, k, arg) + { + dij <- 1*(i == j) + dik <- 1*(i == k) + + arg$D[2] * dik + arg$D[2] * dij + 2 * arg$C[i, 2] * dij * dik + } > > dimlam <- c(2, 2, 2) > #g_i(x) > g <- function(x, i, arg) + c(sum(arg$U[, 1] * arg$E * x[1:3]) - arg$K[1], + sum(arg$U[, 2] * arg$E * x[1:3]) - arg$K[2]) > #Gr_x_j g_i(x) > grg <- function(x, i, j, arg) + c(arg$U[j, 1] * arg$E[j], arg$U[j, 2] * arg$E[j]) > #Gr_x_k Gr_x_j g_i(x) > heg <- function(x, i, j, k, arg) + c(0, 0) > > #true value around (21.146, 16.027, 2.724, 0.574, 0.000) > z0 <- rexp(sum(dimx)+sum(dimlam)) > > > funSSR(z0, dimx, dimlam, grobj=grobj, myarg, constr=g, myarg, grconstr=grg, myarg, compl=phiFB, echo=TRUE) z [1] 1.45091175 0.72595524 0.06072779 0.26948342 1.59852205 2.18896650 2.21156259 [8] 0.42747507 0.59819669 dimx [1] 1 1 1 dimlam [1] 2 2 2 dimmu [1] 0 [1] FALSE [1] 1.7047377 3.4140057 0.6199606 -0.2690977 -1.5851264 -2.1635171 -2.1859238 [8] -0.4265044 -0.5963207 > > jacSSR(z0, dimx, dimlam, heobj=heobj, myarg, constr=g, myarg, grconstr=grg, myarg, + heconstr=heg, myarg, gcompla=GrAphiFB, gcomplb=GrBphiFB) [,1] [,2] [,3] [,4] [,5] [,6] [1,] 4.000000e-02 1.000000e-02 1.000000e-02 3.250000 2.2915000 0.0000000 [2,] 1.000000e-02 1.200000e-01 1.000000e-02 0.000000 0.0000000 1.2500000 [3,] 1.000000e-02 1.000000e-02 4.000000e-02 0.000000 0.0000000 0.0000000 [4,] 1.331957e-05 5.122911e-06 1.690561e-05 -0.997137 0.0000000 0.0000000 [5,] 3.218184e-04 2.194376e-04 3.949877e-04 0.000000 -0.9832411 0.0000000 [6,] 8.784779e-04 3.378761e-04 1.114991e-03 0.000000 0.0000000 -0.9767507 [7,] 6.158691e-04 4.199413e-04 7.558944e-04 0.000000 0.0000000 0.0000000 [8,] 3.351534e-05 1.289051e-05 4.253870e-05 0.000000 0.0000000 0.0000000 [9,] 4.507547e-05 3.073551e-05 5.532392e-05 0.000000 0.0000000 0.0000000 [,7] [,8] [,9] [1,] 0.000000 0.0000000 0.0000000 [2,] 1.562500 0.0000000 0.0000000 [3,] 0.000000 4.1250000 2.8125000 [4,] 0.000000 0.0000000 0.0000000 [5,] 0.000000 0.0000000 0.0000000 [6,] 0.000000 0.0000000 0.0000000 [7,] -0.976817 0.0000000 0.0000000 [8,] 0.000000 -0.9954586 0.0000000 [9,] 0.000000 0.0000000 -0.9937278 > > > GNE.nseq(z0, dimx, dimlam, grobj=grobj, myarg, heobj=heobj, myarg, + constr=g, myarg, grconstr=grg, myarg, heconstr=heg, myarg, + compl=phiFB, gcompla=GrAphiFB, gcomplb=GrBphiFB, method="Newton", + control=list(trace=1, maxit=itermax)) Algorithm parameters -------------------- Method: Newton Global strategy: geometric linesearch (reduction = 0.5) Maximum stepsize = 1.79769e+308 Scaling: fixed ftol = 1e-06 xtol = 1e-08 btol = 0.001 cndtol = 1e-12 Iteration report ---------------- Iter Jac Lambda Ftarg Fnorm Largest |f| 0 1.376376e+01 3.414006e+00 1 N(1.1e-03) 1.0000 1.376101e+01 8.223579e+05 6.282454e+02 1 0.5000 1.376239e+01 8.722953e+04 2.198615e+02 1 0.2500 1.376308e+01 3.535043e+02 1.567194e+01 1 0.1250 1.376342e+01 1.051156e+01 2.987255e+00 2 N(9.5e-04) 1.0000 1.050946e+01 7.771015e+05 6.131515e+02 2 0.5000 1.051051e+01 1.287146e+05 2.633625e+02 2 0.2500 1.051104e+01 1.165676e+04 8.846824e+01 2 0.1250 1.051130e+01 7.886601e+00 2.613848e+00 3 N(2.8e-04) 1.0000 7.885024e+00 6.587111e-02 2.121951e-01 4 N(5.6e-06) 1.0000 6.585793e-02 7.567577e-04 2.265885e-02 5 N(1.2e-08) 1.0000 7.566063e-04 8.609953e+06 2.388524e+03 5 0.5000 7.566820e-04 1.497745e+06 9.961064e+02 5 0.2500 7.567198e-04 1.358701e+05 2.998975e+02 5 0.1250 7.567387e-04 5.817147e-04 1.982667e-02 6 N(5.3e-07) 1.0000 5.815984e-04 1.460135e-07 3.120613e-04 7 N(3.6e-11) 1.0000 1.459843e-07 1.088106e-14 8.517066e-08 GNE: 98.73278 -175.6229 -0.3279775 0.2185223 -1.923309e-15 18.37656 -2.464493e-15 0.8804898 6.3666e-16 with optimal norm 1.475199e-07 after 7 iterations with exit code 1 . Output message: Function criterion near zero Function/grad/hessian calls: 16 7 Optimal (vector) value: -9.144875e-14 3.254657e-15 1.42495e-17 8.517066e-08 0 8.517064e-08 0 8.517064e-08 0 > > GNE.nseq(z0, dimx, dimlam, grobj=grobj, myarg, heobj=heobj, myarg, + constr=g, myarg, grconstr=grg, myarg, heconstr=heg, myarg, + compl=phiFB, gcompla=GrAphiFB, gcomplb=GrBphiFB, method="Broyden", + control=list(trace=1, maxit=itermax)) Algorithm parameters -------------------- Method: Broyden Global strategy: geometric linesearch (reduction = 0.5) Maximum stepsize = 1.79769e+308 Scaling: fixed ftol = 1e-06 xtol = 1e-08 btol = 0.001 cndtol = 1e-12 Iteration report ---------------- Iter Jac Lambda Ftarg Fnorm Largest |f| 0 1.376376e+01 3.414006e+00 1 N(1.1e-03) 1.0000 1.376101e+01 8.223579e+05 6.282454e+02 1 0.5000 1.376239e+01 8.722953e+04 2.198615e+02 1 0.2500 1.376308e+01 3.535043e+02 1.567194e+01 1 0.1250 1.376342e+01 1.051156e+01 2.987255e+00 2 B(1.0e-03) 1.0000 1.050946e+01 8.045503e+05 6.223011e+02 2 0.5000 1.051051e+01 1.341640e+05 2.679373e+02 2 0.2500 1.051104e+01 1.231297e+04 9.075564e+01 2 0.1250 1.051130e+01 1.235108e+01 2.613848e+00 2 0.0625 1.051143e+01 9.179957e+00 2.800552e+00 3 B(8.9e-04) 1.0000 9.178121e+00 7.390155e+05 6.004799e+02 3 0.5000 9.179039e+00 1.451909e+05 2.791744e+02 3 0.2500 9.179498e+00 2.186477e+04 1.185218e+02 3 0.1250 9.179728e+00 2.137348e+03 3.819620e+01 3 0.0625 9.179843e+00 6.930275e+00 2.625517e+00 4 B(5.7e-04) 1.0000 6.928889e+00 3.504221e+04 1.560179e+02 4 0.5000 6.929582e+00 8.487705e+03 7.702540e+01 4 0.2500 6.929929e+00 1.992719e+03 3.752961e+01 4 0.1250 6.930102e+00 4.406532e+02 1.778269e+01 4 0.0625 6.930189e+00 8.817059e+01 7.911530e+00 4 0.0312 6.930232e+00 1.712898e+01 2.982741e+00 4 0.0156 6.930254e+00 6.810811e+00 2.584493e+00 5 B(5.1e-04) 1.0000 6.809449e+00 1.235477e+00 1.335459e+00 6 B(5.4e-04) 1.0000 1.235230e+00 9.763606e-01 1.174411e+00 7 B(3.1e-04) 1.0000 9.761653e-01 2.390089e+04 1.229805e+02 7 0.5000 9.762629e-01 4.855090e+03 5.723750e+01 7 0.2500 9.763118e-01 8.689333e+02 2.437141e+01 7 0.1250 9.763362e-01 8.932509e+01 7.958049e+00 7 0.0625 9.763484e-01 2.802342e-02 1.398708e-01 8 B(5.3e-04) 1.0000 2.801781e-02 4.315872e+00 1.799745e+00 8 0.5000 2.802062e-02 1.068580e+00 8.960422e-01 8 0.2500 2.802202e-02 3.207006e-01 4.862160e-01 8 0.1250 2.802272e-02 1.269022e-01 3.026361e-01 8 0.0625 2.802307e-02 6.703299e-02 2.183276e-01 8 0.0312 2.802324e-02 4.511298e-02 1.783303e-01 8 0.0156 2.802333e-02 3.598897e-02 1.589040e-01 8 0.0078 2.802337e-02 3.186449e-02 1.493378e-01 9 N(1.6e-05) 1.0000 2.801781e-02 1.852726e-04 1.115079e-02 10 B(1.7e-05) 1.0000 1.852356e-04 1.132067e-09 2.747208e-05 GNE: 32.77728 -15.31047 3.057442 0.5265966 4.173337e-08 3.487127 1.568139e-07 0.6189174 7.853322e-10 with optimal norm 4.758291e-05 after 2 iterations with exit code 4 . Output message: Iteration limit exceeded Function/grad/hessian calls: 38 2 Optimal (vector) value: 1.221351e-16 2.92046e-16 -7.351438e-16 2.747208e-05 -4.173337e-08 2.747147e-05 -1.568139e-07 2.747198e-05 -7.853345e-10 > > > > #------------------------------------------------------------------------------- > # (4) Example of GNE with 4 solutions(!) > #------------------------------------------------------------------------------- > > myarg <- list(C=c(2, 3), D=c(4,0)) > > dimx <- c(1, 1) > #Gr_x_j O_i(x) > grobj <- function(x, i, j, arg) + { + dij <- 1*(i == j) + other <- ifelse(i == 1, 2, 1) + 2*(x[i] - arg$C[i])*(x[other] - arg$D[i])^4*dij + 4*(x[i] - arg$C[i])^2*(x[other] - arg$D[i])^3*(1-dij) + } > #Gr_x_k Gr_x_j O_i(x) > heobj <- function(x, i, j, k, arg) + { + dij <- 1*(i == j) + dik <- 1*(i == k) + other <- ifelse(i == 1, 2, 1) + res <- 2*(x[other] - arg$D[i])^4*dij*dik + 8*(x[i] - arg$C[i])*(x[other] - arg$D[i])^3*dij*(1-dik) + res <- res + 8*(x[i] - arg$C[i])*(x[other] - arg$D[i])^3*(1-dij)*dik + res + 12*(x[i] - arg$C[i])^2*(x[other] - arg$D[i])^2*(1-dij)*(1-dik) + } > > dimlam <- c(1, 1) > #g_i(x) > g <- function(x, i) + ifelse(i == 1, sum(x[1:2]) - 1, 2*x[1]+x[2]-2) > #Gr_x_j g_i(x) > grg <- function(x, i, j) + ifelse(i == 1, 1, 1 + 1*(i == j)) > #Gr_x_k Gr_x_j g_i(x) > heg <- function(x, i, j, k) + 0 > > > > z0 <- rexp(sum(dimx)+sum(dimlam)) > > funSSR(z0, dimx, dimlam, grobj=grobj, myarg, constr=g, grconstr=grg, compl=phiFB, echo=FALSE) [1] -333.3051383 1.3312462 0.3710572 -0.2366962 > > jacSSR(z0, dimx, dimlam, heobj=heobj, myarg, constr=g, grconstr=grg, + heconstr=heg, gcompla=GrAphiFB, gcomplb=GrBphiFB, echo=FALSE) [,1] [,2] [,3] [,4] [1,] 218.170525 412.72454451 1.0000000 0.00000000 [2,] -1.872309 0.09890361 0.0000000 2.00000000 [3,] 1.842397 1.84239711 -0.4611428 0.00000000 [4,] 0.651373 1.30274595 0.0000000 -0.06273846 > > > GNE.nseq(z0, dimx, dimlam, grobj=grobj, myarg, heobj=heobj, myarg, + constr=g, grconstr=grg, heconstr=heg, + compl=phiFB, gcompla=GrAphiFB, gcomplb=GrBphiFB, method="Newton", + control=list(trace=1, maxit=itermax)) Algorithm parameters -------------------- Method: Newton Global strategy: geometric linesearch (reduction = 0.5) Maximum stepsize = 1.79769e+308 Scaling: fixed ftol = 1e-06 xtol = 1e-08 btol = 0.001 cndtol = 1e-12 Iteration report ---------------- Iter Jac Lambda Ftarg Fnorm Largest |f| 0 5.554714e+04 3.333051e+02 1 N(5.7e-05) 1.0000 5.553603e+04 2.509305e+09 6.491077e+04 1 0.5000 5.554159e+04 1.127562e+07 3.466350e+03 1 0.2500 5.554436e+04 7.611737e+04 3.033596e+02 1 0.1250 5.554575e+04 1.691743e+04 1.824454e+02 2 N(1.5e-04) 1.0000 1.691405e+04 6.843064e+02 3.690208e+01 3 N(1.3e-05) 1.0000 6.841696e+02 1.500085e+04 1.731686e+02 3 0.5000 6.842380e+02 1.537709e+03 5.543032e+01 3 0.2500 6.842722e+02 6.577922e+02 3.621186e+01 4 N(7.6e-06) 1.0000 6.576606e+02 1.047183e+04 1.444803e+02 4 0.5000 6.577264e+02 1.274388e+03 5.042533e+01 4 0.2500 6.577593e+02 6.069226e+02 3.479819e+01 5 N(6.0e-06) 1.0000 6.068012e+02 4.366450e+03 9.329876e+01 5 0.5000 6.068619e+02 7.603884e+02 3.895110e+01 5 0.2500 6.068923e+02 4.901953e+02 3.127679e+01 6 N(5.1e-06) 1.0000 4.900973e+02 1.640014e+03 5.719620e+01 6 0.5000 4.901463e+02 4.254899e+02 2.914097e+01 7 N(4.0e-06) 1.0000 4.254048e+02 1.389984e+02 1.666511e+01 8 N(3.2e-06) 1.0000 1.389706e+02 1.031315e+00 1.415021e+00 9 N(2.5e-06) 1.0000 1.031109e+00 1.967650e+01 6.190084e+00 9 0.5000 1.031212e+00 2.523242e+00 2.212293e+00 9 0.2500 1.031264e+00 1.061369e+00 1.432206e+00 9 0.1250 1.031290e+00 9.146055e-01 1.330227e+00 10 N(2.4e-06) 1.0000 9.144226e-01 3.279538e+01 7.989833e+00 10 0.5000 9.145140e-01 3.489431e+00 2.601516e+00 10 0.2500 9.145598e-01 1.127650e+00 1.474276e+00 10 0.1250 9.145826e-01 8.533059e-01 1.282172e+00 GNE: 1.158679 -0.1586793 504.5664 5.597377 with optimal norm 1.306374 after 10 iterations with exit code 4 . Output message: Iteration limit exceeded Function/grad/hessian calls: 26 10 Optimal (vector) value: 1.282172 -0.1917022 3.501555e-11 0.1609281 > > GNE.nseq(z0, dimx, dimlam, grobj=grobj, myarg, heobj=heobj, myarg, + constr=g, grconstr=grg, heconstr=heg, + compl=phiFB, gcompla=GrAphiFB, gcomplb=GrBphiFB, method="Broyden", + control=list(trace=1, maxit=itermax)) Algorithm parameters -------------------- Method: Broyden Global strategy: geometric linesearch (reduction = 0.5) Maximum stepsize = 1.79769e+308 Scaling: fixed ftol = 1e-06 xtol = 1e-08 btol = 0.001 cndtol = 1e-12 Iteration report ---------------- Iter Jac Lambda Ftarg Fnorm Largest |f| 0 5.554714e+04 3.333051e+02 1 N(5.7e-05) 1.0000 5.553603e+04 2.509305e+09 6.491077e+04 1 0.5000 5.554159e+04 1.127562e+07 3.466350e+03 1 0.2500 5.554436e+04 7.611737e+04 3.033596e+02 1 0.1250 5.554575e+04 1.691743e+04 1.824454e+02 2 B(1.7e-04) 1.0000 1.691405e+04 1.670629e+03 4.301059e+01 3 B(1.4e-03) 1.0000 1.670294e+03 1.814907e+03 6.004712e+01 3 0.5000 1.670462e+03 1.433715e+03 5.148286e+01 4 B(1.4e-03) 1.0000 1.433428e+03 1.814182e+02 1.872747e+01 5 B(1.4e-03) 1.0000 1.813819e+02 1.736134e+01 5.878055e+00 6 B(1.3e-03) 1.0000 1.735787e+01 1.333773e+01 4.239868e+00 7 B(7.0e-04) 1.0000 1.333506e+01 1.836282e+01 6.044139e+00 7 0.5000 1.333640e+01 1.055255e+01 4.340812e+00 8 B(3.8e-04) 1.0000 1.055044e+01 9.186686e+00 3.908505e+00 9 B(1.9e-04) 1.0000 9.184849e+00 7.569288e+00 3.716260e+00 10 B(1.1e-04) 1.0000 7.567775e+00 5.055351e+00 3.116828e+00 GNE: -2.004593 3.014773 4.429472 0.07396386 with optimal norm 3.179733 after 1 iterations with exit code 4 . Output message: Iteration limit exceeded Function/grad/hessian calls: 15 1 Optimal (vector) value: -3.116828 0.6250137 0.01019116 -0.07305052 > > > #------------------------------------------------------------------------------- > # (5) another Example > #------------------------------------------------------------------------------- > > # associated objective functions > > dimx <- c(2, 2, 3) > #Gr_x_j O_i(x) > grfullob <- function(x, i, j) + { + x <- x[1:7] + if(i == 1) + grad <- 3*(x - 1:7)^2 + if(i == 2) + grad <- 1:7*(x - 1:7)^(0:6) + if(i == 3) + { + s <- x[5]^2 + x[6]^2 + x[7]^2 - 5 + grad <- c(1, 0, 1, 0, 4*x[5]*s, 4*x[6]*s, 4*x[7]*s) + } + grad[j] + } > > > #Gr_x_k Gr_x_j O_i(x) > hefullob <- function(x, i, j, k) + { + x <- x[1:7] + if(i == 1) + he <- diag( 6*(x - 1:7) ) + if(i == 2) + he <- diag( c(0, 2, 6, 12, 20, 30, 42)*(x - 1:7)^c(0, 0:5) ) + if(i == 3) + { + s <- x[5]^2 + x[6]^2 + x[7]^2 + + he <- rbind(rep(0, 7), rep(0, 7), rep(0, 7), rep(0, 7), + c(0, 0, 0, 0, 4*s+8*x[5]^2, 8*x[5]*x[6], 8*x[5]*x[7]), + c(0, 0, 0, 0, 8*x[5]*x[6], 4*s+8*x[6]^2, 8*x[6]*x[7]), + c(0, 0, 0, 0, 8*x[5]*x[7], 8*x[6]*x[7], 4*s+8*x[7]^2) ) + } + he[j,k] + } > > > > # constraint linked functions > > dimlam <- c(1, 2, 2) > #constraint function g_i(x) > g <- function(x, i) + { + x <- x[1:7] + if(i == 1) + res <- sum( x^(1:7) ) -7 + if(i == 2) + res <- c(sum(x) + prod(x) - 14, 20 - sum(x)) + if(i == 3) + res <- c(sum(x^2) + 1, 100 - sum(x)) + res + } > > > #Gr_x_j g_i(x) > grfullg <- function(x, i, j) + { + x <- x[1:7] + if(i == 1) + grad <- (1:7) * x ^ (0:6) + if(i == 2) + { + grad <- 1 + sapply(1:7, function(i) prod(x[-i])) + grad <- cbind(grad, -1) + } + if(i == 3) + grad <- cbind(2*x, -1) + + if(i == 1) + res <- grad[j] + if(i != 1) + res <- grad[j,] + as.numeric(res) + } > > #Gr_x_k Gr_x_j g_i(x) > hefullg <- function(x, i, j, k) + { + x <- x[1:7] + if(i == 1) + he1 <- diag( c(0, 2, 6, 12, 20, 30, 42) * x ^ c(0, 0, 1:5) ) + if(i == 2) + { + he1 <- matrix(0, 7, 7) + he1[1, -1] <- sapply(2:7, function(i) prod(x[-c(1, i)])) + he1[2, -2] <- sapply(c(1, 3:7), function(i) prod(x[-c(2, i)])) + he1[3, -3] <- sapply(c(1:2, 4:7), function(i) prod(x[-c(3, i)])) + he1[4, -4] <- sapply(c(1:3, 5:7), function(i) prod(x[-c(4, i)])) + he1[5, -5] <- sapply(c(1:4, 6:7), function(i) prod(x[-c(5, i)])) + he1[6, -6] <- sapply(c(1:5, 7:7), function(i) prod(x[-c(6, i)])) + he1[7, -7] <- sapply(1:6, function(i) prod(x[-c(7, i)])) + + he2 <- matrix(0, 7, 7) + } + if(i == 3) + { + he1 <- diag(rep(2, 7)) + he2 <- matrix(0, 7, 7) + } + if(i != 1) + return( c(he1[j, k], he2[j, k]) ) + else + return( he1[j, k] ) + } > > > > > # (3) compute Phi > # > > z <- rexp(sum(dimx) + sum(dimlam)) > > n <- sum(dimx) > m <- sum(dimlam) > x <- z[1:n] > lam <- z[(n+1):(n+m)] > > funSSR(z, dimx, dimlam, grobj=grfullob, constr=g, grconstr=grfullg, compl=phiFB) [1] 6.7169535 1.8641342 21.4933579 -60.3385113 -1.0393242 -2.3987353 [7] -7.8196723 131.0270708 -0.6833819 23.5591032 29.2102504 183.0022465 > > jacSSR(z, dimx, dimlam, heobj=hefullob, constr=g, grconstr=grfullg, + heconstr=hefullg, gcompla=GrAphiFB, gcomplb=GrBphiFB) [,1] [,2] [,3] [,4] [,5] [1,] 8.742614742 0.00000000 0.00000000 0.000000000 0.000000000 [2,] 0.000000000 -2.48438047 0.00000000 0.000000000 0.000000000 [3,] 0.132433113 0.22134671 -15.68997564 0.214199103 3.208283179 [4,] 0.033562916 0.05609655 0.21419910 73.855078277 0.813084715 [5,] 0.000000000 0.00000000 0.00000000 0.000000000 16.104684572 [6,] 0.000000000 0.00000000 0.00000000 0.000000000 0.359607041 [7,] 0.000000000 0.00000000 0.00000000 0.000000000 1.465438735 [8,] 1.999986006 5.88035745 0.88936253 28.047461851 0.001058243 [9,] 0.008840393 0.00922767 0.01194492 0.009196537 0.022237738 [10,] -1.999978728 -1.99997873 -1.99997873 -1.999978728 -1.999978728 [11,] 9.816061412 5.87301046 1.53808136 6.068986990 0.405192278 [12,] -1.999976019 -1.99997602 -1.99997602 -1.999976019 -1.999976019 [,6] [,7] [,8] [,9] [,10] [,11] [1,] 0.00000000 0.000000000 1.0000000 0.000000 0.0000000 0.0000000 [2,] 0.00000000 0.000000000 2.9401993 0.000000 0.0000000 0.0000000 [3,] 0.73422440 0.180172844 0.0000000 1.445493 -1.0000000 0.0000000 [4,] 0.18607667 0.045661738 0.0000000 1.112903 -1.0000000 0.0000000 [5,] 0.35960704 1.465438735 0.0000000 0.000000 0.0000000 0.2028510 [6,] 17.59373439 6.403413493 0.0000000 0.000000 0.0000000 0.8863822 [7,] 6.40341349 42.117010509 0.0000000 0.000000 0.0000000 3.6121062 [8,] 0.20517924 485.856610499 -0.9947097 0.000000 0.0000000 0.0000000 [9,] 0.01146159 0.009048331 0.0000000 -0.871708 0.0000000 0.0000000 [10,] -1.99997873 -1.999978728 0.0000000 0.000000 -0.9934774 0.0000000 [11,] 1.77053714 7.215135980 0.0000000 0.000000 0.0000000 -0.9291531 [12,] -1.99997602 -1.999976019 0.0000000 0.000000 0.0000000 0.0000000 [,12] [1,] 0.0000000 [2,] 0.0000000 [3,] 0.0000000 [4,] 0.0000000 [5,] -1.0000000 [6,] -1.0000000 [7,] -1.0000000 [8,] 0.0000000 [9,] 0.0000000 [10,] 0.0000000 [11,] 0.0000000 [12,] -0.9930746 > > x <- GNE.nseq(z, dimx, dimlam, grobj=grfullob, NULL, heobj=hefullob, NULL, + constr=g, NULL, grconstr=grfullg, NULL, heconstr=hefullg, NULL, + compl=phiFB, gcompla=GrAphiFB, gcomplb=GrBphiFB, method="Newton", + control=list(trace=0, maxit=itermax)) > > print(x) GNE: 3.229317 0.183708 1.539436 2.548892 1.088479 1.088225 1.087213 -11.73454 10.00698 33.82558 397.174 893.934 with optimal norm 159.8344 after 10 iterations with exit code 4 . Output message: Iteration limit exceeded Function/grad/hessian calls: 59 10 Optimal (vector) value: 3.17503 5.585294 2.068223 -24.2716 -35.61146 -35.81163 -36.60984 107.3835 -0.2341082 10.47266 24.59725 93.67751 > summary(x) GNE: 3.229317 0.183708 1.539436 2.548892 1.088479 1.088225 1.087213 -11.73454 10.00698 33.82558 397.174 893.934 with optimal norm 159.8344 after 10 iterations with exit code 4 . > > > > > proc.time() user system elapsed 0.90 0.14 1.03