【Python】人工智能-机器学习——不调库手撕演化算法解决函数最小值问题

本文主要是介绍【Python】人工智能-机器学习——不调库手撕演化算法解决函数最小值问题,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1 作业内容描述

1.1 背景

  1. 现在有一个函数 3 − s i n 2 ( j x 1 ) − s i n 2 ( j x 2 ) 3-sin^2(jx_1)-sin^2(jx_2) 3sin2(jx1)sin2(jx2),有两个变量 x 1 x_1 x1 x 2 x_2 x2,它们的定义域为 x 1 , x 2 ∈ [ 0 , 6 ] x_1,x_2\in[0,6] x1,x2[0,6],并且 j = 2 j=2 j=2,对于此例,所致对于 j = 2 , 3 , 4 , 5 j=2,3,4,5 j=2,3,4,5分别有 16,36,64,100 个全局最优解。

  2. 现在有一个Shubert函数 ∏ i = 1 n ∑ j = 1 5 j cos ⁡ [ ( j + 1 ) x i + j ] \prod_{i=1}^{n}\sum_{j=1}^{5}j\cos[(j+1)x_i+j] i=1nj=15jcos[(j+1)xi+j],其中定义域为 − 10 < x i < 10 -10<x_i<10 10<xi<10,对于此问题,当n=2时有18个不同的全局最优解

1.2 要求

  1. 求该函数的最小值即 m i n ( 3 − s i n 2 ( j x 1 ) − s i n 2 ( j x 2 ) ) min(3-sin^2(jx_1)-sin^2(jx_2)) min(3sin2(jx1)sin2(jx2)),j=2,精确到小数点后6位。
  2. 求该Shubert函数的最小值即 m i n ( ∏ i = 1 2 ∑ j = 1 5 j cos ⁡ [ ( j + 1 ) x i + j ] ) min(\prod_{i=1}^{2}\sum_{j=1}^{5}j\cos[(j+1)x_i+j]) min(i=12j=15jcos[(j+1)xi+j]),精确到小数点后6位

2 作业已完成部分和未完成部分

该作业已经全部完成,没有未完成的部分。

Value在这里插入图片描述
Colab NotebookGithub Rep

3. 作业运行结果截图

最后跑出的结果如下:

  1. 第一个函数的最小值为 1.0000000569262162
  2. 第二个函数的最小值为-186.73042323192567

4 核心代码和步骤

4.1 基本的步骤

  1. 定义目标函数 objective_function:使用了一个二维的目标函数,即 3 − s i n 2 ( j x 1 ) − s i n 2 ( j x 2 ) 3-sin^2(jx_1)-sin^2(jx_2) 3sin2(jx1)sin2(jx2)
  2. 定义选择函数 crossover:用于交叉操作,通过交叉率(crossover_rate)确定需要进行交

叉的父母对的数量,并在这些父母对中交换某些变量的值。

  1. 定义变异函数 mutate:用于变异操作,通过变异率(mutation_rate)确定需要进行变异

的父母对的数量,并在这些父母对中随机改变某些变量的值。

  1. 定义进化算法 evolutionary_algorithm:初始化种群,其中每个个体都是一个二维向量。在

每一代中,计算每个个体的适应度值,绘制三维图表展示种群分布和最佳解。

  1. 更新全局最佳解。根据适应度值确定复制的数量并形成繁殖池。选择父母、进行交叉和变

异,更新种群。重复上述步骤直到达到指定的迭代次数。

  1. 设置算法参数:population_size:种群大小。;num_generations:迭代的次数。;muta

tion_rate:变异率。;crossover_rate:交叉率。

  1. 运行进化算法 evolutionary_algorithm:调用进化算法函数并获得最终的最佳解、最佳适

应度值和每一代的演化数据。

  1. 输出结果:打印最终的最佳解和最佳适应度值。输出每个迭代步骤的最佳适应度值。

  2. 可视化结果:绘制函数曲面和最优解的三维图表。绘制适应度值随迭代次数的变化曲线。

