学习凸优化和线性代数

一、知识点

1.plt.plot画图

连接点是plot([x,y],[x1,y1]),结果画出来的图总是错误的,正确的操作应该是plot([x,x1],[y,y1])

2.import scipy.optimize as sco有两个求最小值的函数,fminbound寻找给定范围内的最小值,fmin_bfgs寻找给定值的局部最小值

3.scipy.optimize.brute(func, rangeargs =()Ns = 20full_output = 0finish = disp = False ) 求解函数全局最优权重https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.brute.html

4.pandas高级功能:面板数据、字符串方法、分类、可视化。面板数据分为一维series、二维dataframe、三维panel;支持字符串方法。

.swapaxes('items', 'minor')将items和minor的数据转换

如下:

Dimensions: 5 (items) x 503 (major_axis) x 12 (minor_axis)

Items axis: us.IXIC to usGOOG

Major_axis axis: 2016-12-05 00:00:00 to 2018-12-03 00:00:00

Minor_axis axis: close to atr14

Dimensions: 12 (items) x 503 (major_axis) x 5 (minor_axis)

Items axis: close to atr14

Major_axis axis: 2016-12-05 00:00:00 to 2018-12-03 00:00:00

Minor_axis axis: us.IXIC to usGOOG

(https://blog.csdn.net/pipisorry/article/details/53486777)

5.mat, linalg :求特征值和特征向量;

二、凸优化模型

import numpyas np

import scipy.optimizeas sco

from scipy.interpolateimport interp1d

from abupyimport ABuSymbolPd

from mpl_toolkits.mplot3dimport Axes3D

import matplotlib.pyplotas plt

fig = plt.figure()

ax = Axes3D(fig)

x = np.arange(-10, 10, 0.5)

y = np.arange(-10, 10, 0.5)

x_grid, y_grid = np.meshgrid(x, y)

# z^2 = x^2 + y^2

z_grid = x_grid **2 + y_grid **2

ax.plot_surface(x_grid, y_grid, z_grid, rstride=1, cstride=1, cmap='hot')

#plt.show()

def convex_func(xy):

return xy[0] **2 + xy[1] **2

bounds = ((-10, 10), (-10, 10))

guess = [5, 5]

for methodin ['SLSQP', 'TNC', 'L-BFGS-B']:

# 打印start

    print(method +' start')

ret = sco.minimize(convex_func, guess, method=method, bounds=bounds)

print(ret)

# 这里通过np.allclose判定结果是不是(0, 0)

    print('result is (0, 0): {}'.format(

np.allclose(ret['x'], [0., 0.], atol=0.001)))

# 打印end

    print(method +' end')

(本文学习自阿布量化https://www.abuquant.com)

你可能感兴趣的:(学习凸优化和线性代数)