admin管理员组文章数量:1401247
I am trying to minimise a complex problem (non-linear) with differential_evolution
method in scipy. Key syntaxes are given below
a) I am creating an object assigned to differential_evolution
res = differential_evolution(self.loss_function,x0,bounds,args=(input_series, ilt,bhpgrad,q_obs), streategy='belst1bin', maxiter=1000, popsize=15, disp =True, tol=1e-6 )
b) bounds
are provided as tuples in the following form, the len(bounds) == len(x)
bounds = [ (0,1000), (0,1000),........ , (-1000,1000)]
depending on the nature of corresponding elements in x.
c) loss-function is part of a class, the definition of the self
is accomplished through def __init__()
.
def loss_function(self, x, input_series,ilt,bhpgrad, q_obs):
Note that there are 4 constants which shall not be optimized by differential_evolutions, but needs to execute them. These constants are being passed through args = (.......)
method.
I get the following error:
res = differential_evolution(self.loss_function,x0,bounds,args=(input_series, ilt,bhpgrad,q_obs), \
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: differential_evolution() got multiple values for argument 'args'
I don't understand why this is happening or how to fix it.
I am trying to minimise a complex problem (non-linear) with differential_evolution
method in scipy. Key syntaxes are given below
a) I am creating an object assigned to differential_evolution
res = differential_evolution(self.loss_function,x0,bounds,args=(input_series, ilt,bhpgrad,q_obs), streategy='belst1bin', maxiter=1000, popsize=15, disp =True, tol=1e-6 )
b) bounds
are provided as tuples in the following form, the len(bounds) == len(x)
bounds = [ (0,1000), (0,1000),........ , (-1000,1000)]
depending on the nature of corresponding elements in x.
c) loss-function is part of a class, the definition of the self
is accomplished through def __init__()
.
def loss_function(self, x, input_series,ilt,bhpgrad, q_obs):
Note that there are 4 constants which shall not be optimized by differential_evolutions, but needs to execute them. These constants are being passed through args = (.......)
method.
I get the following error:
res = differential_evolution(self.loss_function,x0,bounds,args=(input_series, ilt,bhpgrad,q_obs), \
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: differential_evolution() got multiple values for argument 'args'
I don't understand why this is happening or how to fix it.
Share Improve this question edited Mar 23 at 14:20 Nick ODell 25.8k7 gold badges46 silver badges88 bronze badges asked Mar 23 at 7:47 MuraliMurali 213 bronze badges1 Answer
Reset to default 1Per the documentation, the argument list is as follows:
differential_evolution(func, bounds, args=(), strategy='best1bin', maxiter=1000, popsize=15, tol=0.01, mutation=(0.5, 1), recombination=0.7, rng=None, callback=None, disp=False, polish=True, init='latinhypercube', atol=0, updating='immediate', workers=1, constraints=(), x0=None, *, integrality=None, vectorized=False)
So, if you pass positional arguments, the first one will be func
, the second bounds
, the third args
, etc. You pass 3 positional arguments before switching to keyword arguments, so scipy is interpreting x0
as bounds
and bounds
as your args
, and then you have a keyword argument for args
so scipy thinks you're passing it twice. The simple fix is to move x0
later in your argument list and pass it as a keyword argument. Or, just use keyword arguments for everything.
本文标签: pythonSolution to syntax problem in using quotdifferentialevolution()quot in scipyStack Overflow
版权声明:本文标题:python - Solution to syntax problem in using "differential_evolution()" in scipy - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744293802a2599243.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论