非线性最小二乘问题的数值方法 —— 狗腿法 Powell‘s Dog Leg Method (II, Python 简单实例)

news2024/9/27 5:50:36

Title: 非线性最小二乘问题的数值方法 —— 狗腿法 Powell‘s Dog Leg Method (II, Python 简单实例)


姊妹博文

非线性最小二乘问题的数值方法 —— 狗腿法 Powell‘s Dog Leg Method (I - 原理与算法)


0.前言

本篇博文作为对前述 “非线性最小二乘问题的数值方法 —— 狗腿法 Powell‘s Dog Leg Method (I - 原理与算法)” 的简单实践扩展.

理论部分参见前述博文, 此处不再重复. 这里只是补充一个简单的 Python 实例.


1. 最优问题实例

m i n i m i z e g ( x ) = 1 2 ∥ r ( x ) ∥ 2 2 = 1 2 ∑ i = 1 3 r i ( x ) 2 (I-1) {\rm minimize}\quad {g}(\mathbf{x}) = \frac{1}{2}\|\mathbf{r}(\mathbf{x})\|_2^2 = \frac{1}{2}\sum_{i=1}^{3} r_i(\mathbf{x})^2 \tag{I-1} minimizeg(x)=21r(x)22=21i=13ri(x)2(I-1)

其中

x = [ x 1 , x 2 ] T \mathbf{x} = \begin{bmatrix} x_1, x_2 \end{bmatrix}^{\small\rm T} x=[x1,x2]T

r ( x ) = [ r 1 ( x ) ,   r 2 ( x ) ,   r 3 ( x ) ] T \mathbf{r}(\mathbf{x}) = \begin{bmatrix} r_1(\mathbf{x}), \, r_2(\mathbf{x}) ,\,r_3(\mathbf{x}) \end{bmatrix}^{\small\rm T} r(x)=[r1(x),r2(x),r3(x)]T

r 1 ( x ) = sin ⁡ x 1 − 0.4 r_1(\mathbf{x}) = \sin x_1 -0.4 r1(x)=sinx10.4

r 2 ( x ) = cos ⁡ x 2 + 0.8 r_2(\mathbf{x}) = \cos x_2 + 0.8 r2(x)=cosx2+0.8

r 3 ( x ) = x 1 2 + x 2 2 − 1 r_3(\mathbf{x}) = \sqrt{x_1^2 +x_2^2} -1 r3(x)=x12+x22 1

可以推得

∂ r ( x ) ∂ x = [ cos ⁡ x 1 0 0 − sin ⁡ x 2 x 1 x 1 2 + x 2 2 x 2 x 1 2 + x 2 2 ] \frac{\partial \mathbf{r}(\mathbf{x})}{\partial \mathbf{x}} = \begin{bmatrix}\cos x_1 & 0\\ 0 &-\sin x_2 \\ \frac{x_1}{\sqrt{x_1^2+x_2^2}} & \frac{x_2}{\sqrt{x_1^2+x_2^2}} \end{bmatrix} xr(x)= cosx10x12+x22 x10sinx2x12+x22 x2

g ( x ) = 1 2 [ ( sin ⁡ x 1 − 0.4 ) 2 + ( cos ⁡ x 2 + 0.8 ) 2 + ( x 2 2 + x 1 2 − 1 ) 2 ] g(\mathbf{x})=\frac{1}{2} \left[{ {{\left( \sin{ {x_1} }-0.4\right) }^{2}}+{{\left( \cos{ {x_2} }+0.8\right) }^{2}}+{{\left( \sqrt{{{{x_2}}^{2}}+{{{x_1}}^{2}}}-1\right) }^{2}}}\right] g(x)=21[(sinx10.4)2+(cosx2+0.8)2+(x22+x12 1)2]

