python - How Do I put 2 matrix into scipy.optimize.minimize? -


i work scipy.optimize.minimize function. purpose w,z minimize f(w,z)

both w , z n m matrices:

[[1,1,1,1],  [2,2,2,2]] 

f(w,z) receive parameter w , z.

i tried form given below:

def f(x):    w = x[0]    z = x[1]    ...  minimize(f, [w,z]) 

but, minimize not work well.

what valid form put 2 matrices (n m) scipy.optimize.minimize?

optimize needs 1d vector optimize. on right track. need flatten argument minimize , in f, start x = np.reshape(x, (2, m, n)) pull out w , z , should in business.

i've run issue before. example, optimizing parts of vectors in multiple different classes @ same time. typically wind function maps things 1d vector , function pulls data out objects can evaluate cost function. in:

def tovector(w, z):     assert w.shape == (2, 4)     assert z.shape == (2, 4)     return np.hstack([w.flatten(), z.flatten()])  def towz(vec):     assert vec.shape == (2*2*4,)     return vec[:2*4].reshape(2,4), vec[2*4:].reshape(2,4)  def dooptimization(f_of_w_z, w0, z0):     def f(x):          w, z = towz(x)         return f_of_w_z(w, z)      result = minimize(f, tovec(w0, z0))     # different optimize functions return     # vector result differently. in case it's result.x:     result.x = towz(result.x)      return result 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -