0

I am trying to use scipy.optimize.minimze to minimize the objective function as follows.

import numpy as np
from scipy import optimize
max_q_fun = lambda q : -q     
def max_q_min(args):
        cons = args 
        res = optimize.minimize(max_q_fun, (0.1), method='SLSQP', bounds = ((0,1),), constraints=cons)
        q = res.x
        return q 
total_counts = np.arange(0,10)
num_actions = 10         
args = [({'type': 'ineq', 'fun': lambda q: total_counts[act] * 
                 (p[act] * np.log(p[act] / q) + (1-p[act]) * np.log((1-p[act]) / (1-q))) - np.log(10)}) 
                for act in range(num_actions)]
pl = Pool(num_actions)
actions = pl.map(max_q_min,args)
current_action = np.argmax(actions)

However, if I use Pool by from pathos.multiprocessing import ProcessingPool as Pool the error shows that

NameError: name 'np' is not defined

If I use Pool by from multiprocessing import Pool, the error shows that AttributeError: Can't pickle local object 'kl_ucb.act.<locals>.max_q_min'.

Any idea how I can use parallel computing for different constraints ?

exteral
  • 991
  • 2
  • 12
  • 33

0 Answers0