∇ g ( x ) = [ x 1 ( x 2 2 + x 1 2 − 1 ) x 2 2 + x 1 2 + cos ⁡ x 1 ( sin ⁡ x 1 − 0.4 ) x 2 ( x 2 2 + x 1 2 − 1 ) x 2 2 + x 1 2 − sin ⁡ x 2 ( cos ⁡ x 2 + 0.8 ) ] \nabla g(\mathbf{x}) = \begin{bmatrix}\frac{{x_1} \left( \sqrt{{{{x_2}}^{2}}+{{{x_1}}^{2}}}-1\right) }{\sqrt{{{{x_2}}^{2}}+{{{x_1}}^{2}}}}+\cos{ {x_1} } \left( \sin{ {x_1} }-0.4\right) \\ \frac{{x_2} \left( \sqrt{{{{x_2}}^{2}}+{{{x_1}}^{2}}}-1\right) }{\sqrt{{{{x_2}}^{2}}+{{{x_1}}^{2}}}}- \sin{ {x_2} } \left( \cos{ {x_2} }+0.8\right) \end{bmatrix} g(x)= x22+x12 x1(x22+x12 1)+cosx1(sinx10.4)x22+x12 x2(x22+x12 1)sinx2(cosx2+0.8)

H ~ ( x ) = [ x 1 2 x 2 2 + x 1 2 + ( cos ⁡ x 1 ) 2 x 1 x 2 x 2 2 + x 1 2 x 1 x 2 x 2 2 + x 1 2 ( sin ⁡ x 2 ) 2 + x 2 2 x 2 2 + x 1 2 ] \widetilde{\mathbf{H}}(\mathbf{x})=\begin{bmatrix}\frac{{{{x_1}}^{2}}}{{{{x_2}}^{2}}+{{{x_1}}^{2}}}+{{(\cos{ {x_1} })}^{2}} & \frac{{x_1} {x_2}}{{{{x_2}}^{2}}+{{{x_1}}^{2}}}\\ \frac{{x_1} {x_2}}{{{{x_2}}^{2}}+{{{x_1}}^{2}}} & {{(\sin{ {x_2} )}}^{2}}+\frac{{{{x_2}}^{2}}}{{{{x_2}}^{2}}+{{{x_1}}^{2}}}\end{bmatrix} H (x)=[x22+x12x12+(cosx1)2x22+x12x1x2x22+x12x1x2(sinx2)2+x22+x12x22]

具体的符号推导参见非线性最小二乘问题的数值方法 —— 从牛顿迭代法到高斯-牛顿法 (实例篇 V).


2. 狗腿法 (Powell‘s Dog Leg Method) Python 实现

基于狗腿法的算法流程实现如下简单 Python Demo:

from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
import numpy as np
from numpy.linalg import inv, det, norm
from math import cos
from math import sin
from math import sqrt
from math import pow

# multiplication of two matrixs
def multiply_matrix(A, B):
    if  A.shape[1] == B.shape[0]:
        C = np.zeros((A.shape[0], B.shape[1]), dtype = float)
        [rows, cols] = C.shape
        
        for row in range(rows): 
            for col in range(cols):
                for elt in range(len(B)):
                    C[row, col] += A[row, elt] * B[elt, col]
        return C
    else:
        return "Cannot multiply A and B. Please check whether the dimensions of the inputs are compatible."

# g(x) = (1/2) ||r(x)||_2^2
def g(x_vector):
    x_1 = x_vector[0]
    x_2 = x_vector[1]
    return ( pow(sin(x_1)-0.4, 2)+ pow(cos(x_2)+0.8, 2) + pow(sqrt(pow(x_2,2)+pow(x_1,2))-1, 2) ) /2

# r(x) = [r_1, r_2, r_3]^{T}
def r(x_vector):
    x_1 = x_vector[0]
    x_2 = x_vector[1]
    return np.array([[sin(x_1)-0.4],
                     [cos(x_2)+0.8],
                     [sqrt(pow(x_1,2)+pow(x_2,2))-1]], dtype=object)

