0

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) 
5
  • Please explain what mappingFun does in R. Commented Dec 1, 2022 at 10:00
  • Are you wanting a constraint of the parameters being within one standard deviation from the mean? Commented Dec 1, 2022 at 10:10
  • It used to standardize the output after each population is created, but before the population is passed to the objective function. Commented Dec 1, 2022 at 13:33
  • Could you provide a MWE so we can help further? Commented Dec 2, 2022 at 12:02
  • @AndrewNelson it's a bit difficult to provide a MWE, I just want to know is it possible to standardize the output (like calling a function and applying it on the output to standardize it) after each iteration before it goes for the next iteration for optimization. I have a list of 80 matrices which is getting optimized and gives an output list of 80 optimized values Commented Dec 5, 2022 at 9:58

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.