Skip to content

Commit

Permalink
Version 0.8.6.2. Merge branch 'devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
braunm committed Mar 28, 2018
2 parents 3bb65b7 + d5c8088 commit b0a8522
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 107 deletions.
10 changes: 5 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: trustOptim
Type: Package
Title: Trust Region Optimization for Nonlinear Functions with Sparse Hessians
Version: 0.8.6.1
Date: 2017-10-05
Version: 0.8.6.2
Date: 2018-03-26
Authors@R: person(given="Michael", family="Braun", email="[email protected]", role=c("aut","cre","cph"))
Maintainer: Michael Braun <[email protected]>
URL: http://coxprofs.cox.smu.edu/braunm
Expand All @@ -11,16 +11,16 @@ Description: Trust region algorithm for nonlinear optimization. Efficient when
cross-partial derivatives). See Braun, M. (2014) <doi:10.18637/jss.v060.i04>.
License: MPL (>= 2.0)
Depends:
R (>= 3.4.2)
R (>= 3.4.0)
Suggests:
testthat,
knitr
Imports:
Matrix (>= 1.2.8),
Matrix (>= 1.2.12),
Rcpp (>= 0.12.13),
methods
LinkingTo: Rcpp, RcppEigen (>= 0.3.3.3.0)
Copyright: (c) 2015-2017 Michael Braun
Copyright: (c) 2015-2018 Michael Braun
Roxygen: list(wrap=FALSE)
VignetteBuilder: knitr
SystemRequirements: C++11
Expand Down
6 changes: 6 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@

NEWS for trustOptim package


VERSION 0.8.6.2 (March 26, 2018)

- Removed deprecated Matrix package functions rBind and cBind, and
replaced them with their rbind and cbind counterparts.

VERSION 0.8.6.1 (October 6, 2017)

- Modified registration of native routines in src/init.c to be
Expand Down
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@

## NEWS for trustOptim package


VERSION 0.8.6.2 (March 26, 2018)

- Removed deprecated Matrix package functions rBind and cBind, and
replaced them with their rbind and cbind counterparts.


VERSION 0.8.6.1 (October 6, 2017)

- Modified registration of native routines in src/init.c to be
Expand Down
2 changes: 1 addition & 1 deletion R/binary.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ binary.hess <- function(P, data, priors, order.row=FALSE) {
}

Bmu <- .d2.dmu(N,SX, XO)
res <- rBind(cBind(B2, Matrix::t(cross)),cBind(cross, Bmu))
res <- rbind(cbind(B2, Matrix::t(cross)),cbind(cross, Bmu))

return(res)
}
Expand Down
6 changes: 3 additions & 3 deletions inst/doc/trustOptim-demo.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ options(scipen=999)

## ---- echo=FALSE---------------------------------------------------------
M <- as(kronecker(diag(N),matrix(1,k,k)),"lMatrix")
M <- rBind(M, Matrix(TRUE,k,N*k))
M <- cBind(M, Matrix(TRUE, k*(N+1), k))
M <- rbind(M, Matrix(TRUE,k,N*k))
M <- cbind(M, Matrix(TRUE, k*(N+1), k))
print(M)