# \partial r(x) / \partial x
def dr(x_vector):
    x_1 = x_vector[0]
    x_2 = x_vector[1]
    if sqrt(pow(x_2,2)+pow(x_1,2)) < 1e-3:  ## 人为设置
        return np.array([[cos(x_1),	0], 
                         [0, -sin(x_2)],
                         [0, 0]], dtype=object)
    else:
        return np.array([[cos(x_1),	0],
                         [0,	-sin(x_2)],
                         [x_1/sqrt(pow(x_2,2)+pow(x_1,2)), x_2/sqrt(pow(x_2,2)+pow(x_1,2))]], dtype=object)

# Simplified Hessian matrix in Gauss-Newton method
# refer to eq. ​(I-1-2) in blog "非线性最小二乘问题的数值方法 —— 从高斯-牛顿法到列文伯格-马夸尔特法 (I)"
def sH(x_vector):
    x_1 = x_vector[0]
    x_2 = x_vector[1]
    return multiply_matrix(np.transpose(dr(x_1, x_2)), dr(x_1, x_2)) 


# \nabla g(x_1, x_2)
# refer to eq. ​(I-1-3) in blog "非线性最小二乘问题的数值方法 —— 从高斯-牛顿法到列文伯格-马夸尔特法 (I)"
def dg(x_vector):
    x_1 = x_vector[0]
    x_2 = x_vector[1]

    return np.array(multiply_matrix(np.transpose(dr(x_1, x_2)), r(x_1, x_2)))


# model for the cost function g based on eq (II-2-2) in "非线性最小二乘问题的数值方法 —— 狗腿法 Powell‘s Dog Leg Method (I - 原理与算法)"
def L_model(h_vector, g_i, dg_i, sH_i):
    return g_i + multiply_matrix( dg_i.transpose(), h_vector) + 0.5 * multiply_matrix(multiply_matrix(h_vector.transpose(), sH_i), h_vector)


