0
我想將Matlab代碼轉換爲Jython版本,並發現Matlab中的fminsearch可能會被Apache-Common-Math-Optimization所取代。 我正在編寫Mango Medical Image腳本管理器,它使用Jython 2.5.3作爲編碼語言。 Math版本是3.6.1。 這裏是我的代碼:如何在Jython中使用Apache Commons Math Optimization?
def f(x,y):
\t return x^2+y^2
sys.path.append('/home/shujian/APPs/Mango/lib/commons-math3-3.6.1.jar')
sys.add_package('org.apache.commons.math3.analysis')
from org.apache.commons.math3.analysis import MultivariateFunction
sys.add_package('org.apache.commons.math3.optim.nonlinear.scalar.noderiv')
from org.apache.commons.math3.optim.nonlinear.scalar.noderiv import NelderMeadSimplex,SimplexOptimizer
sys.add_package('org.apache.commons.math3.optim.nonlinear.scalar')
from org.apache.commons.math3.optim.nonlinear.scalar import ObjectiveFunction
sys.add_package('org.apache.commons.math3.optim')
from org.apache.commons.math3.optim import MaxEval,InitialGuess
sys.add_package('org.apache.commons.math3.optimization')
from org.apache.commons.math3.optimization import GoalType
initialSolution=[2.0,2.0]
simplex=NelderMeadSimplex([2.0,2.0])
opt=SimplexOptimizer(2**(-6), 2**(-10))
solution=opt.optimize(MaxEval(300),ObjectiveFunction(f),simplex,GoalType.MINIMIZE,InitialGuess([2.0,2.0]))
skewParameters2 = solution.getPointRef()
print skewParameters2;
而且我得到了以下錯誤:
TypeError: optimize(): 1st arg can't be coerced to
我很困惑如何使用優化在Jython中,例子都是Java版本。