优化时模糊元素,fmin_powell

时间:2017-04-01 02:32:22

标签: python scipy

我在使用fmin_powell方法优化参数时遇到了问题。

coeff = np.array([1.,1.,1.,1.])

def run(coeff, *func):
     if np.any(coeff < 0): return (np.minimum(coeff, 0)**2 + 1) * 100000000.0
     else:
          [some math operations]
          return Energy

def optimize(f):
   return opt.fmin_powell(run, coeff, args=(f,f), disp=0)

f = ['1a','2b','3c', '4d', '5e', '6e', '7f', '8g']

p = Pool(processes=8)
async_ret = p.map(optimize,f,chunksize=1)
result = async_ret.get()
p.terminate()

即,我收到错误消息:

  async_ret = p.map(optimize,f,chunksize=1)
  File "/apps/anaconda/lib/python2.7/multiprocessing/pool.py", line 251, in map
    return self.map_async(func, iterable, chunksize).get()
  File "/apps/anaconda/lib/python2.7/multiprocessing/pool.py", line 567, in get
    raise self._value
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

我认为问题出现了问题:if np.any(coeff < 0): return (np.minimum(coeff, 0)**2 + 1) * 100000000.0但是,我没有发现错误。

有人看到问题所在吗?

0 个答案:

没有答案