def dog_leg_method(x_vector, epsilon_1, epsilon_2, epsilon_3, max_iter, trust_region_radius):
    # x_1 = x_vector[1]
    # # x_2 = x_vector[2]
    iter = 0
    delta = trust_region_radius   # trust-region radius
    found = False
    # g_i = g(x_vector)
    x_current_vector = x_vector
    r_i = r(x_current_vector)
    dr_i = dr(x_current_vector)
    dg_i = multiply_matrix(np.transpose(dr_i), r_i)
    g_i = g(x_current_vector)

    # if np.max(np.abs(dg_i)) < epsilon_1:
    if (norm(r_i, np.inf) < epsilon_3 ) or (norm(dg_i, np.inf) < epsilon_1):
        found = True

    array_x_1 = []
    array_x_2 = []
    array_x_3 = []
    # x_new_vector = np.array([0,0])
    # g_new = np.inf
    while (found == False) and (iter < max_iter):
    # sH_i = sH(x_vector)
        array_x_1.append(x_current_vector[0])
        array_x_2.append(x_current_vector[1])
        array_x_3.append(g_i)

        iter += 1
        step_sd_i = - dg_i 
        Jh = multiply_matrix(dr_i, step_sd_i)
        alpha_i = pow(norm(step_sd_i, 2), 2) / pow(norm(Jh, 2), 2)
        step_cp_i = alpha_i * step_sd_i                     ## Steepest descent step
        sH_i = multiply_matrix(np.transpose(dr_i), dr_i)    ## Simplified Hessian Matrix

        inv_sH_i =  inv(sH_i)
        step_gn_i = - np.array(multiply_matrix(inv_sH_i, dg_i))       ## Gauss-Newton step
        rho = -1

        while (rho < 0) and (found == False):               ## Until step acceptable
            if norm(step_gn_i, 2) < delta:                  ## Case I
                step_dl_i = step_gn_i
                print("Iterating index [%d], Case I"%iter)
            elif norm(step_cp_i, 2) >= delta:               ## Case II 
                step_dl_i = (delta / norm(step_sd_i, 2)) * step_sd_i
                print("Iterating index [%d], Case II"%iter)
            else:                                           ## Case III
                step_gn_cp_i = step_gn_i - step_cp_i
                gn_cp_norm_sq = pow(norm(step_gn_cp_i, 2),2)
                delta_cp_sq = pow(delta,2) - pow(norm(step_cp_i, 2), 2)
                c_matrix = multiply_matrix( np.transpose(step_cp_i), step_gn_cp_i )
                c = c_matrix[0][0]
                sqrt_discriminant = sqrt( pow(c,2) + gn_cp_norm_sq * delta_cp_sq ) 
                if (c <= 0):
                    beta = (-c + sqrt_discriminant) / gn_cp_norm_sq
                else:
                    beta = delta_cp_sq / (c + sqrt_discriminant)

                step_dl_i = step_cp_i + beta * step_gn_cp_i
                print("Iterating index [%d], Case III"%iter)
                
            norm_step_dl = norm(step_dl_i, 2)
            if (norm_step_dl <= epsilon_2 * (norm(x_current_vector, 2) + epsilon_2)):
                found = True
            else:
                # print(x_current_vector.shape)
                # print(step_dl_i.shape)
                x_new_vector = x_current_vector + step_dl_i.flatten()
                g_new = g(x_new_vector)
                L_0 = g_i
                L_h = L_model(step_dl_i, g_i, dg_i, sH_i)
                rho = (g_i - g_new) / (L_0 - L_h)
                if (rho > 0):                           ## Step acceptable
                    x_current_vector = x_new_vector     ## New iterating state
                    r_i = r(x_current_vector)
                    dr_i = dr(x_current_vector)
                    dg_i = multiply_matrix(np.transpose(dr_i), r_i)
                    g_i = g(x_current_vector)
                    if (norm(r_i, np.inf) < epsilon_3 ) or (norm(dg_i, np.inf) < epsilon_1):
                        found = True
                if (rho > 0.75):                        ## Expanding trust region
                    if (delta - 3 * norm_step_dl < 0):
                        delta = 3 * norm_step_dl
                elif (rho < 0.25):                      ## Shrinking trust region
                    delta = delta / 2
                    if (delta < (epsilon_2*(norm(x_current_vector, 2)+epsilon_2))):
                        found = True

    return array_x_1, array_x_2, array_x_3
      

def result_plot(trajectory, trust_region_radius):
    fig = plt.figure()
    ax3 = plt.axes(projection='3d')
    xx = np.arange(-5,5,0.1)
    yy = np.arange(-4,4,0.1)
    X, Y = np.meshgrid(xx, yy)
    Z = np.zeros((X.shape[0], Y.shape[1]), dtype = float)
    for i in range(X.shape[0]):
        for j in range(Y.shape[1]):
            Z[i,j] = g(np.array([X[0,j], Y[i,0]]))

    ax3.plot_surface(X, Y, Z, rstride = 1, cstride = 1, cmap='rainbow', alpha=0.25)
    ax3.contour(X, Y, Z, offset=-1, cmap = 'rainbow')

    ax3.plot(trajectory[0], trajectory[1], trajectory[2], "r--")

    offset_data = -1*np.ones(len(trajectory[0]))
    ax3.plot(trajectory[0], trajectory[1], offset_data,'k--')
    ax3.set_title('Dog Leg Method \n(Initial point [%.1f, %.1f], Trust-region radius %.2f)' %(trajectory[0][0], trajectory[1][0], trust_region_radius))
    ax3.set_xlabel("r_1")
    ax3.set_ylabel("r_2")
    ax3.set_zlabel("g")

    file_name_prefix = "./dog_leg"
    file_extension = ".png"
    radius= "-r"
    file_name = f"{file_name_prefix}_{trajectory[0][0]}_{trajectory[1][0]}{radius}{trust_region_radius}{file_extension}"
    print(file_name)
    plt.draw()
    plt.savefig(file_name)