## ------------------------------------------------------------------------
Expand All @@ -37,7 +37,7 @@ priors <- list(inv.Sigma = rWishart(1,k+5,diag(k))[,,1],
## ------------------------------------------------------------------------

opt <- trust.optim(start, fn=binary.f,
gr = binary.grad,
gr = binary.grad,
hs = binary.hess,
method = "Sparse",
control = list(
Expand Down
19 changes: 9 additions & 10 deletions inst/doc/trustOptim-demo.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ methods. It has more of a focus on how to use the package.

The need to optimize continuous nonlinear functions occurs frequently
in statistics, most notably in maximum likelihood and _maximum a
posteriori_ (MAP) estimation. Users of **R**
posteriori_ (MAP) estimation. Users of **R**
have a choice of dozens of optimization algorithms. The most readily
available algorithms are those that are accessed from the `optim`
function in the base *R* distribution, and from the many contributed
Expand All @@ -47,7 +47,7 @@ Hessian. However, if the algorithm stores the entire dense
inverse Hessian, its use is resource-intensive when the number of
parameters is large. For example, the Hessian for a 50,000 parameter
model requires 20GB of RAM to store it as a standard, dense base
**R** matrix.
**R** matrix.

The *trustOptim* package provides a trust region algorithm that is optimized for problems for which the
Hessian is sparse. Sparse Hessians occur when a large number of the
Expand Down Expand Up @@ -81,7 +81,7 @@ $$
p_i=\frac{\exp(x_i'\beta_i)}{1+\exp(x_i'\beta_i)},~i=1 ... N
$$

The coefficients can be thought of as sensitivities to the covariates, and they are distributed across the population of households following a multivariate normal distribution with mean $\mu$ and covariance $\Sigma$. We assume that we know $\Sigma$, but we do not know $\mu$. Instead, we place a multivariate normal prior on $\mu$, with mean $0$ and covariance $\Omega_0$. Thus, each $\beta_i$, and $\mu$ are $k-$dimensional vectors, and the total number of unknown variables in the model is $(N+1)k$.
The coefficients can be thought of as sensitivities to the covariates, and they are distributed across the population of households following a multivariate normal distribution with mean $\mu$ and covariance $\Sigma$. We assume that we know $\Sigma$, but we do not know $\mu$. Instead, we place a multivariate normal prior on $\mu$, with mean $0$ and covariance $\Omega_0$. Thus, each $\beta_i$, and $\mu$ are $k-$dimensional vectors, and the total number of unknown variables in the model is $(N+1)k$.

The log posterior density, ignoring any normalization constants, is
$$
Expand Down Expand Up @@ -123,17 +123,16 @@ if $N=`r N`$ and $k=`r k`$, then there are `r nv1` total variables, and the Hess

```{r, echo=FALSE}
M <- as(kronecker(diag(N),matrix(1,k,k)),"lMatrix")
M <- rBind(M, Matrix(TRUE,k,N*k))
M <- cBind(M, Matrix(TRUE, k*(N+1), k))
M <- rbind(M, Matrix(TRUE,k,N*k))
M <- cbind(M, Matrix(TRUE, k*(N+1), k))
print(M)
```

There are `r nels1` elements in this symmetric matrix, but only `r nnz1` are
non-zero, and only `r nnz1LT` values are unique. Although the reduction in
RAM from using a sparse matrix structure for the Hessian may be
modest, consider what would happen if $N=`r Q`$ instead. In that case,
there are `r nv2` variables in the problem, and more than $`r
floor(nels2/10^6)`$ million
there are `r nv2` variables in the problem, and more than $`r floor(nels2/10^6)`$ million
elements in the Hessian. However, only $`r nnz2`$ of those elements are
non-zero. If we work with only the lower triangle of the Hessian we only need to work with
only `r nnz2LT` values.
Expand Down Expand Up @@ -163,7 +162,7 @@ start <- rnorm(nvars) ## random starting values
priors <- list(inv.Sigma = rWishart(1,k+5,diag(k))[,,1],
inv.Omega = diag(k))
```

This dataset represents the simulated choices for $N= `r N`$ customers
over $T= `r binary$T`$ purchase opportunties, where the probability of purchase
is influenced by $k= `r k`$ covariates.
Expand All @@ -182,7 +181,7 @@ compressed sparse matrix class defined in the Matrix package.
```{r}
opt <- trust.optim(start, fn=binary.f,
gr = binary.grad,
gr = binary.grad,
hs = binary.hess,
method = "Sparse",
control = list(
Expand All @@ -196,7 +195,7 @@ opt <- trust.optim(start, fn=binary.f,
),
data=binary, priors=priors
)
```
```



Expand Down
Loading

0 comments on commit b0a8522

Please sign in to comment.