# Below is an example showing how to create functions needed to generate MaxPro design manually by
# continuous.optim without using the maxpro.optim function in the package.
compute.distance.matrix <- function(A){
log_prod_metric = function(x, y) 2 * sum(log(abs(x-y)))
return (c(proxy::dist(A, log_prod_metric)))
}
optim.obj = function(x){
D = matrix(x, nrow=n, ncol=p)
d = exp(compute.distance.matrix(D))
d_matrix = matrix(0, n, n)
d_matrix[lower.tri(d_matrix)] = d
d_matrix = d_matrix + t(d_matrix)
fn = sum(1/d)
lfn = log(fn)
I = diag(n)
diag(d_matrix) = rep(1,n)
A = B = D
for(j in 1:p)
{
A = t(outer(D[,j], D[,j], "-"))
diag(A) = rep(1, n)
B[, j] = diag((1/A - I) %*% (1/d_matrix - I))
}
grad = 2 * B / fn
return(list("objective"=lfn, "gradient"=grad))
}
n = 20
p = 3
D.ini = maxproLHD(n, p)$design
D = continuous.optim(D.ini, optim.obj)
Run the code above in your browser using DataLab