|
Algorithm 1 LSTM and Petri Net Workflow for IDS |
-
1:
Data Preprocessing:
-
2:
Load dataset
-
3:
Balance benign and attack packets
-
4:
Labels mapping (0 for benign, 1 for attack)
-
5:
Handle missing and infinite values
-
6:
Standardize features
-
7:
Remove highly correlated features
-
8:
Apply PCA to reduce dimensionality
-
9:
Prepare Data for LSTM:
-
10:
Convert data to sequences of window size 50
-
11:
Split data into training, validation, and test sets
-
12:
LSTM Model Training:
-
13:
Define LSTM model with layers
-
14:
Compile model with binary cross-entropy loss and Adam optimizer
-
15:
Train model with training and validation data
-
16:
Save trained model
-
17:
LSTM Model Evaluation:
-
18:
Evaluate model on test data
-
19:
Calculate confusion matrix and classification report
-
20:
Petri Net Definition:
-
21:
Define places:
-
22:
Define transitions:
-
23:
Define arcs:
-
24:
:
-
25:
: &
-
26:
: &
-
27:
: &
-
28:
Petri Net Execution:
-
29:
Initialize Petri Net with test data
-
30:
for to 10 do
-
31:
Fire transition to simulate packet arrival
-
32:
for to 50 do
-
33:
Wait for next packet
-
34:
Fire transition to simulate packet arrival
-
35:
end for
-
36:
Fire transition to predict packet flow using LSTM
-
37:
if has token and does not then
-
38:
Fire transition (Benign packet flow)
-
39:
Store packets in non-blocked list
-
40:
else
-
41:
Fire transition (Attack packet flow)
-
42:
Store packets in blocked list
-
43:
end if
-
44:
Move to next set of packets
-
45:
end for
|