if __name__ == "__main__":
    test_data = np.array([[4.9, 3.9], [-2.9, 1.9], [0.1, -0.1], [-0.1, 0.1], [0,-3.8],[1,2.5]], dtype=object)
    trust_region_radius = np.array([0.4, 0.01, 2.0])
    for radius in trust_region_radius:
        for inital_data in test_data:
            print("\nInitial point: [%.1f, %.1f]" %(inital_data[0],inital_data[1]))
            print("Trust region radius: %.2f" %radius)
            epsilon_1 = 1e-6
            epsilon_2 = 1e-6
            epsilon_3 = 1e-6
            max_iter = 1000
            trajectory = dog_leg_method(inital_data, epsilon_1, epsilon_2, epsilon_3, max_iter, radius)
            result_plot(trajectory, radius)


3. 测试结果

A. 结果显示

测试显示 (初始点 [4.9, 3.9], 信赖域半径分别为 0.01、0.4、2.0)测试显示 (初始点 [-2.9, 1.9], 信赖域半径分别为 0.01、0.4、2.0)
Levenberg_Marquardt_4.9_3.9Levenberg_Marquardt_4.9_3.9
Levenberg_Marquardt_0.1_-0.1Levenberg_Marquardt_-0.1_0.1
Levenberg_Marquardt_0_-3.8Levenberg_Marquardt_1_2.5

B. 迭代步说明

不同信赖域的迭代步及每一步的类型如下表所示. Case III 代表该步类型为狗腿步, Case II 代表该步类型为柯西步, Case I 代表该步类型为高斯-牛顿步.

越靠近收敛极小值点, 高斯-牛顿步类型出现频率越高, 这样有利于快速收敛.

信赖域半径对计算性能也有影响.

