Ich habe eine glatte Funktion f (x) = sin (x/5) * exp (x/10) + 5 * exp (-x/2) Die Aufgabe ist ein Minimum einer nicht-glatten Funktion h (x) = int (f (x)) im Intervall von 1 bis 30 zu finden. Mit anderen Worten, jeder Wert von f (x) wird in den Typ int und die Funktion umgewandelt nimmt nur ganzzahlige Werte an.Scipy.optimize differential_evolution Indexfehler: Tupelindex außerhalb des Bereichs
Ich verwende 2 Methoden, um ein Minimum von scipy.optimize zu finden: minimieren und differential_evolution. Das Minimieren gibt mir das Ergebnis -5 wohingegen differential_evolution gibt Index-Fehler: Tupel-Index außerhalb des Bereichs Die Frage ist, warum und was ist falsch? Hier
ist der Code:
import math
import numpy as np
from scipy.optimize import minimize
from scipy.optimize import differential_evolution
from scipy.linalg import *
import matplotlib.pyplot as plt
def f(x):
return np.sin(x/5.0) * np.exp(x/10.0) + 5 * np.exp((-x/2.0))
def h(x):
return f(x).astype(int)
x = np.arange(1, 30)
y = h(x)
plt.plot(x, y)
plt.show()
#res = minimize(h, 30, method='BFGS')
#print res
res = differential_evolution(h, [1, 30])
print res
Zur gleichen Zeit funktioniert die differential_evolution-Methode gut für die anfängliche glatte Funktion - res = differential_evolution (f, [1, 30]) – plywoods