4.2 第一个函数 3 − s i n 2 ( j x 1 ) − s i n 2 ( j x 2 ) 3-sin^2(jx_1)-sin^2(jx_2) 3sin2(jx1)sin2(jx2)

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt# 定义目标函数
def objective_function(x):j = 2return 3 - np.sin(j * x[0])**2 - np.sin(j * x[1])**2 # 3 - sin(2x1)^2 - sin(2x2)^2# 定义选择函数
def crossover(parents_1, parents_2, crossover_rate):num_parents = len(parents_1) # 父母的数量 num_crossover = int(crossover_rate * num_parents) # 选择进行交叉的父母对的数量# 选择进行交叉的父母对crossover_indices = np.random.choice(num_parents, size=num_crossover, replace=False) # 选择进行交叉的父母对的索引# 复制父母copy_parents_1 = np.copy(parents_1)copy_parents_2 = np.copy(parents_2)# 进行交叉操作for i in crossover_indices:parents_1[i][1] = copy_parents_2[i][1] # 交叉变量x2parents_2[i][1] = copy_parents_1[i][1] # 交叉变量x2return parents_1, parents_2# 定义变异函数
def mutate(parents_1, parents_2, mutation_rate):num_parents = len(parents_1) # 父母的数量num_mutations = int(mutation_rate * num_parents) # 选择进行变异的父母对的数量# 选择进行变异的父母对mutation_indices = np.random.choice(num_parents, size=num_mutations, replace=False) # 选择进行变异的父母对的索引# 进行变异操作for i in mutation_indices:parents_1[i][1] = np.random.uniform(0, 6)  # 变异变量x2parents_2[i][1] = np.random.uniform(0, 6)  # 变异变量x2return parents_1, parents_2# 定义进化算法
def evolutionary_algorithm(population_size, num_generations, mutation_rate, crossover_rate):bounds = [(0, 6), (0, 6)]  # 变量的取值范围# 保存每个迭代步骤的信息evolution_data = []# 初始化种群population = np.random.uniform(bounds[0][0], bounds[0][1], size=(population_size, 2))# 设置初始的 best_solutionbest_solution = population[0]  # 选择种群中的第一个个体作为初始值best_fitness = objective_function(best_solution) # 计算初始值的适应度值for generation in range(num_generations):# 计算适应度fitness_values = np.apply_along_axis(objective_function, 1, population)# 找到当前最佳解current_best_index = np.argmin(fitness_values)current_best_solution = population[current_best_index]current_best_fitness = fitness_values[current_best_index]# 绘制每次迭代的三维分布图fig = plt.figure() # 创建一个新的图形ax = fig.add_subplot(111, projection='3d') # 创建一个三维的坐标系ax.scatter(population[:, 0], population[:, 1], fitness_values, color='black', marker='.', label='Population') # 绘制种群的分布图ax.scatter(best_solution[0], best_solution[1], best_fitness, s=100, color='red', marker='o', label='Best Solution') # 绘制最佳解的分布图# 设置坐标轴的标签ax.set_xlabel('X1') ax.set_ylabel('X2')ax.set_zlabel('f(x)')ax.set_title(f'Generation {generation} - Best Fitness: {best_fitness:.6f}')ax.legend() # 显示图例plt.show() # 显示图形# 更新全局最佳解if current_best_fitness < best_fitness: # 如果当前的最佳解的适应度值小于全局最佳解的适应度值best_solution = current_best_solutionbest_fitness = current_best_fitness# 保存当前迭代步骤的信息evolution_data.append({'generation': generation,'best_solution': best_solution,'best_fitness': best_fitness})# 根据适应度值确定复制的数量并且形成繁殖池reproduction_ratios = fitness_values / np.sum(fitness_values) # 计算每个个体的适应度值占总适应度值的比例sorted_index_ratios = np.argsort(reproduction_ratios) # 对比例进行排序half_length = len(sorted_index_ratios) // 2 # 选择前一半的个体first_half_index = sorted_index_ratios[:half_length] # 选择前一半的个体的索引new_half_population = population[first_half_index] # 选择前一半的个体breeding_pool = np.concatenate((new_half_population, new_half_population)) # 将前一半的个体复制一份,形成繁殖池# 选择父母        parents_1 = breeding_pool[:half_length]parents_2 = breeding_pool[half_length:] # 先获取最后一半的父母parents_2 = np.flip(parents_2, axis=0) # 再将父母的顺序反转# 选择和交叉parents_1, parents_2 = crossover(parents_1, parents_2, crossover_rate)# 变异parents_1, parents_2 = mutate(parents_1, parents_2, mutation_rate)# 更新种群population = np.vstack([parents_1, parents_2])return best_solution, best_fitness, evolution_data# 设置算法参数
population_size = 10000
num_generations = 40
mutation_rate = 0.1  # 变异率
crossover_rate = 0.4   # 交叉率# 运行进化算法
best_solution, best_fitness, evolution_data = evolutionary_algorithm(population_size, num_generations, mutation_rate, crossover_rate)# 输出结果
print("最小值:", best_fitness)
print("最优解:", best_solution)# 输出每个迭代步骤的最佳适应度值
print("每个迭代步骤的最佳适应度值:")
for step in evolution_data:print(f"Generation {step['generation']}: {step['best_fitness']}")# 可视化函数曲面和最优解
x1_vals = np.linspace(0, 6, 100)
x2_vals = np.linspace(0, 6, 100)
X1, X2 = np.meshgrid(x1_vals, x2_vals)
Z = 3 - np.sin(2 * X1)**2 - np.sin(2 * X2)**2fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(X1, X2, Z, alpha=0.5, cmap='viridis')
ax.scatter(best_solution[0], best_solution[1], best_fitness, color='red', marker='o', label='Best Solution')
ax.set_xlabel('X1')
ax.set_ylabel('X2')
ax.set_zlabel('f(x)')
ax.set_title('Objective Function and Best Solution')
ax.legend()# 绘制适应度值的变化曲线
evolution_df = pd.DataFrame(evolution_data)
plt.figure()
plt.plot(evolution_df['generation'], evolution_df['best_fitness'], label='Best Fitness')
plt.xlabel('Generation')
plt.ylabel('Fitness')
plt.title('Evolution of Fitness')
plt.legend()plt.show()

