-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.json
1 lines (1 loc) · 8.18 KB
/
search.json
1
[{"title":"Arknights","url":"/project/2023/11/08/Arknights/","content":"略略略 \n这是一个抽卡分享timeLucky time20发三个金!小子!!\nBad luck总结:六十几发没出六星,人给我干麻了,差点开氪\n","categories":["娱乐"],"tags":["明日方舟"]},{"title":"Hello World","url":"/project/2023/11/01/hello-world/","content":"Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.\nQuick StartCreate a new post$ hexo new "My New Post"\n\nMore info: Writing\nRun server$ hexo server\n\nMore info: Server\nGenerate static files$ hexo generate\n\nMore info: Generating\nDeploy to remote sites$ hexo deploy\n\nMore info: Deployment\n"},{"url":"/project/2023/11/11/About/","content":"皱皮于2019.5.27入舟\n于2023入zjut精弘网络\n友链什么的等我解决完报错再说QAQ\n"},{"title":"数学建模","url":"/project/2023/11/11/%E5%85%B3%E4%BA%8E%E6%95%B0%E5%AD%A6%E5%BB%BA%E6%A8%A1/","content":"略略略 \n看看高中课题Python程序代码:import numpy as np #引入外部扩展程序库NumPy并简写为“np”import pandas as pd #引入外部扩展程序库pandas并简写为“pd”import matplotlib as mpl #引入外部扩展程序库matplotlib并简写为“mpl”,该库属于画图的指令库import matplotlib.pyplot as plt #引入外部扩展程序库matplotlib中的pyplot命令,并简写为“plt”,该库属于画图的指令库from sklearn.preprocessing import MinMaxScaler #从外部扩展程序库sklearn中的preprocessing命令中引入MinMaxScaler指令,用于归一化\nmpl.rcParams[‘font.sans-serif’] = [u’simHei’] ##用来正常显示中文标签mpl.rcParams[‘axes.unicode_minus’] = False ##用来正常显示正负号df = pd.read_csv(‘JXwater.csv’, encoding=’utf-8’) #从文件JXwater.csv中引入数据,数据格式为utf-8\nmax_epochs = 60000 #迭代次数learn_rate = 0.025 #学习率mse_final = 6.5e-4 #误差限阈值\ninput_number = 4 #模型设置4个输入out_number = 1 #模型设置1个输出hidden_unit_number =20 #隐藏层个数设置为20\nw1 = 0.5 * np.random.rand(hidden_unit_number, input_number) - 0.1 #返回hidden*input维度随机数组\nb1 = 0.5 * np.random.rand(hidden_unit_number, 1) - 0.1 #返回hidden*output维度随机数组\nw2 = 0.5 * np.random.rand(out_number, hidden_unit_number) - 0.1\nb2 = 0.5 * np.random.rand(out_number, 1) - 0.1\nx = df[[‘日期’,’杭嘉湖分区平均’, ‘嘉兴站降雨’,’南排水量’]]\ny = df[[‘嘉兴水位’]]time=df[[‘日期’]] #变量time来代表日期\nsample_number = x.shape[0] #sample_number为样本数量print(“sample_number= “,sample_number) #输出样本数量\nx_scaler = MinMaxScaler(feature_range=(-1, 1))y_scaler = MinMaxScaler(feature_range=(-1, 1))x = x_scaler.fit_transform(x)y = y_scaler.fit_transform(y)\nsample_in = x.Tsample_out = y.T#输出结果用于检查print(sample_in)print(sample_out)#定义sigmoid阈值函数def sigmoid(z): return 1.0 / (1.0 + np.exp(-z))\nmse_history = [] #新建空数组,后面用于存放真实值与实际值误差,并通过迭代来逐步缩小误差,直到满足迭代停止\nfor i in range(max_epochs): # max_epochs迭代次数 # FP过程,误差前向传播过程 # 隐藏层的输出 hidden_out = sigmoid(np.dot(w1, sample_in).transpose() + b1.transpose()).transpose()\n# 输出层的输出(为了简化我们的写法,输出层不进行sigmoid激活)\nnetwork_out = (np.dot(w2, hidden_out).transpose() + b2.transpose()).transpose()\n\n# 误差值\nerr = sample_out - network_out #误差值err=实际输出值-网络训练输出值\nmse = np.average(np.square(err)) #求均方误差\nmse_history.append(mse) #误差累积值存放在mse_history中\nmin_mse=min(mse_history[i-1],mse_history[i]) #min_mse为累积误差的最小值\n#如果mse小于误差限阈值则迭代终止,跳出循环\nif mse < mse_final:\n break\n\n# BP 过程,误差反向传播过程\ndelta2 = -err #输出层到隐藏层误差\ndelta1 = np.dot(w2.transpose(), delta2) * hidden_out * (1 - hidden_out) #隐藏层到输入层误差\ndw2 = np.dot(delta2, hidden_out.transpose())\ndb2 = np.dot(delta2, np.ones((sample_number, 1)))\ndw1 = np.dot(delta1, sample_in.transpose())\ndb1 = np.dot(delta1, np.ones((sample_number, 1)))\nw2 -= learn_rate * dw2 #误差调整后的w2\nb2 -= learn_rate * db2\nw1 -= learn_rate * dw1 #误差调整后的w1\nb1 -= learn_rate * db1\n\n#=====================成果图输出(包括1个误差曲线图、1个BP网络计算成果和实际输出结果的水位过程对比图,#以及1个未来1d BP网络预测成果和实际水位过程对比图====================================#fig.1#误差曲线图mse_history10 = np.log10(mse_history) #取误差对数值,为了看到误差收敛的变化情况min_mse = min(mse_history10)print(“min_mse”,min_mse) #输出min_mseplt.plot(mse_history10) #画误差变化过程图print(“min_mse=”,min_mse)plt.plot([0, len(mse_history10)], [min_mse, min_mse])ax = plt.gca()ax.set_yticks([-2, -1, 0, 1, 2, min_mse])ax.set_xlabel(‘iteration’)ax.set_ylabel(‘MSE’)ax.set_title(‘Log10 MSE History’)plt.show()\ndf1 = pd.read_csv(‘JXwater_test.csv’, encoding=’utf-8’) # 读取预测集#预测集,利用前面训练好的BP神经网络,将预测数据所谓输入给到BP,获得输出的水位预测结果x1 = df1[[‘日期’,’杭嘉湖分区平均’, ‘嘉兴站降雨’,’南排水量’]] #预测集输入y1 = df1[[‘嘉兴水位’]] #真实值x1_scaler = MinMaxScaler(feature_range=(-1, 1))y1_scaler = MinMaxScaler(feature_range=(-1, 1))x1 = x1_scaler.fit_transform(x1)y1 = y1_scaler.fit_transform(y1)test_in=x1.T\nhidden_out = sigmoid((np.dot(w1, sample_in).transpose() + b1.transpose())).transpose()network_out = (np.dot(w2, hidden_out).transpose() + b2.transpose()).transpose()sample_out = y_scaler.inverse_transform(y)\nnetwork_out = y_scaler.inverse_transform(network_out.T)\n#fig.2#嘉兴水位BP模拟与实测过程对比图fig, axes = plt.subplots(nrows=1, ncols=1, figsize=(12, 10)) #设置图片的位置及大小(figsize)line1, = axes.plot(network_out[:, 0], ‘k’, marker=’o’) #图中第一条线,训练值,用黑色圆点表示line2, = axes.plot(sample_out[:, 0], ‘r’, markeredgecolor=’b’, marker=’*’, markersize=9) #图中第二条线,实测值,用五角星表示axes.legend((line1, line2), (‘forcast’, ‘real’), loc=’upper left’)axes.set_title(‘嘉兴水位模拟与实测过程’)\n#fig.3# BP预测输出和实际输出对比图test_hidden_out = sigmoid((np.dot(w1, test_in).transpose() + b1.transpose())).transpose()test_network_out = (np.dot(w2, test_hidden_out).transpose() + b2.transpose()).transpose()test_out = y1_scaler.inverse_transform(y1)\ntest_network_out = y1_scaler.inverse_transform(test_network_out.T)test_out = y1_scaler.inverse_transform(y1)print(“test_network_out”,test_network_out)#调用作图指令↓fig, axes = plt.subplots(nrows=1, ncols=1, figsize=(12, 10))#设置图片的位置及大小(figsize)line1, = axes.plot(test_network_out[:, 0], ‘k’, marker=’o’)#图中第一条线,预测值,用黑色圆点表示line2, = axes.plot(test_out[:, 0], ‘r’, markeredgecolor=’b’, marker=’*’, markersize=9)#图中第二条线,实测值,用五角星表示axes.legend((line1, line2), (‘forcast’, ‘real’), loc=’upper left’)axes.set_title(‘嘉兴水位预测集与实测’)\nplt.show()#在计算机界面显示上述3幅图\n","categories":["学习"],"tags":["建模"]}]