├── Fault_modify.py ├── LICENSE ├── Model.py ├── README.md ├── Temp1.npy ├── ae_D0_temp.mat ├── ae_D1_temp.mat ├── ae_D2_temp.mat ├── ae_Kobs3_temp.mat ├── ae_ver_temp.mat ├── example.py ├── example_introd.md ├── img-folder ├── Acc_errorContribution.png ├── README.md ├── error_contribution.png └── sim.png └── memorymat1.npy /Fault_modify.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | #模拟四种传感器故障 3 | #卡死 4 | def Stuck(Kobs,Var_number,Initial_moment,a): 5 | Kobs[Initial_moment-1:,Var_number-1]=a 6 | return Kobs 7 | #恒增益 8 | def ConstantGain(Kobs,Var_number,Initial_moment,G): 9 | Kobs[Initial_moment-1:, Var_number-1] = (1+G)*Kobs[Initial_moment-1:,Var_number-1] 10 | return Kobs 11 | #固定偏差 12 | def FixedDeviation(Kobs,Var_number,Initial_moment,b): 13 | Kobs[Initial_moment-1:, Var_number-1] = b+ Kobs[Initial_moment-1:, Var_number-1] 14 | return Kobs 15 | #线性偏差 16 | def Linear_deviation(Kobs,Var_number,Initial_moment,f,c): 17 | line=(f * (np.arange(0, Kobs.shape[0]-Initial_moment + 1, step=1)) + c) 18 | Kobs[Initial_moment-1:, Var_number-1]=line+Kobs[Initial_moment-1:, Var_number-1] 19 | return Kobs 20 | 21 | 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /Model.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from scipy import io 3 | import matplotlib.pyplot as plt 4 | import matplotlib.ticker as ticker 5 | 6 | column_num=18 7 | step=100 8 | delta=0.001 9 | z=4 10 | 11 | #加载训练数据,默认进行归一化 12 | def Traindata(name_list,if_nor=True): 13 | np_D = np.zeros((1, column_num)) 14 | for i in range(len(name_list)): 15 | dict_obj = io.loadmat(name_list[i]) 16 | temp = dict_obj['ae_D'] 17 | np_D = np.vstack((np_D, temp)) 18 | np_D = np.delete(np_D, 0, axis=0) 19 | np_D = np_D[:, 4:]#去掉不需要的前四列 20 | index = np.where(np_D[:,3]< 10)[0]#将磨煤机电流低于10的值删去 21 | np_D=np.delete(np_D,index,axis=0) 22 | np_Dmax, np_Dmin = np_D.max(axis=0), np_D.min(axis=0) 23 | if if_nor: 24 | np_D = (np_D - np_Dmin) / (np_Dmax - np_Dmin) 25 | print('已归一化的训练集,大小为:', np_D.shape) 26 | return np_D,np_Dmax,np_Dmin 27 | else: 28 | print('未归一化的训练集,大小为:', np_D.shape) 29 | return np_D, np_Dmax, np_Dmin 30 | 31 | #加载测试数据,默认进行归一化 32 | def Testdata(name_string,np_Dmax,np_Dmin,if_nor=True): 33 | dict_obj = io.loadmat(name_string) 34 | np_Kobs = dict_obj['ae_Kobs2'] 35 | np_Kobs = np_Kobs[:, 4:] 36 | if if_nor: 37 | np_Kobs = (np_Kobs - np_Dmin) / (np_Dmax - np_Dmin) 38 | return np_Kobs 39 | else: 40 | return np_Kobs 41 | 42 | #加载故障数据,默认进行归一化 43 | def Faultdata(name_string,np_Dmax,np_Dmin,if_nor=True): 44 | dict_obj = io.loadmat(name_string) 45 | np_Kobs = dict_obj['ae_ver_temp'] 46 | np_Kobs = np_Kobs[:, 4:] 47 | if if_nor: 48 | np_Kobs = (np_Kobs - np_Dmin) / (np_Dmax - np_Dmin) 49 | return np_Kobs 50 | else: 51 | return np_Kobs 52 | #归一化 53 | def normalization(np_Kobs,np_Dmax,np_Dmin): 54 | np_Kobs = (np_Kobs - np_Dmin) / (np_Dmax - np_Dmin) 55 | return np_Kobs 56 | 57 | #模型训练,返回记忆矩阵 58 | def MemoryMat_train(np_D,memorymat_name): 59 | memorymat = np.zeros((1, np_D.shape[1])) 60 | for i in range(np_D.shape[1]): 61 | for k in range(step): 62 | for j in range(np_D.shape[0]): 63 | if np.abs(np_D[j,i]-k*(1/step))thres2: 83 | np_D3 = np.vstack((np_D3, np_D[t])) 84 | else: 85 | np_D2 = np.vstack((np_D2, np_D[t])) 86 | np_D1 = np.delete(np_D1, 0, axis=0) 87 | np_D2 = np.delete(np_D2, 0, axis=0) 88 | np_D3 = np.delete(np_D3, 0, axis=0) 89 | print('D1,D2,D3:',np_D1.shape,np_D2.shape,np_D3.shape) 90 | #建立不同负荷段的记忆矩阵 91 | memorymat1 = np.zeros((1, np_D1.shape[1])) 92 | for i in range(np_D1.shape[1]): 93 | for k in range(step): 94 | for j in range(np_D1.shape[0]): 95 | if np.abs(np_D1[j, i] - k * (1 / step)) < delta: 96 | memorymat1 = np.vstack((memorymat1, np_D1[j])) 97 | break 98 | memorymat1 = np.delete(memorymat1, 0, axis=0) 99 | print('memorymat1:', memorymat1.shape) 100 | memorymat2 = np.zeros((1, np_D2.shape[1])) 101 | for i in range(np_D2.shape[1]): 102 | for k in range(step): 103 | for j in range(np_D2.shape[0]): 104 | if np.abs(np_D2[j, i] - k * (1 / step)) < delta: 105 | memorymat2 = np.vstack((memorymat2, np_D2[j])) 106 | break 107 | memorymat2 = np.delete(memorymat2, 0, axis=0) 108 | print('memorymat2:', memorymat2.shape) 109 | memorymat3 = np.zeros((1, np_D3.shape[1])) 110 | for i in range(np_D3.shape[1]): 111 | for k in range(step): 112 | for j in range(np_D3.shape[0]): 113 | if np.abs(np_D3[j, i] - k * (1 / step)) < delta: 114 | memorymat3 = np.vstack((memorymat3, np_D3[j])) 115 | break 116 | memorymat3 = np.delete(memorymat3, 0, axis=0) 117 | print('memorymat3:', memorymat3.shape) 118 | return memorymat1,memorymat2,memorymat3 119 | 120 | #计算保存记忆矩阵的Temp矩阵 121 | def Temp_MemMat(memorymat,Temp_name): 122 | memorymat_row = memorymat.shape[0] 123 | Temp = np.zeros((memorymat_row, memorymat_row)) 124 | for i in range(memorymat_row): 125 | for j in range(memorymat_row): 126 | Temp[i, j] = np.linalg.norm(memorymat[i] - memorymat[j]) 127 | np.save(Temp_name,Temp) 128 | 129 | #MSET计算,被MSETs调用 130 | def MSET(memorymat_name,Kobs,Temp_name):#Temp为临时计算的矩阵 131 | memorymat=np.load(memorymat_name)#加载记忆矩阵 132 | memorymat_row=memorymat.shape[0] 133 | Kobs_row=Kobs.shape[0] 134 | Temp=np.load(Temp_name) 135 | Temp1=np.zeros((memorymat_row,Kobs_row)) 136 | for m in range(memorymat_row): 137 | for n in range(Kobs_row): 138 | Temp1[m,n]=np.linalg.norm(memorymat[m] - Kobs[n]) 139 | Kest=np.dot(np.dot(memorymat.T,(np.linalg.pinv(Temp))),Temp1) 140 | Kest=Kest.T 141 | return Kest 142 | #判断输入的观测向量,再传到相应记忆矩阵中,得到估计值 143 | def MSETs(memorymat1_name,memorymat2_name,memorymat3_name,Kobs): 144 | row_Kobs=Kobs.shape[0] 145 | col_Kobs = Kobs.shape[1] 146 | Kest=np.zeros((row_Kobs,col_Kobs)) 147 | for t in range(row_Kobs): 148 | if Kobs[t,col_Kobs-1]<1/3: 149 | Kest[t] = MSET(memorymat1_name,Kobs[t:t+1,:],'Temp_low.npy') 150 | elif Kobs[t,col_Kobs-1]>2/3: 151 | Kest[t] = MSET(memorymat3_name, Kobs[t:t+1,:],'Temp_hig.npy') 152 | else: 153 | Kest[t] = MSET(memorymat2_name,Kobs[t:t+1,:],'Temp_med.npy') 154 | return Kest 155 | 156 | #基于融合距离的相似度计算 157 | def Cal_sim(Kobs,Kest): 158 | dist_norm = np.zeros((Kobs.shape[0],1)) 159 | dist_cos = np.zeros((Kobs.shape[0], 1)) 160 | for i in range(Kobs.shape[0]): 161 | dist_norm[i]=np.linalg.norm(Kobs[i, :] - Kest[i, :]) # 欧式距离 162 | dist_cos[i]= np.dot(Kobs[i, :], Kest[i, :]) /\ 163 | (np.linalg.norm(Kobs[i, :]) * np.linalg.norm(Kest[i, :])) # dot向量内积,norm向量二范数 164 | dist_cos= dist_cos* 0.5 + 0.5 # 余弦距离平移至[0,1] 165 | sim = (1 / (1 + dist_norm / dist_cos)) # 相似度公式 166 | return sim 167 | 168 | # 根据区间统计的思想确定动态阈值 169 | def Cal_thres(sim): 170 | mu = np.zeros((sim.shape[0], 1)) 171 | sigma = np.zeros((sim.shape[0], 1)) 172 | index=np.empty((1,),dtype=int) 173 | for i in range(sim.shape[0]): 174 | if i==0: 175 | mu[i]=sim[i] 176 | else: 177 | # 相似度大于动态阈值且大于0.8,更新动态阈值 178 | if sim[i-1] >= (mu[i-1] - z * sigma[i-1]) and sim[i-1]>=0.8: 179 | mu[i]=1/(i+1)*sim[i]+i/(i+1)*sim[i-1] 180 | sigma[i]=np.sqrt((i-1)/i*(sigma[i-1]**2)+((sim[i]-mu[i-1])**2/(i+1))) 181 | # 相似度小于动态阈值或相似度大于动态阈值且小于0.8,不更新 182 | elif sim[i-1]<(mu[i-1] - z * sigma[i-1])or \ 183 | (sim[i-1] >= (mu[i-1] - z * sigma[i-1]) and sim[i-1]<0.8): 184 | mu[i]=mu[i-1] 185 | sigma[i]=sigma[i-1] 186 | index=np.append(index,i) 187 | index=np.delete(index,0) 188 | thres=mu-z*sigma 189 | return thres,index 190 | 191 | #各变量及其误差的可视化 192 | def pic_vars(label,Kobs,Kest,np_Dmax,np_Dmin): 193 | Kobs = Kobs * (np_Dmax - np_Dmin) + np_Dmin # 反归一化 194 | Kest = Kest * (np_Dmax - np_Dmin) + np_Dmin # 反归一化 195 | col_num=Kobs.shape[1] 196 | e=np.ones((Kobs.shape[0],Kobs.shape[1])) 197 | plt.ion() 198 | plt.rcParams['font.sans-serif'] = ['SimHei'] # 图片显示中文 199 | plt.rcParams['axes.unicode_minus'] = False 200 | for i in range(col_num): 201 | plt.subplot(211) 202 | plt.gca().yaxis.set_major_formatter(ticker.FormatStrFormatter('%.1f')) 203 | plt.plot(Kobs[:, i], 'steelblue', label='观测值', lw=1.5) 204 | plt.plot(Kest[:, i], 'indianred', label='估计值', lw=1.5) 205 | plt.legend(loc='upper right', fontsize=13) 206 | plt.xlabel('样本序号', fontsize=20) 207 | plt.ylabel(label[i], fontsize=20, verticalalignment='bottom') 208 | plt.xticks(fontsize=20) 209 | plt.yticks(fontsize=20) 210 | plt.subplot(212) 211 | plt.gca().yaxis.set_major_formatter(ticker.FormatStrFormatter('%.1f')) 212 | e[:, i] = (np.abs(Kobs[:, i] - Kest[:, i]) / Kobs[:, i]) * 100 213 | plt.plot(e[:, i], 'peru', lw=1) # 偏离度 214 | plt.xlabel('样本序号', fontsize=20) 215 | plt.ylabel('相对误差/%', fontsize=20) 216 | plt.xticks(fontsize=20) 217 | plt.yticks(fontsize=18) 218 | plt.show() 219 | np.set_printoptions(formatter={'float': '{: 0.4f}'.format}) 220 | 221 | #误差贡献率 222 | def error_contribution(Kobs,Kest,momtent,label): 223 | error=(Kobs - Kest)**2 224 | error_cont =[] 225 | for row in error: 226 | error_cont.append(row/row.sum()) 227 | plt.ion() 228 | plt.rcParams['font.sans-serif'] = ['SimHei'] # 图片显示中文 229 | plt.rcParams['axes.unicode_minus'] = False 230 | plt.bar(np.arange(1,Kobs.shape[1]+1,1), error_cont[momtent]) 231 | plt.xticks(range(1, Kobs.shape[1]+1, 1), label, rotation=80) 232 | plt.title('1min内第%d时刻各变量的误差贡献率'%(momtent+1)) 233 | plt.show() 234 | 235 | # 累计误差贡献率 236 | def Accumu_errorContirbution(Kobs,Kest,momtent,time_range,label): 237 | if time_range==0: 238 | print('Warning:time_range cannot be zero') 239 | return 240 | else: 241 | error = (Kobs - Kest) ** 2 242 | error_cont = np.zeros((1,Kobs.shape[1])) 243 | for i in range(time_range): 244 | error_cont += error[momtent+i]/error[momtent+i].sum() 245 | error_cont = np.squeeze(error_cont/time_range) 246 | plt.ion() 247 | plt.rcParams['font.sans-serif'] = ['SimHei'] # 图片显示中文 248 | plt.rcParams['axes.unicode_minus'] = False 249 | plt.bar(np.arange(1,Kobs.shape[1]+1,1) ,error_cont) 250 | plt.xticks(range(1,Kobs.shape[1]+1,1),label,rotation=80) 251 | plt.title('1min内第%d个时刻发出预警起的累计误差贡献率' % (momtent+1)) 252 | plt.show() 253 | 254 | #更新记忆矩阵 255 | def Mat_update(Kobs,sim,thres,memorymat_name,Temp_name): 256 | Kobs_row=Kobs.shape[0] 257 | Kobs_col = Kobs.shape[1] 258 | k_index=np.arange(201,301,1) 259 | break_flag=False 260 | mat_temp = [] 261 | for i in range(Kobs_row): 262 | if sim[i]>thres :#判断观测向量是否正常 263 | for k,k_in in enumerate(k_index): 264 | for j in range(Kobs_col): 265 | if np.abs(Kobs[i,j] - k_in * (1 / step)) < delta: 266 | mat_temp.append(Kobs[i]) 267 | print('add state') 268 | break_flag=True 269 | break 270 | if break_flag==True: 271 | break 272 | mat_temp= np.array(mat_temp, dtype=float) 273 | print('size of mat_temp:',mat_temp.shape) 274 | # Temp_MemMat(memorymat,Temp_name) 275 | # print('size of memorymat',memorymat.shape) 276 | # np.save(memorymat_name,memorymat) 277 | return mat_temp 278 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MSET_python 2 | ## Python implementation of multivariate state estimation technology 3 | 该项目为多元状态估计技术的python实现,主要包含`训练与测试数据`(.mat文件)、`模型`(Model.py)以及`测试例子`(example.py)
4 | 其中`ae_D_temp`为训练数据,`ae_Kobs3_temp`为正常测试数据,`ae_ver_temp`为磨煤机堵煤故障数据,数据集包含风粉混合物温度等14个变量。 5 | ### `Model.py`包含以下功能:
6 | #### 输入文件名列表,加载训练数据,默认对数据进行归一化
7 | ``` 8 | Traindata(name_list,if_nor=True) 9 | ``` 10 | #### 加载测试数据,默认进行归一化
11 | ``` 12 | Testdata(name_string,np_Dmax,np_Dmin,if_nor=True) 13 | ``` 14 | #### 加载故障数据,默认进行归一化
15 | ``` 16 | Faultdata(name_string,np_Dmax,np_Dmin,if_nor=True) 17 | ``` 18 | #### 归一化模块,适合用于需对原始数据进行操作而未进行归一化的数据
19 | ``` 20 | normalization(np_Kobs,np_Dmax,np_Dmin) 21 | ``` 22 | #### 模型训练,返回记忆矩阵
23 | ``` 24 | MemoryMat_train(np_D,memorymat_name) 25 | ``` 26 | #### 多模型训练,分高中低负荷建立模型,返回三个记忆矩阵
27 | ``` 28 | MemoryMats_train(np_D) 29 | ``` 30 | #### 计算保存记忆矩阵的Temp矩阵,在每次输入观测向量,计算估计值时,可直接加载Temp,减少运算量
31 | ``` 32 | Temp_MemMat(memorymat,Temp_name) 33 | ``` 34 | #### 输入记忆矩阵、观测向量以及Temp矩阵,返回对应的估计向量
35 | ``` 36 | MSET(memorymat_name,Kobs,Temp_name) 37 | ``` 38 | #### 对于输入的观测向量先划分负荷段,再传到相应记忆矩阵中,得到估计值
39 | ``` 40 | MSETs(memorymat1_name,memorymat2_name,memorymat3_name,Kobs) 41 | ``` 42 | #### 基于融合距离的相似度计算
43 | ``` 44 | Cal_sim(Kobs,Kest) 45 | ``` 46 | #### 根据区间统计的思想确定动态阈值,动态阈值的更新与当前时刻及前一时刻的相似度均值、方差相关
47 | >PS.为了避免在故障发生时阈值随相似度一直下降发生漏报,在阈值更新的触发条件上引入新的限制,即:相似度大于动态阈值且大于0.8,更新动态阈值;相似度小于动态阈值或相似度大于动态阈值且小于0.8,则不更新 48 | ``` 49 | Cal_thres(sim) 50 | ``` 51 | #### 各变量及其误差的可视化
52 | ``` 53 | pic_vars(label,Kobs,Kest,np_Dmax,np_Dmin) 54 | ``` 55 | #### 误差贡献率
56 | ``` 57 | error_contribution(Kobs,Kest,momtent,label) 58 | ``` 59 | #### 累计误差贡献率
60 | ``` 61 | Accumu_errorContirbution(Kobs,Kest,momtent,time_range,label) 62 | ``` 63 | #### 更新记忆矩阵,目前该函数未可用
64 | ``` 65 | Mat_update(Kobs,sim,thres,memorymat_name,Temp_name) 66 | ``` 67 | -------------------------------------------------------------------------------- /Temp1.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaobinbin0827/MSET_python/0dce7c0df145518f7bcdb85029bbd5f595dc516c/Temp1.npy -------------------------------------------------------------------------------- /ae_D0_temp.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaobinbin0827/MSET_python/0dce7c0df145518f7bcdb85029bbd5f595dc516c/ae_D0_temp.mat -------------------------------------------------------------------------------- /ae_D1_temp.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaobinbin0827/MSET_python/0dce7c0df145518f7bcdb85029bbd5f595dc516c/ae_D1_temp.mat -------------------------------------------------------------------------------- /ae_D2_temp.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaobinbin0827/MSET_python/0dce7c0df145518f7bcdb85029bbd5f595dc516c/ae_D2_temp.mat -------------------------------------------------------------------------------- /ae_Kobs3_temp.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaobinbin0827/MSET_python/0dce7c0df145518f7bcdb85029bbd5f595dc516c/ae_Kobs3_temp.mat -------------------------------------------------------------------------------- /ae_ver_temp.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaobinbin0827/MSET_python/0dce7c0df145518f7bcdb85029bbd5f595dc516c/ae_ver_temp.mat -------------------------------------------------------------------------------- /example.py: -------------------------------------------------------------------------------- 1 | from Model import * 2 | from Fault_modify import * 3 | 4 | N=60#每次输入60个观测向量 5 | label1=('风粉混合物温度/℃','反作用力加载油压/MPa','加载油压/MPa', 6 | '磨煤机电流/A','一次风压力/kPa','密封风母管压力/kPa', 7 | '一次风与密封风差压/kPa', '出入口差压/kPa','油箱油温/℃', 8 | '一次风流量/t·h-1','轴承温度/℃','推力瓦温/℃', 9 | '油池油温/℃','实际功率/MW') 10 | label2=('1风粉混合物温度','2反作用力加载油压','3加载油压', 11 | '4磨煤机电流','5一次风压力','6密封风母管压力', 12 | '7一次风与密封风差压', '8出入口差压','9油箱油温', 13 | '10一次风流量','11轴承温度','12推力瓦温', 14 | '13油池油温','14实际功率') 15 | 16 | name_list=['ae_D0_temp','ae_D1_temp','ae_D2_temp']#数据文件名列表 17 | np_D,np_Dmax,np_Dmin=Traindata(name_list,if_nor=True)#加载训练集 18 | # memorymat=MemoryMat_train(np_D,'memorymat1.npy')#训练得到记忆矩阵 19 | # Temp_MemMat(memorymat,'Temp1.npy')#保存MSET计算用的临时矩阵 20 | # Kobs=Testdata('ae_Kobs3_temp',np_Dmax,np_Dmin,if_nor=True) #加载测试集 21 | Kobs=Faultdata('ae_ver_temp',np_Dmax,np_Dmin,if_nor=True) #加载故障集 22 | Kobs=Kobs[0:1140,:]#故障集共1185个点,取前1140个,被60整除 23 | # 将观测值与估计值输入值循环输入得到 24 | sim=np.zeros((Kobs.shape[0],1)) 25 | thres=np.zeros((Kobs.shape[0],1)) 26 | Kest=np.zeros((Kobs.shape[0],Kobs.shape[1])) 27 | for i in range(int(Kobs.shape[0]/N)): 28 | # 加载记忆矩阵与临时矩阵,输入观测向量,计算对应估计向量 29 | Kest[i*N:(i+1)*N] = MSET(memorymat_name='memorymat1.npy', 30 | Kobs=Kobs[i*N:(i+1)*N], Temp_name='Temp1.npy') 31 | sim[i*N:(i+1)*N]=Cal_sim(Kobs[i*N:(i+1)*N],Kest[i*N:(i+1)*N]) 32 | thres[i*N:(i+1)*N],warning_index=Cal_thres(sim[i*N:(i+1)*N]) 33 | if any(warning_index): 34 | #如果故障索引存在值,打印该点编号并显示误差贡献率 35 | print('第%d次循环中的故障点:' % (i + 1), warning_index) 36 | error_contribution(Kobs[i*N:(i+1)*N],Kest[i*N:(i+1)*N],warning_index[0],label2) 37 | Accumu_errorContirbution(Kobs[i*N:(i+1)*N], Kest[i*N:(i+1)*N] 38 | ,warning_index[0], N-warning_index[0],label2) 39 | # 画图 40 | pic_vars(label1,Kobs,Kest,np_Dmax,np_Dmin)#各变量的估计结果及误差 41 | plt.ion() 42 | plt.plot(sim,label='相似度曲线') 43 | plt.plot(thres,label='动态阈值') 44 | plt.ylim((0,1)) 45 | plt.legend() 46 | plt.show() 47 | -------------------------------------------------------------------------------- /example_introd.md: -------------------------------------------------------------------------------- 1 | example.py介绍 2 | ===== 3 | * 该文件实现了MSET的全流程,包括加载数据、训练数据、计算观测向量的估计值、相似度 4 | >部分代码: 5 | ``` 6 | name_list=['ae_D0_temp','ae_D1_temp','ae_D2_temp']#数据文件名列表 7 | np_D,np_Dmax,np_Dmin=Traindata(name_list,if_nor=True)#加载训练集 8 | # memorymat=MemoryMat_train(np_D,'memorymat1.npy')#训练得到记忆矩阵 9 | # Temp_MemMat(memorymat,'Temp1.npy')#保存MSET计算用的临时矩阵 10 | # Kobs=Testdata('ae_Kobs3_temp',np_Dmax,np_Dmin,if_nor=True) #加载测试集 11 | Kobs=Faultdata('ae_ver_temp',np_Dmax,np_Dmin,if_nor=True) #加载故障集 12 | ``` 13 | ``` 14 | for i in range(int(Kobs.shape[0]/N)): 15 | Kest[i*N:(i+1)*N] = MSET(memorymat_name='memorymat1.npy', 16 | Kobs=Kobs[i*N:(i+1)*N], Temp_name='Temp1.npy') 17 | sim[i*N:(i+1)*N]=Cal_sim(Kobs[i*N:(i+1)*N],Kest[i*N:(i+1)*N]) 18 | thres[i*N:(i+1)*N],warning_index=Cal_thres(sim[i*N:(i+1)*N]) 19 | ``` 20 | ``` 21 | pic_vars(label1,Kobs,Kest,np_Dmax,np_Dmin)#各变量的估计结果及误差 22 | ``` 23 | ----- 24 | * 对于故障数据,在监测到故障时给出对应的时刻点,并显示误差贡献图与累计误差贡献图 25 | >部分代码: 26 | ``` 27 | if any(warning_index): 28 | #如果故障索引存在值,打印该点编号并显示误差贡献率 29 | print('第%d次循环中的故障点:' % (i + 1), warning_index) 30 | error_contribution(Kobs[i*N:(i+1)*N],Kest[i*N:(i+1)*N],warning_index[0],label2) 31 | Accumu_errorContirbution(Kobs[i*N:(i+1)*N], Kest[i*N:(i+1)*N],warning_index[0], N-warning_index[0],label2) 32 | ``` 33 | ------ 34 | * 输入磨煤机堵煤故障数据,部分结果如下: 35 | >![figure 1](https://github.com/xiaobinbin0827/MSET_python/blob/master/img-folder/sim.png) 36 | >![figure 2](https://github.com/xiaobinbin0827/MSET_python/blob/master/img-folder/error_contribution.png) 37 | >![figure 3](https://github.com/xiaobinbin0827/MSET_python/blob/master/img-folder/Acc_errorContribution.png) 38 | -------------------------------------------------------------------------------- /img-folder/Acc_errorContribution.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaobinbin0827/MSET_python/0dce7c0df145518f7bcdb85029bbd5f595dc516c/img-folder/Acc_errorContribution.png -------------------------------------------------------------------------------- /img-folder/README.md: -------------------------------------------------------------------------------- 1 | # 文件夹图片为example.py的部分结果图 2 | -------------------------------------------------------------------------------- /img-folder/error_contribution.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaobinbin0827/MSET_python/0dce7c0df145518f7bcdb85029bbd5f595dc516c/img-folder/error_contribution.png -------------------------------------------------------------------------------- /img-folder/sim.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaobinbin0827/MSET_python/0dce7c0df145518f7bcdb85029bbd5f595dc516c/img-folder/sim.png -------------------------------------------------------------------------------- /memorymat1.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaobinbin0827/MSET_python/0dce7c0df145518f7bcdb85029bbd5f595dc516c/memorymat1.npy --------------------------------------------------------------------------------