# optimizelogpost: Optimize log of marginalized and reparameterized joint... In CARrampsOcl: Reparameterized and marginalized posterior sampling for conditional autoregressive models, OpenCL implementation

## Description

Optimize log of marginalized and reparameterized joint posterior.

## Usage

 `1` ```optimizelogpost(alpha, beta, D, y, By, k, func) ```

## Arguments

 `alpha` `beta` `D` `y` `By` `k` `func`

## Value

Maximum value of log posterior density.

Kate Cowles

## 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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91``` ```##---- Should be DIRECTLY executable !! ---- ##-- ==> Define data, use random, ##-- or do help(data=index) for the standard data sets. ## The function is currently defined as function( alpha,beta,D, y, By, k, func ) { # Note: this function needs to be made generic to accept different values # of F; right now it works only if F = 3. F <- ncol( D ) + 1 # F = number of precision parms (meas err precision and for all Q's) optimouts <- numeric() # We need to run optimization from different starting values to increase # chance of finding global max. if( F ==5 ) { optimout1 <- optim( c( 6/10, 1/10, 1/10, 1/10 ), func, alpha=alpha, beta = beta, D = D, y = y,By = By, k = k, control = list(fnscale = -1) )\$value optimout2 <- optim( c( 1/10, 1/10, 1/10, 1/10 ), func, alpha=alpha, beta = beta, D = D, y = y, By = By, k = k, control = list(fnscale = -1) )\$value optimout3 <- optim( c( 1/10, 1/10, 1/10, 6/10 ), func, alpha=alpha, beta = beta, D = D, y = y, By = By, k = k, control = list(fnscale = -1) )\$value optimout4 <- optim( c( 1/10, 1/10, 6/10, 1/10 ), func, alpha=alpha, beta = beta, D = D, y = y, By = By, k = k, control = list(fnscale = -1) )\$value optimout5 <- optim( c( 1/10, 6/10, 1/10, 1/10 ), func, alpha=alpha, beta = beta, D = D, y = y, By = By, k = k, control = list(fnscale = -1) )\$value gmax <- max( optimout1, optimout2, optimout3, optimout4, optimout5 ) } else if( F ==4 ) { optimout1 <- optim( c( 1/16, 3/16, 5/16 ), func, alpha=alpha, beta = beta, D = D, y = y,By = By, k = k, control = list(fnscale = -1) )\$value optimout2 <- optim( c( 3/16, 5/16, 7/16 ), func, alpha=alpha, beta = beta, D = D, y = y, By = By, k = k, control = list(fnscale = -1) )\$value optimout3 <- optim( c( 5/16, 7/16, 1/16 ), func, alpha=alpha, beta = beta, D = D, y = y, By = By, k = k, control = list(fnscale = -1) )\$value optimout4 <- optim( c( 7/16, 1/16, 3/16 ), func, alpha=alpha, beta = beta, D = D, y = y, By = By, k = k, control = list(fnscale = -1) )\$value gmax <- max( optimout1, optimout2, optimout3, optimout4 ) } else if( F ==3 ) { #optimout1 <- optim( c( 1/9 , 3/9 ), func, alpha=alpha, beta = beta, optimout1 <- optim( c( 1/6 , 1/2 ), func, alpha=alpha, beta = beta, D = D, y = y,By = By, k = k, control = list(fnscale = -1) )\$value optimout2 <- optim( c( 1/2 , 1/3 ), func, alpha=alpha, beta = beta, D = D, y = y, By = By, k = k, control = list(fnscale = -1) )\$value optimout3 <- optim( c( 1/3 , 1/6 ), func, alpha=alpha, beta = beta, D = D, y = y, By = By, k = k, control = list(fnscale = -1) )\$value gmax <- max( optimout1, optimout2, optimout3 ) } else if (F==2) { max1 <- optimize( func,c(0,0.5),alpha=alpha, beta = beta, D = D, y = y, By = By, k = k, maximum=T)\$objective max2 <- optimize( func,c(0.5,1.0), alpha=alpha, beta = beta, D = D, y = y, By = By, k = k, maximum=T)\$objective gmax<- max(max1,max2) } gmax } ```

CARrampsOcl documentation built on May 2, 2019, 3:27 a.m.