-
Notifications
You must be signed in to change notification settings - Fork 0
/
dcr.py
123 lines (98 loc) · 2.95 KB
/
dcr.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
from gentab.evaluators import KNN, LightGBM, XGBoost, MLP
from gentab.generators import (
SMOTE,
ADASYN,
TVAE,
CTGAN,
GaussianCopula,
CopulaGAN,
CTABGAN,
CTABGANPlus,
AutoDiffusion,
ForestDiffusion,
Tabula,
GReaT,
)
from gentab.data import Config, Dataset
from gentab.utils import console
import pandas as pd
import numpy as np
def preproc_playnet(dataset):
dataset.reduce_size(
{
"left_attack": 0.97,
"right_attack": 0.97,
"right_transition": 0.9,
"left_transition": 0.9,
"time_out": 0.8,
"left_penal": 0.5,
"right_penal": 0.5,
}
)
dataset.merge_classes(
{
"attack": ["left_attack", "right_attack"],
"transition": ["left_transition", "right_transition"],
"penalty": ["left_penal", "right_penal"],
}
)
dataset.reduce_mem()
return dataset
def preproc_adult(dataset):
dataset.merge_classes({"<=50K": ["<=50K."], ">50K": [">50K."]})
dataset.reduce_mem()
return dataset
def preproc_car(dataset):
return dataset
configs = [
("configs/car_evaluation_cr.json", preproc_car, "Car Evaluation"),
("configs/playnet_cr.json", preproc_playnet, "PlayNet"),
("configs/adult_cr.json", preproc_adult, "Adult"),
]
gens = [
(TVAE, "TVAE \cite{xu2019modeling}"),
(CTGAN, "CTGAN \cite{xu2019modeling}"),
(GaussianCopula, "GaussianCopula \cite{patki2016synthetic}"),
(CopulaGAN, "CopulaGAN \cite{xu2019modeling}"),
(CTABGAN, "CTAB-GAN \cite{zhao2021ctab}"),
(CTABGANPlus, "CTAB-GAN+ \cite{zhao2022ctab}"),
(AutoDiffusion, "AutoDiffusion \cite{suh2023autodiff}"),
(ForestDiffusion, "ForestDiffusion \cite{jolicoeur2023generating}"),
(GReaT, "GReaT \cite{borisov2022language}"),
(Tabula, "Tabula \cite{zhao2023tabula}"),
]
DCR = pd.DataFrame()
for c in configs:
config = Config(c[0])
dataset = c[1](Dataset(config))
console.print(dataset.class_counts(), dataset.row_count())
for g in gens:
generator = g[0](dataset)
try:
generator.load_from_disk()
min_l2_dist = dataset.distance_closest_record()
DCR.loc[c[2], g[1]] = np.mean(min_l2_dist)
except FileNotFoundError:
DCR.loc[c[2], g[1]] = 0.0
round = 2
console.print(DCR)
DCR_mean = DCR.mean()
console.print(DCR_mean)
DCR_ranks = DCR.rank(ascending=True, axis=1)
console.print(DCR_ranks)
DCR_mean_rank = DCR_ranks.mean().round(round)
max = DCR_mean_rank.max()
console.print(DCR_mean_rank)
lines = []
for index, row in DCR_mean_rank.items():
if max == row:
line = (
index + " & " + "\\textbf{{{:.{prec}f}}}".format(row, prec=round) + " \\\\"
)
elif row != float("inf"):
line = index + " & " + "{:.{prec}f}".format(row, prec=round) + " \\\\"
else:
line = index + " & - \\\\"
lines.append(line)
for line in lines:
console.print(line)