Trust-region radius = 0.01Trust-region radius = 0.4Trust-region radius = 2.0
Initial point: [4.9, 3.9]
Trust region radius: 0.01
Iterating index [1], Case II
Iterating index [2], Case II
Iterating index [3], Case II
Iterating index [4], Case II
Iterating index [5], Case II
Iterating index [6], Case II
Iterating index [7], Case I
Iterating index [8], Case I
Iterating index [9], Case I
Iterating index [10], Case I
Iterating index [11], Case I
Iterating index [12], Case I
Iterating index [13], Case I
Iterating index [14], Case I
Iterating index [15], Case I
Iterating index [16], Case I
Iterating index [17], Case I
Iterating index [18], Case I
Iterating index [19], Case I
Iterating index [20], Case I
Iterating index [21], Case I
Iterating index [22], Case I
Iterating index [23], Case I
Iterating index [24], Case I
Iterating index [25], Case I
Initial point: [4.9, 3.9]
Trust region radius: 0.40
Iterating index [1], Case II
Iterating index [2], Case II
Iterating index [3], Case III
Iterating index [4], Case III
Iterating index [4], Case III
Iterating index [5], Case I
Iterating index [5], Case I
Iterating index [5], Case III
Iterating index [6], Case II
Iterating index [7], Case I
Iterating index [8], Case I
Iterating index [9], Case I
Iterating index [10], Case I
Iterating index [11], Case I
Iterating index [12], Case I
Iterating index [13], Case I
Iterating index [14], Case I
Iterating index [15], Case I
Iterating index [16], Case I
Iterating index [17], Case I
Iterating index [18], Case I
Iterating index [19], Case I
Iterating index [20], Case I
Iterating index [21], Case I
Iterating index [22], Case I
Iterating index [23], Case I
Initial point: [4.9, 3.9]
Trust region radius: 2.00
Iterating index [1], Case II
Iterating index [2], Case I
Iterating index [3], Case I
Iterating index [3], Case I
Iterating index [3], Case III
Iterating index [4], Case I
Iterating index [5], Case I
Iterating index [6], Case I
Iterating index [7], Case I
Iterating index [8], Case I
Iterating index [9], Case I
Iterating index [10], Case I
Iterating index [11], Case I
Iterating index [12], Case I
Iterating index [13], Case I
Iterating index [14], Case I
Iterating index [15], Case I
Iterating index [16], Case I
Iterating index [17], Case I
Iterating index [18], Case I
Iterating index [19], Case I
Iterating index [20], Case I
Iterating index [21], Case I
Iterating index [22], Case I
Initial point: [-2.9, 1.9]
Trust region radius: 0.01
Iterating index [1], Case II
Iterating index [2], Case II
Iterating index [3], Case II
Iterating index [4], Case II
Iterating index [5], Case I
Iterating index [6], Case I
Iterating index [7], Case I
Iterating index [8], Case III
Iterating index [8], Case III
Iterating index [9], Case I
Iterating index [10], Case I
Iterating index [11], Case I
Iterating index [12], Case I
Iterating index [13], Case I
Iterating index [14], Case I
Iterating index [15], Case I
Iterating index [16], Case I
Iterating index [17], Case I
Iterating index [18], Case I
Iterating index [19], Case I
Iterating index [20], Case I
Iterating index [21], Case I
Iterating index [22], Case I
Iterating index [23], Case I
Iterating index [24], Case I
Iterating index [25], Case I
Iterating index [26], Case I
Initial point: [-2.9, 1.9]
Trust region radius: 0.40
Iterating index [1], Case II
Iterating index [2], Case I
Iterating index [3], Case I
Iterating index [4], Case I
Iterating index [5], Case III
Iterating index [5], Case III
Iterating index [6], Case I
Iterating index [7], Case I
Iterating index [8], Case I
Iterating index [9], Case I
Iterating index [10], Case I
Iterating index [11], Case I
Iterating index [12], Case I
Iterating index [13], Case I
Iterating index [14], Case I
Iterating index [15], Case I
Iterating index [16], Case I
Iterating index [17], Case I
Iterating index [18], Case I
Iterating index [19], Case I
Iterating index [20], Case I
Iterating index [21], Case I
Iterating index [22], Case I
Iterating index [23], Case I
Initial point: [-2.9, 1.9]
Trust region radius: 2.00
Iterating index [1], Case I
Iterating index [2], Case I
Iterating index [3], Case III
Iterating index [4], Case III
Iterating index [4], Case III
Iterating index [5], Case I
Iterating index [6], Case I
Iterating index [7], Case I
Iterating index [8], Case I
Iterating index [9], Case I
Iterating index [10], Case I
Iterating index [11], Case I
Iterating index [12], Case I
Iterating index [13], Case I
Iterating index [14], Case I
Iterating index [15], Case I
Iterating index [16], Case I
Iterating index [17], Case I
Iterating index [18], Case I
Iterating index [19], Case I
Iterating index [20], Case I
Iterating index [21], Case I
Iterating index [22], Case I

4. 结论

以上仅为一个狗腿法的简单示例, 推导和算法请见 “非线性最小二乘问题的数值方法 —— 狗腿法 Powell‘s Dog Leg Method (I - 原理与算法)”.

如有问题请指出, 谢谢!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1403417.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

L1-069 胎压监测(Java)

小轿车中有一个系统随时监测四个车轮的胎压&#xff0c;如果四轮胎压不是很平衡&#xff0c;则可能对行车造成严重的影响。 让我们把四个车轮 —— 左前轮、右前轮、右后轮、左后轮 —— 顺次编号为 1、2、3、4。本题就请你编写一个监测程序&#xff0c;随时监测四轮的胎压&…

系统架构14 - 软件工程(2)

