Skip to content

Commit

Permalink
Rsolnp bug with multiple start points when unif+cos(1) models are
Browse files Browse the repository at this point in the history
specified
  • Loading branch information
David Lawrence Miller committed Oct 3, 2014
1 parent 8c62020 commit cb5f248
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 23 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ Description: This package implements mark-recapture distance sampling
J.L., Southwell, C. and Paxton, C.L.G. "Accommodating unmodelled
heterogeneity in double-observer distance sampling surveys". 2006.
Biometrics 62:372-378.)
Version: 2.1.10
Date: 2014-09-27
Version: 2.1.11
Date: 2014-10-3
Depends:
R (>= 3.0)
Suggests:
Expand Down
6 changes: 6 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
mrds 2.1.11
-----------

* Bug in unif+cos(1) models when using monotonicity constraints and randomised starting points. Since the model only has 1 parameter, there is a bug in selecting columns in Rsolnp starting value code that makes the result be a vector, which then doesn't work with an apply later. Workaround of not using randomised starting values in mrds for that model. Thanks to Nathalie Cavada for finding this bug.


mrds 2.1.10
-----------

Expand Down
49 changes: 28 additions & 21 deletions R/detfct.fit.opt.R
Original file line number Diff line number Diff line change
Expand Up @@ -135,27 +135,34 @@ detfct.fit.opt <- function(ddfobj, optim.options, bounds, misc.options,
lowerbounds.ic <- rep(0,2*misc.options$mono.points)
upperbounds.ic <- rep(10^10,2*misc.options$mono.points)

#lt<-try(solnp(pars=initialvalues, fun=flnl, eqfun=NULL, eqB=NULL,
# ineqfun=flnl.constr,
# ineqLB=lowerbounds.ic, ineqUB=upperbounds.ic,
# LB=lowerbounds, UB=upperbounds,
# ddfobj=ddfobj, misc.options=misc.options,
# control=list(trace=as.integer(showit),
# tol=misc.options$mono.tol,
# delta=misc.options$mono.delta)))

# this code randomly generates starting values see ?gosolnp
lt<-try(gosolnp(pars=initialvalues, fun=flnl, eqfun=NULL, eqB=NULL,
ineqfun=flnl.constr,
ineqLB=lowerbounds.ic, ineqUB=upperbounds.ic,
LB=lowerbounds, UB=upperbounds,
ddfobj=ddfobj, misc.options=misc.options,
control=list(trace=as.integer(showit),
tol=misc.options$mono.tol,
delta=misc.options$mono.delta),
distr = rep(1, length(lowerbounds)),
n.restarts = 2, n.sim = 200,
rseed=as.integer(runif(1)*1e9)))
if(length(initialvalues)==1){
## gosolnp (below) doesn't work when there is only 1 parameter
## since there is a bug that leaves the optimisation with a vector
## when it is expecting a matrix. To avoid this bug, don't do the
## multiple start points in that case (should only be unif+cos(1))
## models for us.
lt<-try(solnp(pars=initialvalues, fun=flnl, eqfun=NULL, eqB=NULL,
ineqfun=flnl.constr,
ineqLB=lowerbounds.ic, ineqUB=upperbounds.ic,
LB=lowerbounds, UB=upperbounds,
ddfobj=ddfobj, misc.options=misc.options,
control=list(trace=as.integer(showit),
tol=misc.options$mono.tol,
delta=misc.options$mono.delta)))
}else{
# this code randomly generates starting values see ?gosolnp
lt<-try(gosolnp(pars=initialvalues, fun=flnl, eqfun=NULL, eqB=NULL,
ineqfun=flnl.constr,
ineqLB=lowerbounds.ic, ineqUB=upperbounds.ic,
LB=lowerbounds, UB=upperbounds,
ddfobj=ddfobj, misc.options=misc.options,
control=list(trace=as.integer(showit),
tol=misc.options$mono.tol,
delta=misc.options$mono.delta),
distr = rep(1, length(lowerbounds)),
n.restarts = 2, n.sim = 200,
rseed=as.integer(runif(1)*1e9)))
}


# if that failed then make a dummy object
Expand Down

0 comments on commit cb5f248

Please sign in to comment.