我正在使用scipy的fmin来最小化功能。有没有办法在同一图的顶部打印最小化的不同步骤,以便我可以看到进度?这是我要尽量减少的功能:
import numpy as np
import matplotlib.pylab as plt
def wave_func(func_params):
"""This function calculates the difference between a sinewave (sin(x)) and raw_data (different sin wave)
This is the function that will be minimized by modulating a, b, k, and h parameters in order to minimize
the difference between curves."""
a = 1
b = 1
k = 0
h = 0
y_wave = a * np.sin((x_vals-h)/b) + k
error = np.sum((y_wave - raw_data) * (y_wave - raw_data))
plt.plot(y_wave)
plt.show()
time.sleep(1)
return error
但是,这每次都会绘制不同的图,并且不可能遵循。