Start `BBsolve`

or `BBoptim`

from multiple starting
points to obtain multiple solutions and to test sensitivity to starting values.

1 2 3 4 5 |

`par` |
A real matrix, each row of which is an argument to |

`fn` |
see |

`gr` |
Only required for optimization. See |

`action` |
A character string indicating whether to solve a nonlinear system or to optimize. Default is “solve”. |

`method` |
see |

`upper` |
An upper bound for box constraints. See |

`lower` |
An lower bound for box constraints. See |

`project` |
A projection
function or character string indicating its name. The projection
function that takes a point in |

`projectArgs` |
A list with arguments to the |

`control` |
See |

`quiet` |
A logical variable (TRUE/FALSE). If |

`details` |
Logical indicating if the result should include the full
result from |

`...` |
arguments passed fn (via the optimization algorithm). |

The optimization or root-finder is run with each row of `par`

indicating
initial guesses.

list with elements `par`

, `values`

, and `converged`

.
It optionally returns an attribute called “details”, which is a list as long as
the number of starting values, which contains the complete object returned
by `dfsane`

or `spg`

for each starting value.

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/

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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | ```
# Use a preset seed so the example is reproducable.
require("setRNG")
old.seed <- setRNG(list(kind="Mersenne-Twister", normal.kind="Inversion",
seed=1234))
# Finding multiple roots of a nonlinear system
brownlin <- function(x) {
# Brown's almost linear system(A.P. Morgan, ACM 1983)
# two distinct solutions if n is even
# three distinct solutions if n is odd
n <- length(x)
f <- rep(NA, n)
nm1 <- 1:(n-1)
f[nm1] <- x[nm1] + sum(x) - (n+1)
f[n] <- prod(x) - 1
f
}
p <- 9
n <- 50
p0 <- matrix(rnorm(n*p), n, p) # n starting values, each of length p
ans <- multiStart(par=p0, fn=brownlin)
pmat <- ans$par[ans$conv, 1:p] # selecting only converged solutions
ord1 <- order(abs(pmat[,1]))
round(pmat[ord1, ], 3) # all 3 roots can be seen
# An optimization example
rosbkext <- function(x){
n <- length(x)
j <- 2 * (1:(n/2))
jm1 <- j - 1
sum(100 * (x[j] - x[jm1]^2)^2 + (1 - x[jm1])^2)
}
p0 <- rnorm(50)
spg(par=p0, fn=rosbkext)
BBoptim(par=p0, fn=rosbkext)
pmat <- matrix(rnorm(100), 20, 5) # 20 starting values each of length 5
ans <- multiStart(par=pmat, fn=rosbkext, action="optimize")
ans
attr(ans, "details")[[1]] #
pmat <- ans$par[ans$conv, 1:5] # selecting only converged solutions
round(pmat, 3)
``` |

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.