需求工程 需求工程软件需求两大过程三个层次业务需求(business requirement)用户需求(user requirement)功能需求 (functional requirement)非功能需求 概述活动阶段需求获取基本步骤获取方法 需求分析三大模型数据流图数据字典DD需求定义方法 需求验证需求管理需求基线变更控制…

Hylicos - MINI2440 - 中断控制

中断 中断源管理 中断是一种异步异常&#xff0c;CPU需要处理很多来自设备的中断请求&#xff0c;而CPU引出的line只有IRQ线和FIQ线&#xff0c;所以就得引入中断控制器帮助CPU搞清楚是中断的来源。 MINI2440的中断控制器&#xff0c;可以接受来自60个中断源的请求。提供这些…

Redis双写一致性

所有的情况都是再并发情况下存在温蒂 一、先更新数据库&#xff0c;再更新缓存场景-不推荐 当有两个线程A、B&#xff0c;同时对一条数据进行操作&#xff0c;一开始数据库和redis的数据都为1&#xff0c;当线程A去修改数据库&#xff0c;将1改为2&#xff0c;然后线程A在修改…

幻兽帕鲁专用服务器

随着幻兽帕鲁这款游戏的热度持续升温&#xff0c;我们遍寻全网&#xff0c;带给各位玩家一个全新的、高品质的游戏体验——莱卡云服务器。有幻兽帕鲁的热衷者们无需再为了服务器的选取困扰&#xff0c;因为我们可以肯定地说&#xff1a;选择莱卡云&#xff0c;你不会失望。 首先…

数据库复试—关系数据库标准语言SQL

数据库复试—关系数据库标准语言SQL SQL&#xff1a;结构化查询语言 以教材中的学生-课程数据库为例进行SQL基础语法的复习 数据库实验环境选择SQLServer 11 关系模式 学生表Student(Sno,Sname,Ssex,Sage,Sdept) 课程表Course(Cno,Cname,Cpno,Ccredit) 学生选课表SC&#xf…

Linux操作系统——理解软硬链接

1.引言 通过我们前面理解文件系统的基础上&#xff0c;我们来理解软硬链接&#xff0c;在我们学习文件的时候我们会见到各种链接文件&#xff0c;其中链接文件分为两种&#xff0c;一种叫软连接&#xff0c;一种叫硬链接。 下面我们新建一个log文件&#xff0c;要对log这个文…

搭建一个简单的Spring Demo

要学习Spring 源码&#xff0c;一个是从Spring GitHub 上去down源码&#xff0c;然后倒入IDEA编译&#xff0c;但这种方法费时费力&#xff0c;如果你不需要对Spring 源码进行修改后&#xff0c;再编译的话&#xff0c;直接搭建一个Spring Demo 的Maven项目&#xff0c;引入Spr…

Linux操作系统——理解文件系统

预备知识 到目前为止&#xff0c;我们所学习到的关于文件的操作&#xff0c;全部都是基于文件被打开&#xff0c;被访问&#xff0c;访问期间比较重要的有重定向&#xff0c;缓冲区&#xff0c;一切皆文件&#xff0c;当我们访问完毕的时候需要将文件关闭&#xff0c;关闭时那…

关于事务的最常见的十道面试题

面试题一&#xff1a;什么是事务&#xff1f;为什么需要事务&#xff1f; 事务(Transaction)是保证数据库可靠性和稳定性的一种机制&#xff0c;单个逻辑工作单元执行的一系列操作&#xff0c;这些操作要么全部完成&#xff0c;要么全部不完成&#xff0c;是数据库环境中的最小…

Aria2 WebUI控制台 任意文件读取漏洞复现(CVE-2023-39141)

0x01 产品简介 Aria2 WebUI控制台是用于下载文件的实用程序。它支持 HTTP(S)/FTP/SFTP/BitTorrent 和 Metalink 协议。aria2可以从多个来源/协议下载文件,并尝试利用您的最大下载带宽。它支持同时从HTTP(S)/FTP/SFTP和BitTorrent下载文件,而从HTTP(S)/FTP/SFTP下载的数据上…