4.3 Shubert 函数的最小值

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt# 定义目标函数
def objective_function(x):result = 1for i in range(1, 3):inner_sum = 0for j in range(1, 6):inner_sum += j * np.cos((j + 1) * x[i - 1] + j)result *= inner_sumreturn result # 定义选择函数
def crossover(parents_1, parents_2, crossover_rate):num_parents = len(parents_1) # 父母的数量 num_crossover = int(crossover_rate * num_parents) # 选择进行交叉的父母对的数量# 选择进行交叉的父母对crossover_indices = np.random.choice(num_parents, size=num_crossover, replace=False) # 选择进行交叉的父母对的索引# 复制父母copy_parents_1 = np.copy(parents_1)copy_parents_2 = np.copy(parents_2)# 进行交叉操作for i in crossover_indices:parents_1[i][1] = copy_parents_2[i][1] # 交叉变量x2parents_2[i][1] = copy_parents_1[i][1] # 交叉变量x2return parents_1, parents_2# 定义变异函数
def mutate(parents_1, parents_2, mutation_rate):num_parents = len(parents_1) # 父母的数量num_mutations = int(mutation_rate * num_parents) # 选择进行变异的父母对的数量# 选择进行变异的父母对mutation_indices = np.random.choice(num_parents, size=num_mutations, replace=False) # 选择进行变异的父母对的索引# 进行变异操作for i in mutation_indices:parents_1[i][1] = np.random.uniform(-10, 10)  # 变异变量x2parents_2[i][1] = np.random.uniform(-10, 10)  # 变异变量x2return parents_1, parents_2# 定义进化算法
def evolutionary_algorithm(population_size, num_generations, mutation_rate, crossover_rate):bounds = [(-10, 10), (-10, 10)]  # 变量的取值范围# 保存每个迭代步骤的信息evolution_data = []# 初始化种群population = np.random.uniform(bounds[0][0], bounds[0][1], size=(population_size, 2))# 设置初始的 best_solutionbest_solution = population[0]  # 选择种群中的第一个个体作为初始值best_fitness = objective_function(best_solution) # 计算初始值的适应度值for generation in range(num_generations):# 计算适应度fitness_values = np.apply_along_axis(objective_function, 1, population) # 找到当前最佳解current_best_index = np.argmin(fitness_values)current_best_solution = population[current_best_index]current_best_fitness = fitness_values[current_best_index]# 绘制每次迭代的三维分布图fig = plt.figure() # 创建一个新的图形ax = fig.add_subplot(111, projection='3d') # 创建一个三维的坐标系ax.scatter(population[:, 0], population[:, 1], fitness_values, color='black', marker='.', label='Population') # 绘制种群的分布图ax.scatter(current_best_solution[0], current_best_solution[1], current_best_fitness, s=100, color='red', marker='o', label='Best Solution') # 绘制最佳解的分布图# 设置坐标轴的标签ax.set_xlabel('X1') ax.set_ylabel('X2')ax.set_zlabel('f(x)')ax.set_title(f'Generation {generation} - Best Fitness: {current_best_fitness:.6f}')ax.legend() # 显示图例plt.show() # 显示图形# 更新全局最佳解if current_best_fitness < best_fitness: # 如果当前的最佳解的适应度值小于全局最佳解的适应度值best_solution = current_best_solutionbest_fitness = current_best_fitness# 保存当前迭代步骤的信息evolution_data.append({'generation': generation,'best_solution': best_solution,'best_fitness': best_fitness})# 根据适应度值确定复制的数量并且形成繁殖池reproduction_ratios = fitness_values / np.sum(fitness_values) # 计算每个个体的适应度值占总适应度值的比例sorted_index_ratios = np.argsort(reproduction_ratios) # 对比例进行排序half_length = len(sorted_index_ratios) // 2 # 选择后一半的个体first_half_index = sorted_index_ratios[half_length:] # 选择后一半的个体的索引new_half_population = population[first_half_index] # 选择后一半的个体breeding_pool = np.concatenate((new_half_population, new_half_population)) # 将后一半的个体复制一份,形成繁殖池# 选择父母        parents_1 = breeding_pool[:half_length]parents_2 = breeding_pool[half_length:] # 先获取最后一半的父母parents_2 = np.flip(parents_2, axis=0) # 再将父母的顺序反转# 选择和交叉parents_1, parents_2 = crossover(parents_1, parents_2, crossover_rate)# 变异parents_1, parents_2 = mutate(parents_1, parents_2, mutation_rate)# 更新种群population = np.vstack([parents_1, parents_2])return best_solution, best_fitness, evolution_data# 设置算法参数
population_size = 15000
num_generations = 40
mutation_rate = 0.08  # 变异率
crossover_rate = 0.2   # 交叉率# 运行进化算法
best_solution, best_fitness, evolution_data = evolutionary_algorithm(population_size, num_generations, mutation_rate, crossover_rate)# 输出结果
print("最小值:", best_fitness)
print("最优解:", best_solution)# 输出每个迭代步骤的最佳适应度值
print("每个迭代步骤的最佳适应度值:")
for step in evolution_data:print(f"Generation {step['generation']}: {step['best_fitness']}")# 可视化函数曲面和最优解
x1_vals = np.linspace(-10, 10, 100)
x2_vals = np.linspace(-10, 10, 100)
X1, X2 = np.meshgrid(x1_vals, x2_vals)
Z = np.zeros_like(X1)
for i in range(Z.shape[0]):for j in range(Z.shape[1]):Z[i, j] = objective_function([X1[i, j], X2[i, j]])fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(X1, X2, Z, alpha=0.5, cmap='viridis')
ax.scatter(best_solution[0], best_solution[1], best_fitness, color='red', marker='o', label='Best Solution')
ax.set_xlabel('X1')
ax.set_ylabel('X2')
ax.set_zlabel('f(x)')
ax.set_title('Objective Function and Best Solution')
ax.legend()# 绘制适应度值的变化曲线
evolution_df = pd.DataFrame(evolution_data)
plt.figure()
plt.plot(evolution_df['generation'], evolution_df['best_fitness'], label='Best Fitness')
plt.xlabel('Generation')
plt.ylabel('Fitness')
plt.title('Evolution of Fitness')
plt.legend()plt.show()

