problems when using scipy.opti​mize.diffe​rential_ev​olution in Matlab environment

조회 수: 1 (최근 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?

답변 (1개)

Al Danial
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.

카테고리

Help CenterFile Exchange에서 Call MATLAB from Python에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by