BBsolve: Solving Nonlinear System of Equations - A Wrapper for...

Description Usage Arguments Details Value References See Also Examples

View source: R/BBsolve.R

Description

A strategy using different Barzilai-Borwein steplengths to solve a nonlinear system of equations.

Usage

1
2
3
  BBsolve(par, fn, method=c(2,3,1), 
	control=list(), quiet=FALSE, ...) 
  

Arguments

par

A real vector argument to fn, indicating the initial guess for the root of the nonliinear system of equations fn.

fn

Nonlinear system of equation that is to be solved. A vector function that takes a real vector as argument and returns a real vector of the same length.

method

A vector of integers specifying which Barzilai-Borwein steplengths should be used in a consecutive manner. The methods will be used in the order specified.

control

A list of parameters governing the algorithm behaviour. This list is the same as that for dfsane and sane (excepting the default for trace). See details for important special features of control parameters.

quiet

logical indicating if messages about convergence success or failure should be suppressed

...

arguments passed fn (via the optimization algorithm).

Details

This wrapper is especially useful in problems where the algorithms (dfsane or sane) are likely to experience difficulties in convergence. When these algorithms with default parameters fail, i.e. when convergence > 0 is obtained, a user might attempt various strategies to find a root of the nonlinear system. The function BBsolve tries the following sequential strategy:

  1. Try a different BB steplength. Since the default is method = 2 for dfsane, the BBsolve wrapper tries method = c(2, 1, 3).

  2. Try a different non-monotonicity parameter M for each method, i.e. BBsolve wrapper tries M = c(50, 10) for each BB steplength.

  3. Try with Nelder-Mead initialization. Since the default for dfsane is NM = FALSE, BBsolve does NM = c(TRUE, FALSE).

The argument control defaults to a list with values maxit = 1500, M = c(50, 10), tol = 1e-07, trace = FALSE, triter = 10, noimp = 100, NM = c(TRUE, FALSE). If control is specified as an argument, only values which are different need to be given in the list. See dfsane for more details.

Value

A list with the same elements as returned by dfsane or sane. One additional element returned is cpar which contains the control parameter settings used to obtain successful convergence, or to obtain the best solution in case of failure.

References

R Varadhan and PD Gilbert (2009), BB: An R Package for Solving a Large System of Nonlinear Equations and for Optimizing a High-Dimensional Nonlinear Objective Function, J. Statistical Software, 32:4, http://www.jstatsoft.org/v32/i04/

See Also

BBoptim, dfsane, sane multiStart

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Use a preset seed so test values are reproducable. 
require("setRNG")
old.seed <- setRNG(list(kind="Mersenne-Twister", normal.kind="Inversion",
    seed=1234))

broydt <- function(x) {
n <- length(x)
f <- rep(NA, n)
h <- 2
f[1] <- ((3 - h*x[1]) * x[1]) - 2*x[2] + 1
tnm1 <- 2:(n-1)
f[tnm1] <- ((3 - h*x[tnm1]) * x[tnm1]) - x[tnm1-1] - 2*x[tnm1+1] + 1
f[n] <- ((3 - h*x[n]) * x[n]) - x[n-1] + 1
f
}

p0 <- rnorm(50)
BBsolve(par=p0, fn=broydt)  # this works 
dfsane(par=p0, fn=broydt) # but this is highly unliikely to work.

# this implements the 3 BB steplengths with M = 50, and without Nelder-Mead initialization
BBsolve(par=p0, fn=broydt, control=list(M=50, NM=FALSE))

# this implements BB steplength 1 with M = 50 and 10, and both with and 
#   without Nelder-Mead initialization  
BBsolve(par=p0, fn=broydt, method=1, control=list(M=c(50, 10))) 

# identical to dfsane() with defaults
BBsolve(par=p0, fn=broydt, method=2, control=list(M=10, NM=FALSE)) 

Example output

Loading required package: setRNG
  Successful convergence.
$par
 [1] -0.5707612 -0.6819101 -0.7024859 -0.7062605 -0.7069519 -0.7070784
 [7] -0.7071015 -0.7071058 -0.7071066 -0.7071067 -0.7071067 -0.7071068
[13] -0.7071068 -0.7071068 -0.7071068 -0.7071068 -0.7071068 -0.7071068
[19] -0.7071068 -0.7071068 -0.7071068 -0.7071068 -0.7071068 -0.7071068
[25] -0.7071068 -0.7071068 -0.7071068 -0.7071068 -0.7071068 -0.7071068
[31] -0.7071068 -0.7071068 -0.7071068 -0.7071067 -0.7071067 -0.7071065
[37] -0.7071061 -0.7071050 -0.7071019 -0.7070933 -0.7070700 -0.7070063
[43] -0.7068325 -0.7063577 -0.7050615 -0.7015252 -0.6918946 -0.6657975
[49] -0.5960353 -0.4164123

$residual
[1] 9.385509e-08

$fn.reduction
[1] 31.59999

$feval
[1] 281

$iter
[1] 255

$convergence
[1] 0

$message
[1] "Successful convergence"

$cpar
method      M     NM 
     3     50      0 

