| 
				
			 | 
			
			
				@@ -123,7 +123,7 @@ def plotData(): 
			 | 
		
	
		
			
			| 
				123
			 | 
			
				123
			 | 
			
			
				 NumFilters=64 
			 | 
		
	
		
			
			| 
				124
			 | 
			
				124
			 | 
			
			
				 KernelSize=7 
			 | 
		
	
		
			
			| 
				125
			 | 
			
				125
			 | 
			
			
				 DropOut=0.2 
			 | 
		
	
		
			
			| 
				126
			 | 
			
				
			 | 
			
			
				-ThresholdFactor=1.7 
			 | 
		
	
		
			
			| 
				
			 | 
			
				126
			 | 
			
			
				+ThresholdFactor=2 
			 | 
		
	
		
			
			| 
				127
			 | 
			
				127
			 | 
			
			
				 TIME_STEPS = 48 
			 | 
		
	
		
			
			| 
				128
			 | 
			
				128
			 | 
			
			
				 def create_sequences(values, time_steps=TIME_STEPS): 
			 | 
		
	
		
			
			| 
				129
			 | 
			
				129
			 | 
			
			
				     output = [] 
			 | 
		
	
	
		
			
			| 
				
			 | 
			
			
				@@ -239,6 +239,7 @@ for i in range(1,NumberOfFailures+1): 
			 | 
		
	
		
			
			| 
				239
			 | 
			
				239
			 | 
			
			
				     rnext=r+dataTestNorm[i].shape[0] 
			 | 
		
	
		
			
			| 
				240
			 | 
			
				240
			 | 
			
			
				     testRanges.append([r,rnext] ) 
			 | 
		
	
		
			
			| 
				241
			 | 
			
				241
			 | 
			
			
				     r=rnext 
			 | 
		
	
		
			
			| 
				
			 | 
			
				242
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				242
			 | 
			
				243
			 | 
			
			
				 testRanges.append([r, x_test.shape[0]+TIME_STEPS  ]) 
			 | 
		
	
		
			
			| 
				243
			 | 
			
				244
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				244
			 | 
			
				245
			 | 
			
			
				  
			 | 
		
	
	
		
			
			| 
				
			 | 
			
			
				@@ -345,7 +346,6 @@ def anomalyMetric(testList):  # first of list is non failure data 
			 | 
		
	
		
			
			| 
				345
			 | 
			
				346
			 | 
			
			
				 anomalyMetric([dataTestNorm[0],dataTestNorm[1],dataTestNorm[2],dataTestNorm[3],dataTestNorm[4]]) 
			 | 
		
	
		
			
			| 
				346
			 | 
			
				347
			 | 
			
			
				 plotData2() 
			 | 
		
	
		
			
			| 
				347
			 | 
			
				348
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				348
			 | 
			
				
			 | 
			
			
				-exit(0) 
			 | 
		
	
		
			
			| 
				349
			 | 
			
				349
			 | 
			
			
				 #   2nd scenario. Go over anomalies and classify it by less error 
			 | 
		
	
		
			
			| 
				350
			 | 
			
				350
			 | 
			
			
				 '''    
			 | 
		
	
		
			
			| 
				351
			 | 
			
				351
			 | 
			
			
				 #This code works, but too slow 
			 | 
		
	
	
		
			
			| 
				
			 | 
			
			
				@@ -370,17 +370,20 @@ for i in anomalous_data_indices: 
			 | 
		
	
		
			
			| 
				370
			 | 
			
				370
			 | 
			
			
				     anomalous_data_type.append(np.argmin(error)+1) 
			 | 
		
	
		
			
			| 
				371
			 | 
			
				371
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				372
			 | 
			
				372
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				373
			 | 
			
				
			 | 
			
			
				-# For plotting purposes 
			 | 
		
	
		
			
			| 
				374
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				375
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				376
			 | 
			
				373
			 | 
			
			
				 anomalous_data_indices_by_failure=[] 
			 | 
		
	
		
			
			| 
				377
			 | 
			
				374
			 | 
			
			
				 for i in range(NumberOfFailures+1): 
			 | 
		
	
		
			
			| 
				378
			 | 
			
				375
			 | 
			
			
				     anomalous_data_indices_by_failure.append([]) 
			 | 
		
	
		
			
			| 
				379
			 | 
			
				376
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				380
			 | 
			
				377
			 | 
			
			
				 for i in range(len(anomalous_data_indices)): 
			 | 
		
	
		
			
			| 
				381
			 | 
			
				
			 | 
			
			
				-    print(i," ",anomalous_data_type[i]) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				378
			 | 
			
			
				+    #print(i," ",anomalous_data_type[i]) 
			 | 
		
	
		
			
			| 
				382
			 | 
			
				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
			 | 
			
				388
			 | 
			
			
				 def plotData3(): 
			 | 
		
	
		
			
			| 
				386
			 | 
			
				389
			 | 
			
			
				     NumFeaturesToPlot=len(indexesToPlot) 
			 | 
		
	
	
		
			
			| 
				
			 | 
			
			
				@@ -391,22 +394,21 @@ def plotData3(): 
			 | 
		
	
		
			
			| 
				391
			 | 
			
				394
			 | 
			
			
				         init=0 
			 | 
		
	
		
			
			| 
				392
			 | 
			
				395
			 | 
			
			
				         end=len(x_train[0]) 
			 | 
		
	
		
			
			| 
				393
			 | 
			
				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
			 | 
			
				397
			 | 
			
			
				         init=end 
			 | 
		
	
		
			
			| 
				396
			 | 
			
				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
			 | 
			
				400
			 | 
			
			
				         init=end 
			 | 
		
	
		
			
			| 
				399
			 | 
			
				401
			 | 
			
			
				         end+=(testRanges[1][1]-testRanges[1][0]) 
			 | 
		
	
		
			
			| 
				400
			 | 
			
				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
			 | 
			
				404
			 | 
			
			
				             init=end 
			 | 
		
	
		
			
			| 
				403
			 | 
			
				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
			 | 
			
				409
			 | 
			
			
				         init=end-(testRanges[NumberOfFailures+1][1]-testRanges[NumberOfFailures+1][0]) 
			 | 
		
	
		
			
			| 
				408
			 | 
			
				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
			 | 
			
				413
			 | 
			
			
				         if i==0: 
			 | 
		
	
		
			
			| 
				412
			 | 
			
				414
			 | 
			
			
				             axes[i].legend(bbox_to_anchor=(1, 0.5)) 
			 | 
		
	
	
		
			
			| 
				
			 | 
			
			
				@@ -418,3 +420,8 @@ def plotData3(): 
			 | 
		
	
		
			
			| 
				418
			 | 
			
				420
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				419
			 | 
			
				421
			 | 
			
			
				 anomalyMetric([dataTestNorm[0],dataTestNorm[1],dataTestNorm[2],dataTestNorm[3],dataTestNorm[4]]) 
			 | 
		
	
		
			
			| 
				420
			 | 
			
				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 
			 |