problems when using scipy.optimize.differential_evolution in Matlab environment
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Al Danial
il 4 Giu 2023
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 Commenti
Vedere anche
Categorie
Scopri di più su Call MATLAB from Python in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!