cesar 8 hours ago
parent
commit
d788f8e5d7

BIN
model_v1_0._checkpoint.weights.h5 View File


BIN
model_v1_1._checkpoint.weights.h5 View File


BIN
model_v1_2._checkpoint.weights.h5 View File


BIN
model_v1_3._checkpoint.weights.h5 View File


BIN
model_v1_4._checkpoint.weights.h5 View File


+ 1
- 1
v1.py View File

144
         layers.Input(shape=(x_train[0].shape[1], x_train[0].shape[2])),
144
         layers.Input(shape=(x_train[0].shape[1], x_train[0].shape[2])),
145
         layers.Conv1D(
145
         layers.Conv1D(
146
             filters=NumFilters,
146
             filters=NumFilters,
147
-            kernel_size=7,
147
+            kernel_size=KernelSize,
148
             padding="same",
148
             padding="same",
149
             strides=2,
149
             strides=2,
150
             activation="relu",
150
             activation="relu",

+ 19
- 12
v1_multifailure.py View File

123
 NumFilters=64
123
 NumFilters=64
124
 KernelSize=7
124
 KernelSize=7
125
 DropOut=0.2
125
 DropOut=0.2
126
-ThresholdFactor=1.7
126
+ThresholdFactor=2
127
 TIME_STEPS = 48
127
 TIME_STEPS = 48
128
 def create_sequences(values, time_steps=TIME_STEPS):
128
 def create_sequences(values, time_steps=TIME_STEPS):
129
     output = []
129
     output = []
239
     rnext=r+dataTestNorm[i].shape[0]
239
     rnext=r+dataTestNorm[i].shape[0]
240
     testRanges.append([r,rnext] )
240
     testRanges.append([r,rnext] )
241
     r=rnext
241
     r=rnext
242
+
242
 testRanges.append([r, x_test.shape[0]+TIME_STEPS  ])
243
 testRanges.append([r, x_test.shape[0]+TIME_STEPS  ])
243
 
244
 
244
 
245
 
345
 anomalyMetric([dataTestNorm[0],dataTestNorm[1],dataTestNorm[2],dataTestNorm[3],dataTestNorm[4]])
346
 anomalyMetric([dataTestNorm[0],dataTestNorm[1],dataTestNorm[2],dataTestNorm[3],dataTestNorm[4]])
346
 plotData2()
347
 plotData2()
347
 
348
 
348
-exit(0)
349
 #   2nd scenario. Go over anomalies and classify it by less error
349
 #   2nd scenario. Go over anomalies and classify it by less error
350
 '''   
350
 '''   
351
 #This code works, but too slow
351
 #This code works, but too slow
370
     anomalous_data_type.append(np.argmin(error)+1)
370
     anomalous_data_type.append(np.argmin(error)+1)
371
 
371
 
372
 
372
 
373
-# For plotting purposes
374
-
375
-
376
 anomalous_data_indices_by_failure=[]
373
 anomalous_data_indices_by_failure=[]
377
 for i in range(NumberOfFailures+1):
374
 for i in range(NumberOfFailures+1):
378
     anomalous_data_indices_by_failure.append([])
375
     anomalous_data_indices_by_failure.append([])
379
 
376
 
380
 for i in range(len(anomalous_data_indices)):
377
 for i in range(len(anomalous_data_indices)):
381
-    print(i," ",anomalous_data_type[i])
378
+    #print(i," ",anomalous_data_type[i])
382
     anomalous_data_indices_by_failure[anomalous_data_type[i]].append(anomalous_data_indices[i])  
379
     anomalous_data_indices_by_failure[anomalous_data_type[i]].append(anomalous_data_indices[i])  
383
 
380
 
381
+MaxIndex=0
382
+for i in range(1,NumberOfFailures+1):
383
+    MaxIndex=max(MaxIndex,max(anomalous_data_indices_by_failure[i]))
384
+
385
+# Enlarge x_test to plot failure points
386
+XTest=np.vstack((x_test[:,0,:],x_test[-1,1:TIME_STEPS,:]))
384
 
387
 
385
 def plotData3():
388
 def plotData3():
386
     NumFeaturesToPlot=len(indexesToPlot)
389
     NumFeaturesToPlot=len(indexesToPlot)
391
         init=0
394
         init=0
392
         end=len(x_train[0])
395
         end=len(x_train[0])
393
         axes[i].plot(range(init,end),x_train[0][:,0,indexesToPlot[i]],label="normal train")
396
         axes[i].plot(range(init,end),x_train[0][:,0,indexesToPlot[i]],label="normal train")
394
-        #axes.plot(range(len(x_train[0]),len(x_train[0])+len(x_test)),x_test[:,0,0],label="abnormal")
395
         init=end
397
         init=end
396
         end+=testRanges[0][1]
398
         end+=testRanges[0][1]
397
-        axes[i].plot(range(init,end),x_test[testRanges[0][0]:testRanges[0][1],0,indexesToPlot[i]],label="normal test")
399
+        axes[i].plot(range(init,end),XTest[testRanges[0][0]:testRanges[0][1],indexesToPlot[i]],label="normal test")
398
         init=end
400
         init=end
399
         end+=(testRanges[1][1]-testRanges[1][0])
401
         end+=(testRanges[1][1]-testRanges[1][0])
400
         for j in range(1,NumberOfFailures+1):
402
         for j in range(1,NumberOfFailures+1):
401
-            axes[i].plot(range(init,end),x_test[testRanges[j][0]:testRanges[j][1],0,indexesToPlot[i]],label="fail type "+str(j), color=colorline[j-1])
403
+            axes[i].plot(range(init,end),XTest[testRanges[j][0]:testRanges[j][1],indexesToPlot[i]],label="fail type "+str(j), color=colorline[j-1])
402
             init=end
404
             init=end
403
             end+=(testRanges[j+1][1]-testRanges[j+1][0])
405
             end+=(testRanges[j+1][1]-testRanges[j+1][0])
404
-
405
-            axes[i].plot(len(x_train[0])+np.array(anomalous_data_indices_by_failure[j])+TIME_STEPS,x_test[np.array(anomalous_data_indices_by_failure[j])+TIME_STEPS,0,indexesToPlot[i]],color=colordot[j-1],marker='.',linewidth=0,label="abnormal detection type "+str(j))
406
+            ##   MODIFY here as in PRevious Plot
407
+            axes[i].plot(len(x_train[0])+np.array(anomalous_data_indices_by_failure[j])+TIME_STEPS,XTest[np.array(anomalous_data_indices_by_failure[j])+TIME_STEPS,indexesToPlot[i]],color=colordot[j-1],marker='.',linewidth=0,label="abnormal detection type "+str(j))
406
 
408
 
407
         init=end-(testRanges[NumberOfFailures+1][1]-testRanges[NumberOfFailures+1][0])
409
         init=end-(testRanges[NumberOfFailures+1][1]-testRanges[NumberOfFailures+1][0])
408
         end=init+(testRanges[0][1]-testRanges[0][0])
410
         end=init+(testRanges[0][1]-testRanges[0][0])
409
-        axes[i].plot(range(init,end),x_test[testRanges[0][0]:testRanges[0][1],0,indexesToPlot[i]],color='orange')
411
+        axes[i].plot(range(init,end),XTest[testRanges[0][0]:testRanges[0][1],indexesToPlot[i]],color='orange')
410
 
412
 
411
         if i==0:
413
         if i==0:
412
             axes[i].legend(bbox_to_anchor=(1, 0.5))
414
             axes[i].legend(bbox_to_anchor=(1, 0.5))
418
 
420
 
419
 anomalyMetric([dataTestNorm[0],dataTestNorm[1],dataTestNorm[2],dataTestNorm[3],dataTestNorm[4]])
421
 anomalyMetric([dataTestNorm[0],dataTestNorm[1],dataTestNorm[2],dataTestNorm[3],dataTestNorm[4]])
420
 plotData3()
422
 plotData3()
423
+
424
+#  A new anomalyMEtric for multiclass must be defined
425
+    # look at anomalies detected on first stage
426
+    # l0ok at classification of second stage 
427
+    # then: determine if: correct classified  or  bad classified/unclassified

Powered by TurnKey Linux.