《WebKit 技术内幕》学习之八(1):硬件加速机制

《WebKit 技术内幕》之八&#xff08;1&#xff09;&#xff1a;硬件加速机制 1 硬件加速基础 1.1 概念 这里说的硬件加速技术是指使用GPU的硬件能力来帮助渲染网页&#xff0c;因为GPU的作用主要是用来绘制3D图形并且性能特别好&#xff0c;这是它的专长所在&#xff0c;它…

深入了解WPF控件:常用属性与用法(六)

掌握WPF控件&#xff1a;熟练常用属性&#xff08;六&#xff09; ListView 用于展示数据项集合的列表控件。它提供了丰富的功能和灵活的定制性&#xff0c;可以轻松地展示和编辑大量的数据。 常用属性描述ItemsSource用于设置ListView的数据源。可以是一个集合、数组或列表…

架构师考试相关信息

文章目录 去年考试安排官网通知&#xff1a; 中国计算机技术职业资格网&#xff08;今年的安排估计2月份放出&#xff0c;结果大约12月&#xff09; 1&#xff0e;系统架构的考试要求&#xff1a; &#xff08;1&#xff09;掌握计算机硬软件与网络的基础知识&#xff1b; &…

模板方法模式介绍

目录 一、模板方法模式介绍 1.1 模板方法模式的定义 1.2 模板方法模式的原理 1.2.1 模板方法模式类图 1.2.2 类图角色说明 1.2.3 示例代码 二、模板方法模式的应用 2.1 需求说明 2.2 需求实现 2.2.1 账户抽象类 2.2.2 借款一个月 2.2.3 借款7天 2.2.4 测试类 三、…

helm---自动化一键部署

什么是helm?? 在没有这个helm之前&#xff0c;deployment service ingress helm的作用就是通过打包的方式&#xff0c;把deployment service ingress 这些打包在一块&#xff0c;一键式部署服务&#xff0c;类似于yum 官方提供的一个类似于安装仓库的功能&#xff0c;可以实…

Unity学习之坦克游戏制作(1)开始场景的制作

文章目录 1. 实现效果2. 场景装饰2.1 创建场景2.2 拖入场景地板 3 开始界面3.1 导入UI3.2 创建面板基类3.2.1 开始按钮 4 设置界面5 音效数据逻辑5.1 音效数据可持久化5.2 声明音效管理的主要变量5.3 声明数据管理器5.4 在设置面板的数据初始化5.5 提供API给外部 6 排行榜界面6…

​WordPress顶部管理工具栏怎么添加一二级自定义菜单?

默认情况下&#xff0c;WordPress前端和后台页面顶部都有一个“管理工具栏”&#xff0c;左侧一般就是站点名称、评论、新建&#xff0c;右侧就是您好&#xff0c;用户名称和头像。那么我们是否可以在这个管理工具栏中添加一些一二级自定义菜单呢&#xff1f; 其实&#xff0c…

JavaScript库jquery的使用方法

"写更少&#xff0c;做更多"是jquery的设计理念&#xff0c;jquery是一个兼容多浏览器的JavaScript库&#xff0c;利用jquery的语法设计能使开发更便捷。 网页添加jquery的方法:1.从jquery.com下载库&#xff1b;2.从CDN中载入库&#xff08;示例使用&#xff09;&a…

线性代数:矩阵运算(加减、数乘、乘法、幂、除、转置)

目录 加减 数乘 矩阵与矩阵相乘 矩阵的幂 矩阵转置 方阵的行列式 方阵的行列式&#xff0c;证明&#xff1a;|AB| |A| |B| 加减 数乘 矩阵与矩阵相乘 矩阵的幂 矩阵转置 方阵的行列式 方阵的行列式&#xff0c;证明&#xff1a;|AB| |A| |B|