我们论文 Poisoning Attacks on the PGM-index 的官方代码。
git clone https://github.com/atsukisato/pgm-attack.git
cd pgm-attack
git submodule update --init --recursive
./scripts/build.sh
需要 CMake(参见依赖项)。输出位于 build/ 下(默认二进制文件在 build/bin 中)。
./scripts/download_alex_dataset.sh # ALEX
./scripts/download_mgbench.sh # mgbench
./scripts/download_sosd_datasets.sh # SOSD
./scripts/preprocess_alex_dataset.sh # ALEX
./scripts/preprocess_mgbench.sh # mgbench
./scripts/generate_synthetic_dataset.sh # synthetic
每次运行通过 ./scripts/run_experiment.sh <config.json> 接收一个 JSON 配置。示例:
4.1 最大化最大误差(例如 n=16,连续方法)
./scripts/run_experiment.sh "configs/experiments/poison_attack/maximize_maxerror_consec/baseline_n16.json"
4.2 最小化覆盖的合法键(例如 epsilon=2,连续方法)
./scripts/run_experiment.sh "configs/experiments/poison_attack/minimize_segment_length/baseline_epsilon2.json"
4.3 最大化 m_opt(PGM-index 示例)
./scripts/run_experiment.sh "configs/experiments/poison_attack/inject_poisons_to_minimize_segment_length_swing_lambda_with_theta/baseline.json"
4.4 m_opt 的上界(依赖实例的示例)
./scripts/run_experiment.sh "configs/experiments/upper_bound/fix_w_per_block/baseline.json"
4.5 运行所有实验(批量)
运行 scripts/run_all_experiment.sh 中的完整实验配置列表(编辑该文件以更改集合)。
./scripts/run_all_experiment.sh
在仓库根目录下:
./scripts/plot.sh
./scripts/print_table.sh
图表和日志写入 fig/ 下。请先安装 Python 依赖:pip install -r requirements.txt。
g++、make 和 CMake(构建脚本使用 CMake 进行配置,并通过 cmake --build 构建,后者通常调用 Make)。requirements.txt 中的包(绘图 / 表格脚本)。./scripts/run_experiment.sh 解析实验 JSON 所需。| 路径 | 作用 |
|---|---|
src/ | C++ 源代码(攻击、PGM 基准测试、工具、上界)。 |
configs/experiments/ | 实验 JSON 配置(路径位于 poison_attack/、upper_bound/ 等下)。 |
scripts/ | 构建、数据、run_experiment.sh、run_all_experiment.sh、plot.sh、print_table.sh。 |
third_party/ | Git 子模块(PGM-index、FITing-Tree、RadixSpline)。 |
data/、results/、fig/ | 数据、运行输出以及生成的图表 / 表格日志。 |
plot/ | Python 绘图和表格打印脚本。 |
构建一次镜像:
./docker_build.sh
docker_run.sh — 交互式容器:将仓库挂载到 /workspace,分配 8 个 CPU(0–7),进入 bash,以便手动构建和运行命令。docker_run_all.sh — 分离运行:在容器内(8 个 CPU)执行 ./scripts/run_all_experiment.sh,并将标准输出写入 results/run_all.log。docker_run_all_single_cpu.sh — 与 docker_run_all.sh 相同,但使用一个 CPU 和 OMP_NUM_THREADS=1 进行单线程运行。三者均使用镜像 pgm_poisoning:latest,并采用与脚本中相同的 capability / volume 设置。