problems when using scipy.optimize.differential_evolution in Matlab environment
5 次查看(过去 30 天)
显示 更早的评论
When i call a matlab function to be optimized with the inputs arguments i get 'not enough input' error.
For example; i have a matlab function called Residual.m that requires 5 input and returns one value.
Residual(state, N, freq, SNR, p)
My code is like this:
py_optimize = py.importlib.import_module('scipy.optimize');
N=2
bound = [-50, 500; -50, 500; -150, 150];
x_bound = repmat(bound, N, 1);
freq=10; SNR=30;
p=1;
data=py_optimize.differential_evolution(Residual,x_bound,disp=True, maxiter=4500, popsize=65, init='random', workers=worker, recombination=0.8, mutation=nn, strategy='best1bin', tol=0.001, updating='deferred');
When i run this, i get an error that there is not enough inputs.
I tried using matlabFunction with my fuction but i keep getting below error
Error using indexing
Handle to MATLAB function '@()' is not supported. Use a handle to a Python function.
What I'm i not doing right?
0 个评论
回答(1 个)
Al Danial
2023-6-4
scipy.optimize.differential_evolution() expects a Python function as its first argument. You'll need to translate Residual.m to Python, then pass this translated function as the first argument. I suppose in theory you could provide a Python wrapper to Residual.m then use the matlab.engine from Python to call Residual.m but I've not been successful with that combination.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Call MATLAB from Python 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!