CCPP/draw_main.py
2025-04-20 20:55:06 +08:00

224 lines
17 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import numpy as np
from analyzeTool import generate_heat_maps_array, count_classes_samples
from drawing_tool import draw_ori_perturbed, draw_times_diff_bar, draw_ori_perturbed_with_inset, draw_diff_pert_info, \
heat_maps_of_classes
if __name__ == '__main__':
# # ECG 0.04
# original_data = "6.410247599999999712e-01 7.814486200000000382e-01 8.841660900000000156e-01 1.235362999999999989e+00 1.782253300000000040e+00 2.219029200000000035e+00 2.350801099999999977e+00 2.111025199999999824e+00 1.595795800000000098e+00 1.063145000000000007e+00 5.214278199999999863e-01 8.905684099999999770e-02 1.531264400000000026e-01 2.324356599999999884e-01 -1.149376899999999951e-01 -1.651973100000000139e-01 5.011464799999999602e-03 -1.478869999999999907e-01 -6.105320999999999665e-02 3.645349999999999979e-02 -4.441071200000000219e-01 -6.793092099999999967e-01 -5.299733599999999489e-01 -6.467437299999999611e-01 -7.079432799999999526e-01 -6.633238200000000084e-01 -8.606828899999999782e-01 -9.597856700000000352e-01 -9.276052399999999976e-01 -1.140874799999999967e+00 -1.364474799999999988e+00 -1.286232400000000053e+00 -1.193629000000000051e+00 -1.332616500000000093e+00 -1.469505899999999921e+00 -1.489589899999999911e+00 -1.600690200000000063e+00 -1.777332799999999935e+00 -1.810176000000000007e+00 -1.735597099999999893e+00 -1.704956899999999997e+00 -1.724591900000000066e+00 -1.707795699999999917e+00 -1.594449299999999958e+00 -1.396698400000000007e+00 -1.187054700000000018e+00 -9.916590499999999864e-01 -7.708646200000000004e-01 -5.576156799999999469e-01 -3.874625899999999956e-01 -1.684684999999999933e-01 1.158190000000000053e-01 3.144081799999999816e-01 3.764868499999999840e-01 4.204736399999999819e-01 4.975668799999999892e-01 5.742429000000000006e-01 6.478606900000000168e-01 6.616984399999999988e-01 6.051487300000000236e-01 6.295551700000000528e-01 7.117260399999999487e-01 6.740077100000000376e-01 6.155466400000000338e-01 6.777178400000000158e-01 7.207244900000000509e-01 6.626562999999999759e-01 6.158657499999999896e-01 6.617521699999999729e-01 7.109475100000000047e-01 6.147269899999999732e-01 5.231166299999999714e-01 5.887229699999999566e-01 5.911069100000000409e-01 5.855090899999999543e-01 6.948123600000000177e-01 5.469097400000000331e-01 3.645842599999999933e-01 6.602078500000000405e-01 8.684830799999999629e-01 6.410247599999999712e-01 5.403232999999999508e-01 6.355810499999999807e-01 7.083335299999999890e-01 7.426267199999999624e-01 6.175198499999999813e-01 5.871576699999999649e-01 8.247907500000000169e-01 9.697120799999999763e-01 9.259981499999999643e-01 5.296564000000000272e-01 -1.374844299999999908e-01 -4.576849700000000243e-01 -1.061242400000000030e+00 -2.023360600000000176e+00 -1.376014099999999907e+00"
# perturbed_data = "0.6444 0.7856 0.8888 1.2418 1.7713 2.0436 2.2346 2.1930 1.6804 1.0748 0.3897 -0.0399 0.0686 0.4267 -0.1309 -0.2164 0.0050 -0.1487 -0.0614 0.0366 -0.4464 -0.6829 -0.5328 -0.6501 -0.7117 -0.6668 -0.9808 -1.0112 -1.0913 -1.0141 -1.4900 -1.4651 -1.1812 -1.2940 -1.5742 -1.3882 -1.6847 -1.7861 -1.9346 -1.7152 -1.8077 -1.6203 -1.6006 -1.6807 -1.3937 -1.3646 -1.1665 -0.6113 -0.5605 -0.3895 -0.1694 0.1164 0.3161 0.3785 0.4227 0.5002 0.5773 0.6513 0.6652 0.6083 0.6329 0.7155 0.6775 0.6188 0.6813 0.7245 0.6661 0.6191 0.6652 0.7147 0.6180 0.5259 0.5918 0.5942 0.5886 0.6985 0.5498 0.3665 0.6637 0.8730 0.7138 0.4777 0.6356 0.8395 0.9112 0.5005 0.7421 0.9235 0.9903 1.1184 0.6624 -0.0234 -0.5430 -0.8738 -2.0340 -1.3832"
# scale = (25, 50)
# xy = (45, 0.85)
# xytext = (40, -0.4)
# loc_sample = 'upper right'
# loc_sub = 'upper center'
# draw_ori_perturbed(original_data, perturbed_data,
# filename='论文插图2/figure3_ECG004对比图.pdf',
# loc_sample=loc_sample,
# loc_sub=loc_sub,
# inset_range=scale,
# dashed_lists=[scale],
# xy=xy,
# xytext=xytext)
#
# # ECG 0.02
# perturbed_data = "0.6444 0.7856 0.8888 1.2418 1.8865 2.1496 2.3434 2.1861 1.5822 1.0904 0.5405 0.0347 0.1713 0.3206 -0.1030 -0.1754 0.0050 -0.1487 -0.0614 0.0366 -0.4464 -0.6829 -0.5328 -0.6501 -0.7117 -0.6668 -0.9112 -0.9741 -1.0095 -1.1322 -1.3230 -1.3910 -1.2761 -1.3497 -1.5226 -1.4313 -1.6892 -1.8592 -1.7471 -1.7912 -1.6806 -1.6637 -1.7026 -1.6638 -1.4444 -1.1879 -1.0551 -0.8528 -0.5605 -0.3895 -0.1694 0.1164 0.3161 0.3785 0.4227 0.5002 0.5773 0.6513 0.6652 0.6083 0.6329 0.7155 0.6775 0.6188 0.6813 0.7245 0.6661 0.6191 0.6652 0.7147 0.6180 0.5259 0.5918 0.5942 0.5886 0.6985 0.5498 0.3665 0.6637 0.8730 0.6238 0.5742 0.6817 0.7971 0.7187 0.7069 0.6060 0.8689 1.0034 1.0273 0.5092 -0.2091 -0.3818 -0.9827 -2.0340 -1.3832"
# draw_ori_perturbed(original_data, perturbed_data,
# filename='论文插图2/figure3_ECG002对比图.pdf',
# loc_sample=loc_sample,
# loc_sub=loc_sub,
# inset_range=scale,
# dashed_lists=[scale],
# xy=xy,
# xytext=xytext)
#
# # ECG 0.01
# perturbed_data = "0.6444 0.7856 0.8888 1.2762 1.7566 2.2411 2.3631 2.1221 1.6042 1.0687 0.4979 0.0412 0.1737 0.2803 -0.1073 -0.1920 0.0453 -0.1498 -0.0614 0.0366 -0.4464 -0.6829 -0.5328 -0.6501 -0.7117 -0.6668 -0.8652 -1.0050 -0.9247 -1.1196 -1.3812 -1.3010 -1.1999 -1.3396 -1.4772 -1.4974 -1.6091 -1.7867 -1.8197 -1.7447 -1.7139 -1.6926 -1.6829 -1.6361 -1.3716 -1.1626 -1.0194 -0.7482 -0.5426 -0.4157 -0.1808 0.1277 0.3185 0.4245 0.4058 0.5200 0.5515 0.6634 0.6617 0.5656 0.6466 0.7155 0.6775 0.6188 0.6813 0.7245 0.6661 0.6191 0.6652 0.7147 0.6180 0.5259 0.5918 0.5942 0.5794 0.6845 0.5835 0.3818 0.6755 0.8561 0.6444 0.5432 0.6389 0.7121 0.7465 0.6208 0.5902 0.8291 0.9838 0.9516 0.5245 -0.1788 -0.4601 -1.0668 -2.0340 -1.3832"
# draw_ori_perturbed(original_data, perturbed_data,
# filename='论文插图2/figure3_ECG001对比图.pdf',
# loc_sample=loc_sample,
# loc_sub=loc_sub,
# inset_range=scale,
# dashed_lists=[scale],
# xy=xy,
# xytext=xytext)
# # Sony 0.04
# original_data = "0.0599 0.0599 0.0599 0.0599 -0.7742 -1.3302 -0.4962 0.3379 1.4499 1.1719 0.3379 0.8939 1.7280 1.7280 0.6159 -1.0521 -1.0521 -0.2181 -0.4962 -0.7742 -1.0521 -1.0521 -1.0521 -0.4962 0.0599 0.0599 0.3379 -0.2181 0.3379 0.0599 0.3379 0.3379 -0.7742 -0.4962 -0.4962 -0.4962 -0.2181 -0.2181 -0.2181 0.0599 -0.2181 -0.2181 0.0599 -1.6082 -1.0521 0.6159 0.3379 -0.7742 1.1719 2.8400 3.3960 2.2840 0.8939 -2.1642 -2.1642 -0.4962 0.0599 -0.2181 -0.4962 -0.4962 0.6159 0.6159 0.0599 -0.2181 0.0599"
# perturbed_data = "0.0599 0.0599 0.0599 0.0310 -0.6830 -1.1319 -0.3566 0.3379 1.4499 1.2683 0.4334 0.9029 1.8575 1.9152 0.6944 -1.0521 -1.0521 -0.2181 -0.4962 -0.7742 -1.0521 -1.0521 -1.0521 -0.4962 0.0599 0.0599 0.3379 -0.2181 0.3379 0.0599 0.3379 0.3379 -0.7742 -0.4962 -0.4962 -0.4962 -0.2181 -0.2181 -0.2181 0.0599 -0.2181 -0.2181 0.0599 -1.6082 -1.0521 0.5199 0.1594 -0.7803 1.1256 2.9534 3.5492 2.3713 0.7483 -2.0346 -2.1955 -0.3492 0.0359 -0.1742 -0.3939 -0.6957 0.4353 0.4462 0.0599 -0.2181 0.0599"
# scale = (7, 15)
# xy = (33, 1.4)
# xytext = (15, 0.8)
# loc_sample = 'upper right'
# loc_sub = 'upper center'
# draw_ori_perturbed(original_data, perturbed_data,
# filename='论文插图2/figure3_Sony004对比图.pdf',
# loc_sample=loc_sample,
# loc_sub=loc_sub,
# inset_range=scale,
# dashed_lists=[scale],
# xy=xy,
# xytext=xytext)
#
# # Sony 0.02
# perturbed_data = "0.0599 0.0599 0.0599 0.0374 -0.7051 -1.3549 -0.4990 0.3379 1.4499 1.0861 0.3807 0.9880 1.7390 1.7361 0.6788 -1.0521 -1.0521 -0.2181 -0.4962 -0.7742 -1.0521 -1.0521 -1.0521 -0.4962 0.0599 0.0599 0.3379 -0.2181 0.3379 0.0599 0.3379 0.3379 -0.7742 -0.4962 -0.4962 -0.4962 -0.2181 -0.2181 -0.2181 0.0599 -0.2181 -0.2181 0.0599 -1.6082 -1.0521 0.6970 0.2896 -0.7888 1.1938 2.7924 3.4649 2.3376 0.8073 -2.0784 -2.1942 -0.5223 0.0861 -0.2344 -0.5798 -0.5959 0.5172 0.5588 0.0599 -0.2181 0.0599"
# draw_ori_perturbed(original_data, perturbed_data,
# filename='论文插图2/figure3_Sony002对比图.pdf',
# loc_sample=loc_sample,
# loc_sub=loc_sub,
# inset_range=scale,
# dashed_lists=[scale],
# xy=xy,
# xytext=xytext)
#
# # Sony 0.01
# perturbed_data = "0.0599 0.0599 0.0599 0.0169 -0.7642 -1.3113 -0.4875 0.3379 1.4499 1.1723 0.3651 0.9393 1.6804 1.7290 0.6672 -1.0521 -1.0521 -0.2181 -0.4962 -0.7742 -1.0521 -1.0521 -1.0521 -0.4962 0.0599 0.0599 0.3379 -0.2181 0.3379 0.0599 0.3379 0.3379 -0.7742 -0.4962 -0.4962 -0.4962 -0.2181 -0.2181 -0.2181 0.0599 -0.2181 -0.2181 0.0599 -1.6082 -1.0521 0.6248 0.3447 -0.7442 1.1737 2.7967 3.4208 2.2884 0.8680 -2.1330 -2.1518 -0.5447 0.0130 -0.2304 -0.5026 -0.4783 0.5671 0.6399 0.0599 -0.2181 0.0599"
# draw_ori_perturbed(original_data, perturbed_data,
# filename='论文插图2/figure3_Sony001对比图.pdf',
# loc_sample=loc_sample,
# loc_sub=loc_sub,
# inset_range=scale,
# dashed_lists=[scale],
# xy=xy,
# xytext=xytext)
#
# 随机区间成功
# scale = [(13, 29), (33, 47), (56, 72)]
# # xy = (95, -5)
# # xytext = (40, -0.4)
# loc_sample = 'lower right'
# loc_sub = 'lower right'
# original_data = "0.7105 0.6894 0.6551 1.2894 1.9932 1.9182 1.5860 1.6460 1.5084 0.7529 0.0330 -0.1929 -0.1509 -0.1136 -0.2392 -0.5039 -0.6020 -0.4257 -0.3627 -0.6225 -0.8194 -0.7298 -0.6382 -0.7202 -0.9134 -1.0540 -1.0283 -1.0828 -1.2669 -1.2678 -1.2946 -1.4921 -1.3886 -1.2382 -1.5695 -1.8409 -1.7606 -1.7878 -1.8247 -1.7041 -1.7095 -1.7474 -1.6194 -1.4682 -1.3479 -1.2382 -1.0846 -0.8102 -0.6451 -0.6373 -0.3964 -0.0379 0.0010 -0.0685 0.0609 0.2248 0.3061 0.3292 0.3028 0.3230 0.3998 0.4567 0.5148 0.5269 0.4515 0.4403 0.5410 0.5968 0.5534 0.4987 0.4910 0.5554 0.6822 0.7272 0.6650 0.7387 0.8708 0.7335 0.5975 0.8433 1.0931 1.0070 0.9677 1.0794 0.8658 0.6264 0.9619 1.1341 0.7718 0.9090 1.3177 1.1296 1.0961 1.3177 0.8113 0.1427"
# perturbed_data = '0.7105 0.6894 0.6551 1.2894 1.9932 1.9182 1.5860 1.6460 1.5084 0.7529 0.0330 -0.1929 -0.1509 0.0662 -0.1203 -0.3538 -0.5494 -0.5772 -0.5440 -0.5975 -0.8799 -0.6269 -0.8194 -0.5960 -0.9585 -1.2015 -0.8784 -1.0897 -1.4161 -1.2678 -1.2946 -1.4921 -1.3886 -1.0961 -1.4944 -1.9683 -1.6469 -1.6565 -1.9820 -1.6598 -1.5989 -1.7915 -1.8038 -1.3032 -1.2258 -1.3837 -1.0666 -0.8102 -0.6451 -0.6373 -0.3964 -0.0379 0.0010 -0.0685 0.0609 0.2248 0.3491 0.5100 0.4655 0.5169 0.3829 0.4692 0.5358 0.4554 0.5778 0.5362 0.4921 0.5452 0.6070 0.5404 0.4519 0.6364 0.6822 0.7272 0.6650 0.7387 0.8708 0.7335 0.5975 0.8433 1.0931 1.0070 0.9677 1.0794 0.8658 0.6264 0.9619 1.1341 0.7718 0.9090 1.3177 1.1296 1.0961 1.3177 0.8113 0.1427'
# draw_ori_perturbed(original_data, perturbed_data,
# filename='论文插图2/figure3_ECGFiveDays随机区间成功.pdf',
# loc_sample=loc_sample,
# loc_sub=loc_sub,
# dashed_lists=scale)
#
# # 原区间成功
# scale = [(3, 14), (27, 52), (74,84)]
# perturbed_data = '0.7105 0.6894 0.6551 1.2224 1.8428 2.0472 1.7260 1.6045 1.3185 0.5770 0.1076 -0.2949 -0.1636 0.0517 -0.2392 -0.5039 -0.6020 -0.4257 -0.3627 -0.6225 -0.8194 -0.7298 -0.6382 -0.7202 -0.9134 -1.0540 -1.0283 -0.9722 -1.4386 -1.2600 -1.1366 -1.6790 -1.5343 -1.2766 -1.6165 -1.9023 -1.5843 -1.6212 -1.9980 -1.7463 -1.5317 -1.8412 -1.7552 -1.5399 -1.3920 -1.4149 -1.2649 -0.6781 -0.4535 -0.7282 -0.3204 -0.0391 0.0010 -0.0685 0.0609 0.2248 0.3061 0.3292 0.3028 0.3230 0.3998 0.4567 0.5148 0.5269 0.4515 0.4403 0.5410 0.5968 0.5534 0.4987 0.4910 0.5554 0.6822 0.7272 0.6277 0.6284 0.7937 0.6874 0.7385 0.7790 1.0495 1.1863 0.9164 1.0463 0.8658 0.6264 0.9619 1.1341 0.7718 0.9090 1.3177 1.1296 1.0961 1.3177 0.8113 0.1427'
# draw_ori_perturbed(original_data, perturbed_data,
# filename='论文插图2/figure3_ECGFiveDays原区间成功.pdf',
# loc_sample=loc_sample,
# loc_sub=loc_sub,
# dashed_lists=scale)
#
# # 随机区间失败12
# scale = [(100,130)]
# perturbed_data = original_data
# draw_ori_perturbed(original_data, perturbed_data,
# filename='论文插图2/figure3_ECGFiveDays随机区间失败1.pdf',
# loc_sample=loc_sample,
# loc_sub=loc_sub,
# dashed_lists=scale)
# scale = [(80, 110)]
# draw_ori_perturbed(original_data, perturbed_data,
# filename='论文插图2/figure3_ECGFiveDays随机区间失败2.pdf',
# loc_sample=loc_sample,
# loc_sub=loc_sub,
# dashed_lists=scale)
# # 扰动因子和成功率
# data1 = [52, 81, 81, 81, 81, 81] # Car*
# data2 = [1, 8, 8, 19, 18, 29] # ItalyPowerDemand*
# data3 = [3, 12, 17, 42, 59, 77] # SonyAIBORobotSurface2
# data4 = [0, 4, 65, 78, 78, 78] # Plane
# data5 = [17, 22, 82, 87, 88, 88] # ECG200*
# data6 = [23, 43, 81.5, 100, 100, 100] # Ligning7*
# labels = ['0.01', '0.02', '0.04', '0.06', '0.08', '0.1'] # x轴扰乱因子标记
#
# draw_diff_pert_info(data1, data2, data5, data6, labels, marker='o', linewidth=3,
# filename='./论文插图2/SR3.pdf')
#
# 种群倍数
# car_data_ani = [1, 1, 1, 1, 1]
# ecg200_data_ani = [13.8, 9.4, 11.8, 13.5, 13]
# italy_data_ani = [6.7, 4.8, 3.9, 5.2, 4.5]
# ligning_ani = [8.78, 8.3, 8.2, 8.16, 8.2]
# # car_data_mse = [0.0031, 0.003, 0.00315, 0.0032, 0.00325]
# # ecg200_data_mse = [0.0066, 0.00655, 0.00652, 0.0068, 0.0067]
# # italy_data_mse = [0.0024, 0.00245, 0.0024, 0.0026, 0.0027]
# # ligning_mse = [0.0144, 0.0144, 0.0147, 0.0146, 0.0145]
#
# car_data_q = [544.00, 544.00, 544.00, 544.00, 544.00]
# ecg200_data_q = [423, 469.5, 544, 693, 592]
# italy_data_q = [39, 42.75, 49.05, 42.75, 48]
# ligning_q = [380, 400, 400, 400, 400]
# draw_times_diff_bar(car_data_ani, ecg200_data_ani, italy_data_ani, ligning_ani,
# car_data_q, ecg200_data_q, italy_data_q, ligning_q,
# 'Car', 'ECG200', 'Italy', 'Ligning7',
# filename='./论文插图2/GT-ANI-bar.pdf',
# rightLabel='Queries', leftLabel='ANI', times=1)
# 扰动因子2
car_data_sr = [8.63,
2,
2,
2,
2]
ecg200_data_sr = [7.25,
16.591176470588238,
12.325,
5.8884375,
3.8646153846153846]
italy_data_sr = [6.75,
4.715714285714285,
9.205416666666666,
10.055915492957746,
9.667916666666667]
ligning_sr = [15.417499999999999,
15.142857142857142,
7.199666666666667,
3.9983333333333335,
2.5326666666666666]
car_data_mse = [431.5810526,
100,
100,
100,
100]
ecg200_data_mse = [362.5,
829.4088235294118,
616.1317741935484,
294.53125,
193.07507692307695]
italy_data_mse = [337.5,
235.71285714285713,
460.41625000000005,
502.8149295774648,
483.33214285714286]
ligning_mse = [770.8325000000001,
757.1428571428571,
359.99899999999997,
200.001,
126.66633333333333]
draw_times_diff_bar(car_data_mse, ecg200_data_mse, italy_data_mse, ligning_mse,
car_data_sr, ecg200_data_sr, italy_data_sr, ligning_sr,
'Car', 'ECG200', 'Italy', 'Ligning7',
filename='扰动因子.pdf', rightLabel='ANI', xlabel='$\\beta$',
x_value=['0.01', '0.02', '0.04', '0.06', '0.08'], leftLabel='Queries',times=1)
# 热力图
# data1 = generate_heat_maps_array(count_classes_samples('/Users/catb/Library/CloudStorage/CloudMounter-B40-4/home/BJTU/project/CPadv/CCPP实验结果/热力图/Lightning7', select_colum='Success'),
# classes_size=7)
# data2 = generate_heat_maps_array(count_classes_samples('/Users/catb/Library/CloudStorage/CloudMounter-B40-4/home/BJTU/project/CPadv/CCPP实验结果/热力图/Plane', select_colum='Success'),
# classes_size=7)
# heat_maps_of_classes(data1, data2,
# '',
# cbar_ticks1=[0, 1, 2, 3, 4], cbar_ticks2=[0, 1, 2, 3, 4], filename='热力图.pdf')