GraphSPD论文复现

论文链接:https://csis.gmu.edu/ksun/publications/SP23_GraphSPD.pdf
代码链接:https://github.com/SunLab-GMU/GraphSPD
本文主要参考的就是源码readme

安装

1. 安装OS

  • 我安装的是Ubuntu 20.04桌面版
  • 阿里云下载可能速度会快点
  • 安装教程的话随便找一个参考就好,我的配置如下:
    在这里插入图片描述
  • 建议配置:

RAM: >2GB
Disk: >30GB
CPU: >1 core

2. 下载源码

  • 安装 git
sudo apt install git
  • 将源代码下载到用户的主目录
cd ~
git clone https://github.com/SunLab-GMU/GraphSPD.git

3. 安装依赖

cd ~/GraphSPD/
chmod +x install_dep.sh
./install_dep.sh

4. 容易出错的地方!!!

  • 首先查看安装依赖的python文件,会出现问题的是最后的两个命令
#!/bin/bash

# install pip
sudo apt install python3-pip -y

# install python modules
pip3 install numpy pandas

# install pytorch
pip install torch==1.11.0+cpu torchvision==0.12.0+cpu torchaudio==0.11.0 --extra-index-url https://download.pytorch.org/whl/cpu

# install clang
pip3 install clang==6.0.0.2
sudo apt install clang -y
sudo ln -s /usr/lib/x86_64-linux-gnu/libclang-*.so.1 /usr/lib/x86_64-linux-gnu/libclang.so

# install pytorch-geometric
pip install torch-scatter torch-sparse torch-cluster torch-spline-conv torch-geometric -f https://data.pyg.org/whl/torch-1.11.0+cpu.html

# install java 8
sudo apt-get install openjdk-8-jre

pytorch-geometric安装

  • 我一开始就直接运行的安装文件中的命令,然后得到的版本是这样
    在这里插入图片描述

  • 主要问题就是torch-geometric的版本 2.3.1 过高,我就是卸载之后重装了低版本的

torch-geometric官网可以查看与pytorch对应的版本,torch=1.11.0可用的是 2.1.0 和 2.0.4 ,这俩应该都可以,我重新安装的版本是2.1.0。

# 先卸载再安装
pip uninstall torch-geometric
pip install torch-geometric==2.1.0

java安装

java的版本和joern的版本必须对应
我安装的版本是:jdk11joern2.0.58
如果不知道旧版joern对应的哪个版本的jdk,可以先随便安装一个jdk,如果跟joern的版本不对应的话,在运行joern的时候会出现提示需要哪个版本的jdk,然后删掉错误的jdk版本,重新下载jdk就行。

运行代码

所有的命令都在~/GraphSPD/文件夹下进行
该项目运行在纯CPU环境中

1. 预处理

1.1 使用测试补丁样例

  • ~/GraphSPD/raw_patch/文件夹中有10个测试补丁

  • 首先下载好补丁相关的代码文件

python3 get_ab_file.py nginx nginx 02cca547
python3 get_ab_file.py nginx nginx 661e4086
python3 get_ab_file.py nginx nginx 9a3ec202
python3 get_ab_file.py nginx nginx dac90a4b
python3 get_ab_file.py nginx nginx fc785b12
python3 get_ab_file.py nginx nginx 60a8ed26
python3 get_ab_file.py nginx nginx bd7dad5b
python3 get_ab_file.py nginx nginx 4c5a49ce
python3 get_ab_file.py nginx nginx 71eb19da
python3 get_ab_file.py nginx nginx 56f53316

In the above, the third column refers to the owner (i.e., nginx), the fourth column refers to the repository (i.e., nginx), and the last column refers to the commit ID (e.g., 02cca547).

As the result, the pre-patch and post-patch files will be stored in ~/GraphSPD/ab_file/.

1.2 使用自己的补丁样例

python3 get_ab_file.py [owner] [repository] [commitID]

这里的[owner][repository][commitID]是指Github补丁的作者名、仓库名、commit ID

2. Generate PatchCPGs

  • 生成补丁的PatchCPG
chmod -R +x ./joern
sudo python3 gen_cpg.py
python3 merge_cpg.py
  • gen_cpg.py 会分别生成pre-patch和post-patch文件的CPG
  • merge_cpg.py 会融合两个CPGs为PatchCPG
  • PatchCPGs 保存在 ~/GraphSPD/testdata/

3. 运行PatchGNN模型

  • 运行下面的命令:
python3 test.py
  • 预测结果保存在文件:~/GraphSPD/logs/test_results.txt

  • 运行下面的命令查看结果

cat logs/test_results.txt
  • 预测结果包含PatchCPG文件路径和预测结果,其中1表示安全补丁,0表示非安全补丁
filename,prediction
./testdata/fc785b12/out_slim_ninf_noast_n1_w.log,0
./testdata/dac90a4b/out_slim_ninf_noast_n1_w.log,1
./testdata/60a8ed26/out_slim_ninf_noast_n1_w.log,1
./testdata/71eb19da/out_slim_ninf_noast_n1_w.log,0
./testdata/9a3ec202/out_slim_ninf_noast_n1_w.log,1
./testdata/bd7dad5b/out_slim_ninf_noast_n1_w.log,1
./testdata/661e4086/out_slim_ninf_noast_n1_w.log,1
./testdata/02cca547/out_slim_ninf_noast_n1_w.log,0
./testdata/4c5a49ce/out_slim_ninf_noast_n1_w.log,0
./testdata/56f53316/out_slim_ninf_noast_n1_w.log,0
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
作为AI语言模型,我无法直接为您复现SCI论文,但我可以提供以下有关电力负荷预测的SCI论文及其实现的参考: 1. Li, X., Yang, L., & Zhang, Q. (2017). Short-term load forecasting using extreme learning machine and a hybrid approach. Electric Power Systems Research, 142, 11-20. 该论文采用极限学习机和混合方法进行短期负载预测。极限学习机是一种基于单个隐含层前向反馈神经网络的快速学习算法。混合方法结合了时序分解和回归方法,通过分析负载数据的季节性和趋势性变化来预测负载。 2. Wang, J., Wang, Q., Lu, X., Huang, Z., & Wu, Y. (2016). A new short-term load forecasting method based on extreme learning machine and multi-objective optimization algorithm. Energy, 114, 1141-1149. 该论文提出了一种基于极限学习机和多目标优化算法的新型短期负载预测方法。该方法使用多目标优化算法对模型进行调优,并采用交叉验证和残差分析来验证模型的预测性能。 3. Chen, J., Hong, T., & Pinson, P. (2018). Probabilistic load forecasting using deep learning feed-forward neural networks. IEEE Transactions on Smart Grid, 9(2), 770-779. 该论文采用深度学习前馈神经网络技术进行随机负载预测。该方法将负载数据看作是随机变量,通过训练神经网络来学习每个随机变量的概率分布,从而实现概率负载预测。 4. Akter, M., & Mahmud, M. A. (2019). Electrical load forecasting using artificial neural network and particle swarm optimization: A comparative study. Alexandria Engineering Journal, 58(3), 997-1006. 该论文对比了采用人工神经网络和粒子群优化的电力负载预测方法。研究表明,采用粒子群优化的方法可以提高预测精度,并降低误差率。 以上是一些常见的电力负荷预测SCI论文及其方法介绍,您可以结合自己的研究方向和需求进行选择和参考。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值