5 附录

5.1 In[1] 输出

output_0_0

output_0_1

output_0_2

output_0_3

output_0_4

output_0_5

output_0_6

output_0_7

output_0_8

output_0_9

output_0_10

output_0_11

output_0_12

output_0_13

output_0_14

output_0_15

output_0_16

output_0_17

output_0_18

output_0_19

output_0_20

output_0_21

output_0_22

output_0_23

output_0_24

output_0_25

output_0_26

output_0_27

output_0_28

output_0_29

output_0_30

output_0_31

output_0_32

output_0_33

output_0_34

output_0_35

output_0_36

output_0_37

output_0_38

output_0_39

output_0_41

最小值: 1.0000002473000187

最优解: [0.78562713 0.7854951 ]

每个迭代步骤的最佳适应度值:

Generation 0: 1.0000153042180673

Generation 1: 1.0000153042180673

Generation 2: 1.0000153042180673

Generation 3: 1.0000136942409763

Generation 4: 1.0000136942409763

Generation 5: 1.0000136942409763

Generation 6: 1.0000136942409763

Generation 7: 1.0000100419077742

Generation 8: 1.000005565304546

Generation 9: 1.000002458099502

Generation 10: 1.0000022366988228

Generation 11: 1.0000007727585987

Generation 12: 1.0000007727585987