Iteration:  0  ||F(x0)||:  4.468913 
iteration:  10  ||F(xn)|| =   7.372656 
iteration:  20  ||F(xn)|| =   2.148256 
iteration:  30  ||F(xn)|| =   1.087926 
iteration:  40  ||F(xn)|| =   1.837539 
iteration:  50  ||F(xn)|| =   1.227962 
iteration:  60  ||F(xn)|| =   1.173819 
iteration:  70  ||F(xn)|| =   1.164419 
iteration:  80  ||F(xn)|| =   1.116905 
iteration:  90  ||F(xn)|| =   1.126721 
iteration:  100  ||F(xn)|| =   1.112744 
iteration:  110  ||F(xn)|| =   1.113586 
iteration:  120  ||F(xn)|| =   1.115942 
iteration:  130  ||F(xn)|| =   1.112886 
$par
 [1] -0.5706552 -0.6837528 -0.7044984 -0.7057360 -0.7087213 -0.7061261
 [7] -0.6987339 -0.6990289 -0.7070646 -0.7002412 -0.7064187 -0.7075855
[13] -0.7067219 -0.7016219 -0.6943348 -0.6600190 -0.5448951 -0.1804689
[19]  0.6734614  1.5312355 -0.1678685 -0.5997800 -0.6774198 -0.7063091
[25] -0.7050525 -0.7029759 -0.7094338 -0.7060808 -0.7104785 -0.6995702
[31] -0.7145343 -0.6990088 -0.7072191 -0.6836870 -0.6969368 -0.6938772
[37] -0.6985233 -0.7016326 -0.7064762 -0.7041186 -0.7080469 -0.7058380
[43] -0.7078563 -0.7050803 -0.7057069 -0.7008472 -0.6920625 -0.6656979
[49] -0.5960234 -0.4164090

$residual
[1] 0.1538559

$fn.reduction
[1] 30.51206

$feval
[1] 456

$iter
[1] 130

$convergence
[1] 5

$message
[1] "Lack of improvement in objective function"

Warning message:
In dfsane(par = p0, fn = broydt) : Unsuccessful convergence.
  Successful convergence.
$par
 [1] -0.5707612 -0.6819101 -0.7024859 -0.7062605 -0.7069519 -0.7070784
 [7] -0.7071015 -0.7071058 -0.7071066 -0.7071067 -0.7071067 -0.7071068
[13] -0.7071068 -0.7071068 -0.7071068 -0.7071068 -0.7071068 -0.7071068
[19] -0.7071068 -0.7071068 -0.7071068 -0.7071068 -0.7071068 -0.7071068
[25] -0.7071068 -0.7071068 -0.7071068 -0.7071068 -0.7071068 -0.7071068
[31] -0.7071068 -0.7071068 -0.7071068 -0.7071067 -0.7071067 -0.7071065
[37] -0.7071061 -0.7071050 -0.7071019 -0.7070933 -0.7070700 -0.7070063
[43] -0.7068325 -0.7063577 -0.7050615 -0.7015252 -0.6918946 -0.6657975
[49] -0.5960353 -0.4164123

$residual
[1] 9.385509e-08

$fn.reduction
[1] 31.59999

$feval
[1] 281

$iter
[1] 255

$convergence
[1] 0

$message
[1] "Successful convergence"

$cpar
method      M     NM 
     3     50      0 

  Successful convergence.
$par
 [1] -0.5707611 -0.6819101 -0.7024861 -0.7062606 -0.7069518 -0.7070784
 [7] -0.7071016 -0.7071058 -0.7071066 -0.7071067 -0.7071068 -0.7071068
[13] -0.7071068 -0.7071068 -0.7071068 -0.7071068 -0.7071068 -0.7071068
[19] -0.7071068 -0.7071068 -0.7071068 -0.7071068 -0.7071068 -0.7071068
[25] -0.7071068 -0.7071068 -0.7071068 -0.7071068 -0.7071068 -0.7071068
[31] -0.7071068 -0.7071068 -0.7071068 -0.7071067 -0.7071067 -0.7071065
[37] -0.7071061 -0.7071050 -0.7071019 -0.7070933 -0.7070700 -0.7070063
[43] -0.7068325 -0.7063577 -0.7050615 -0.7015252 -0.6918946 -0.6657975
[49] -0.5960353 -0.4164123

$residual
[1] 6.796092e-08

$fn.reduction
[1] 31.59999

$feval
[1] 54

$iter
[1] 31

$convergence
[1] 0

$message
[1] "Successful convergence"

$cpar
method      M     NM 
     1     50      0 

  Unsuccessful convergence.
$par
 [1] -0.5706552 -0.6837528 -0.7044984 -0.7057360 -0.7087213 -0.7061261
 [7] -0.6987339 -0.6990289 -0.7070646 -0.7002412 -0.7064187 -0.7075855
[13] -0.7067219 -0.7016219 -0.6943348 -0.6600190 -0.5448951 -0.1804689
[19]  0.6734614  1.5312355 -0.1678685 -0.5997800 -0.6774198 -0.7063091
[25] -0.7050525 -0.7029759 -0.7094338 -0.7060808 -0.7104785 -0.6995702
[31] -0.7145343 -0.6990088 -0.7072191 -0.6836870 -0.6969368 -0.6938772
[37] -0.6985233 -0.7016326 -0.7064762 -0.7041186 -0.7080469 -0.7058380
[43] -0.7078563 -0.7050803 -0.7057069 -0.7008472 -0.6920625 -0.6656979
[49] -0.5960234 -0.4164090

$residual
[1] 0.1538559

$fn.reduction
[1] 30.51206

$feval
[1] 456

$iter
[1] 130

$convergence
[1] 5

$message
[1] "Lack of improvement in objective function"

$cpar
method      M     NM 
     2     10      0 

BB documentation built on Oct. 30, 2019, 11:41 a.m.