I want to replicate this function
opt_object <- DEoptim(fn = optimFunctionDT, lower = lower, upper = upper, fnMap = mappingFun, control = DEoptim.control(trace = 500, itermax = 5000, steptol = 1000), lt_scores, ncol(lt_scores), list_matrices_def, cohort_sizes_def)
in python where mappingFun is
mappingFun <- function(x){
rho <- x[1]
zvec <- tail(x, -1)
m <- mean(zvec)
s <- sqrt(sum((zvec-m)^2)/(length(zvec)-1))
zvec <- (zvec-m)/s
c(rho, zvec)
}
I am using scipy.optimize.differential_evolution in python for replicating this function, but there is no fnMap parameter in this function. I am not able to understand where does the mappingFun go in the scipy.optimize.differential_evolution function.
This is what I have tried, but the outputs are not matching. I have used fnMap as a constraint
opt_object = scipy.optimize.differential_evolution(func = optimFunctionDT, bounds = bounds, args = (lt_scores, np.size(lt_scores,1), list_matrices, cohort_sizes), strategy = 'best1bin', maxiter = 5000, popsize = 15, tol = 0.01, mutation = (0.5, 1), recombination = 0.7, seed = 1234, callback = None, disp = False, polish = True, init = 'latinhypercube', atol = 0, updating = 'immediate', workers = 1, constraints = (nlc), x0 = None)
def mappingFun(x):
rho = x[0]
zvec = np.delete(x,0)
m = np.mean(zvec)
s = np.sqrt(sum(np.square(zvec - m)) / (len(zvec) - 1))
zvec = (zvec - m) / s
arr=np.insert(zvec, 0, rho)
return (arr)
nlc = NonlinearConstraint(mappingFun, 0, 1)