Generation 13: 1.0000007091648468

Generation 14: 1.0000007091648468

Generation 15: 1.0000004471760704

Generation 16: 1.0000004471760704

Generation 17: 1.0000004471760704

Generation 18: 1.0000004471760704

Generation 19: 1.0000002609708571

Generation 20: 1.0000002609708571

Generation 21: 1.0000002609708571

Generation 22: 1.0000002609708571

Generation 23: 1.0000002609708571

Generation 24: 1.0000002609708571

Generation 25: 1.0000002609708571

Generation 26: 1.0000002609708571

Generation 27: 1.0000002609708571

Generation 28: 1.0000002609708571

Generation 29: 1.0000002473000187

Generation 30: 1.0000002473000187

Generation 31: 1.0000002473000187

Generation 32: 1.0000002473000187

Generation 33: 1.0000002473000187

Generation 34: 1.0000002473000187

Generation 35: 1.0000002473000187

Generation 36: 1.0000002473000187

Generation 37: 1.0000002473000187

Generation 38: 1.0000002473000187

Generation 39: 1.0000002473000187

output_0_41

output_0_42

5.2 In[2] 输出

output_1_0

output_1_1

output_1_2

output_1_3

output_1_4

output_1_5

output_1_6

output_1_7

output_1_8

output_1_9

output_1_10

output_1_11

output_1_12

output_1_13

output_1_14

output_1_15

output_1_16

output_1_17

output_1_18

output_1_19

output_1_20

output_1_21

output_1_22

output_1_23

output_1_24

output_1_25

output_1_26

output_1_27

output_1_28

output_1_29

output_1_30

output_1_31

output_1_32

output_1_33

output_1_34

output_1_35

output_1_36

output_1_37

output_1_38

output_1_39

最小值: -186.73042323192567

最优解: [-7.70876845 -7.08354764]

每个迭代步骤的最佳适应度值:

Generation 0: -186.59098010602338

Generation 1: -186.59098010602338

Generation 2: -186.59098010602338

Generation 3: -186.59098010602338

Generation 4: -186.70224634663253

Generation 5: -186.70224634663253

Generation 6: -186.70224634663253

Generation 7: -186.70224634663253

Generation 8: -186.70224634663253

Generation 9: -186.70224634663253

Generation 10: -186.70224634663253

Generation 11: -186.71507272172664

Generation 12: -186.71507272172664

Generation 13: -186.7289048406221

Generation 14: -186.73006643615773

Generation 15: -186.73006643615773

Generation 16: -186.73006643615773

Generation 17: -186.73006643615773

Generation 18: -186.73009038074477

Generation 19: -186.73009038074477

Generation 20: -186.73009038074477

Generation 21: -186.73009038074477

Generation 22: -186.73009038074477

Generation 23: -186.73042323192567

Generation 24: -186.73042323192567

Generation 25: -186.73042323192567

Generation 26: -186.73042323192567

Generation 27: -186.73042323192567

Generation 28: -186.73042323192567

