我有一个优化器,它获得2-d初始点,并产生一个2-d的答案。以下是其中红点是初始点而蓝点是解的图。
当我在循环中进行如下操作时,我看不到解点的密度。
import matplotlib.pyplot as plt
exp = 100
for i in range(exp):
fx = convex()
#plotting initial points
plt.scatter(fx.x[0],fx.x[1], c='r',s=1)
#Finding optimal solution
while fx.fvalue() > 1e-4:
fx.new_x(l2=True, alpha = 6, sgd = True)
#plotting optimal solution
plt.scatter(fx.x[0],fx.x[1], c='b', s=1)
plt.xlabel('x')
plt.ylabel('y')
plt.legend(['Initial values', 'Solutions'])
fx
是convex
类的实例,该类具有x
作为其属性并被随机初始化,然后在while循环中进行更新。
我希望动态地或至少在结束for
循环之后才能看到解点的累积。