Commit ef592c07 authored by cif2cif's avatar cif2cif
Browse files

Reescritos READMEs y reorganización

parent a5f55eca
# SecureGrid
Deep Learning based Attack Detection System for Smart Grids
## Required modules
* Keras
* There is a recognized bug in numpy 1.16.3. Thus, the numpy version should be 1.16.1.
pip uninstall numpy
pip install --upgrade numpy==1.16.1
# Mosaik
For running the demo number of packages are needed:
sudo apt-get install git python3-numpy python3-scipy python3-h5py
In addition, there is a bug in arrow in mosaik demo, so you should install the version arrow 0.14:
pip install arrow==0.14
Execute
python securegrid-demo.py
After finishing, you will have the simulation data in the file demo.hdf5
You can visualize this file with any hdf5 viewer.
In our case, we are using ViTables (http://vitables.org/Download/).
If you desire to install it, follow the installation instructions.
The suggested process is:
apt install libhdf5-dev
pip install pyqt5
pip install vitables
Then execute 'vitables' in a terminal.
If you wish to visualize the scenario, you can install maverig: https://bitbucket.org/mosaik/maverig/src/master/. Basically
pip install maverig
## Usage
In order to detect attacks, the power consumption values of the houses are analyzed. For that reason, first, the needed DataFrames to feed the neural network (autoencoder) have to be created.
For this purpose, the notebook dataframe_creation is used. This notebook generates .pkl files that contain the DataFrames with the necessary data. In addition, these DataFrames contain the following features:
| Feature | Description |
| ------------- | ------------- |
| Day | Current day of the first window value |
| Hour | Current hour of the first window value |
| Minute | Current minute of the first window value |
| Pn | Power consumption window values |
| Mean | Mean of the window values |
| Mean_i - Mean_i-1 | Difference between the mean of the window values and the mean of the previous window values |
| s | Standard deviation of the window values |
| Pn - P1 | Difference between the last and first value of the window |
| Q1 | First quartile of the window values |
| Q2 | Median of the window values |
| Q3 | Third quartile of the window values |
| IQR | Interquartile range of the window values |
For executing the dataframe, it is needed to install the package h5py
pip install h5py
Once the DataFrames are created, they are used to feed the autoencoder. Therefore, the conv1d_autoencoder.py file has to be configured.
The normal_data_path variable has to contain the path to the .pkl file that contains data without attacks, that is to say, a normal behaviour of the houses. In addition, the attack_data_path variable has to contain the path to the .pkl file that contains the data that is wanted to be analyzed in order to detect attacks.
Furthermore, in order to train the autoencoder, the DO_TRAINING variable has to be set to True.
Finally, the following command executes the system:
$ python conv1d_autoencoder.py
## Results
Once the system is executed, it generates the predicted_labels.csv file that contains the labels that classify every entry of the DataFrame into attack (1) or normal behaviour (0).
This directory contains an attack detector developed with the deep learning library Keras.
## Installation
$ pip install keras
* There is a recognized bug in numpy 1.16.3. Thus, the numpy version should be 1.16.1.
$ pip uninstall numpy
$ pip install --upgrade numpy==1.16.1
## Configuration
The file `conv1d_autoencoder.py' should be configured as follows:
* variable `normal_data_path`: path to the .pkl file that contains data without attacks, that is to say, a normal behaviour of the houses.
* variable `attack_data_path`: path to the .pkl file that contains the data that is wanted to be analyzed in order to detect attacks.
* variable `DO_TRAINING`: it should be set to True in order to train the autoencoder
## Usage
$ python conv1d_autoencoder.py
## Results
Once the system is executed, it generates the file `predicted_labels.csv`. It contains the labels that classify every entry of the DataFrame into attack (1) or normal behaviour (0).
The file has 2970 rows. Every entry corresponds to the result during the 15 minutes slot.
The result of the simulation was the file P_out for every house. This filehas 44.640 values, since the simulator generates data every minute for a month (60 minutes * 24 hours * 31 days).
Then the preprocessing module created a dataframe (d_15) with a window of 15 minutes (44640 / 15 = 2970).
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
0
0
0
0
0
0
0
0
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