Generation 29: -186.73042323192567

Generation 30: -186.73042323192567

Generation 31: -186.73042323192567

Generation 32: -186.73042323192567

Generation 33: -186.73042323192567

Generation 34: -186.73042323192567

Generation 35: -186.73042323192567

Generation 36: -186.73042323192567

Generation 37: -186.73042323192567

Generation 38: -186.73042323192567

Generation 39: -186.73042323192567

output_1_41

output_1_42

这篇关于【Python】人工智能-机器学习——不调库手撕演化算法解决函数最小值问题的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/625252

相关文章

postgresql使用UUID函数的方法

《postgresql使用UUID函数的方法》本文给大家介绍postgresql使用UUID函数的方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录PostgreSQL有两种生成uuid的方法。可以先通过sql查看是否已安装扩展函数,和可以安装的扩展函数

Python实现终端清屏的几种方式详解

《Python实现终端清屏的几种方式详解》在使用Python进行终端交互式编程时,我们经常需要清空当前终端屏幕的内容,本文为大家整理了几种常见的实现方法,有需要的小伙伴可以参考下... 目录方法一:使用 `os` 模块调用系统命令方法二:使用 `subprocess` 模块执行命令方法三:打印多个换行符模拟

Python实现MQTT通信的示例代码

《Python实现MQTT通信的示例代码》本文主要介绍了Python实现MQTT通信的示例代码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一... 目录1. 安装paho-mqtt库‌2. 搭建MQTT代理服务器(Broker)‌‌3. pytho

MySQL字符串常用函数详解

《MySQL字符串常用函数详解》本文给大家介绍MySQL字符串常用函数,本文结合实例代码给大家介绍的非常详细,对大家学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录mysql字符串常用函数一、获取二、大小写转换三、拼接四、截取五、比较、反转、替换六、去空白、填充MySQL字符串常用函数一、

Spring的RedisTemplate的json反序列泛型丢失问题解决

《Spring的RedisTemplate的json反序列泛型丢失问题解决》本文主要介绍了SpringRedisTemplate中使用JSON序列化时泛型信息丢失的问题及其提出三种解决方案,可以根据性... 目录背景解决方案方案一方案二方案三总结背景在使用RedisTemplate操作redis时我们针对

基于Python开发一个图像水印批量添加工具

《基于Python开发一个图像水印批量添加工具》在当今数字化内容爆炸式增长的时代,图像版权保护已成为创作者和企业的核心需求,本方案将详细介绍一个基于PythonPIL库的工业级图像水印解决方案,有需要... 目录一、系统架构设计1.1 整体处理流程1.2 类结构设计(扩展版本)二、核心算法深入解析2.1 自

从入门到进阶讲解Python自动化Playwright实战指南

《从入门到进阶讲解Python自动化Playwright实战指南》Playwright是针对Python语言的纯自动化工具,它可以通过单个API自动执行Chromium,Firefox和WebKit... 目录Playwright 简介核心优势安装步骤观点与案例结合Playwright 核心功能从零开始学习

Python 字典 (Dictionary)使用详解

《Python字典(Dictionary)使用详解》字典是python中最重要,最常用的数据结构之一,它提供了高效的键值对存储和查找能力,:本文主要介绍Python字典(Dictionary)... 目录字典1.基本特性2.创建字典3.访问元素4.修改字典5.删除元素6.字典遍历7.字典的高级特性默认字典

SpringBoot整合Dubbo+ZK注册失败的坑及解决

《SpringBoot整合Dubbo+ZK注册失败的坑及解决》使用Dubbo框架时,需在公共pom添加依赖,启动类加@EnableDubbo,实现类用@DubboService替代@Service,配... 目录1.先看下公共的pom(maven创建的pom工程)2.启动类上加@EnableDubbo3.实

Python自动化批量重命名与整理文件系统

《Python自动化批量重命名与整理文件系统》这篇文章主要为大家详细介绍了如何使用Python实现一个强大的文件批量重命名与整理工具,帮助开发者自动化这一繁琐过程,有需要的小伙伴可以了解下... 目录简介环境准备项目功能概述代码详细解析1. 导入必要的库2. 配置参数设置3. 创建日志系统4. 安全文件名处