forked from sdv-dev/SDGym
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsdv.py
139 lines (87 loc) · 3.45 KB
/
sdv.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import logging
import sdv
import sdv.timeseries
from sdgym.synthesizers.base import Baseline, SingleTableBaseline
from sdgym.synthesizers.utils import select_device
LOGGER = logging.getLogger(__name__)
class SDV(Baseline):
MODALITIES = ('single-table', 'multi-table')
def fit_sample(self, data, metadata):
LOGGER.info('Fitting SDV')
model = sdv.SDV()
model.fit(metadata, data)
LOGGER.info('Sampling SDV')
return model.sample_all()
class SDVTabular(SingleTableBaseline):
MODALITIES = ('single-table', )
_MODEL = None
_MODEL_KWARGS = None
def _fit_sample(self, data, metadata):
LOGGER.info('Fitting %s', self.__class__.__name__)
model_kwargs = self._MODEL_KWARGS.copy() if self._MODEL_KWARGS else {}
model = self._MODEL(table_metadata=metadata, **model_kwargs)
model.fit(data)
LOGGER.info('Sampling %s', self.__class__.__name__)
return model.sample()
class GaussianCopulaCategorical(SDVTabular):
_MODEL = sdv.tabular.GaussianCopula
_MODEL_KWARGS = {
'categorical_transformer': 'categorical'
}
class GaussianCopulaCategoricalFuzzy(SDVTabular):
_MODEL = sdv.tabular.GaussianCopula
_MODEL_KWARGS = {
'categorical_transformer': 'categorical_fuzzy'
}
class GaussianCopulaOneHot(SDVTabular):
_MODEL = sdv.tabular.GaussianCopula
_MODEL_KWARGS = {
'categorical_transformer': 'one_hot_encoding'
}
class CUDATabular(SDVTabular):
def _fit_sample(self, data, metadata):
LOGGER.info('Fitting %s', self.__class__.__name__)
model_kwargs = self._MODEL_KWARGS.copy() if self._MODEL_KWARGS else {}
model_kwargs.setdefault('cuda', select_device())
model = self._MODEL(table_metadata=metadata, **model_kwargs)
model.fit(data)
LOGGER.info('Sampling %s', self.__class__.__name__)
return model.sample()
class CTGAN(CUDATabular):
_MODEL = sdv.tabular.CTGAN
class TVAE(CUDATabular):
_MODEL = sdv.tabular.TVAE
class CopulaGAN(CUDATabular):
_MODEL = sdv.tabular.CopulaGAN
class SDVRelational(Baseline):
MODALITIES = ('single-table', 'multi-table')
_MODEL = None
_MODEL_KWARGS = None
def fit_sample(self, data, metadata):
LOGGER.info('Fitting %s', self.__class__.__name__)
model_kwargs = self._MODEL_KWARGS.copy() if self._MODEL_KWARGS else {}
model = self._MODEL(metadata=metadata, **model_kwargs)
model.fit(data)
LOGGER.info('Sampling %s', self.__class__.__name__)
return model.sample()
class HMA1(SDVRelational):
_MODEL = sdv.relational.HMA1
class SDVTimeseries(SingleTableBaseline):
MODALITIES = ('timeseries', )
_MODEL = None
_MODEL_KWARGS = None
def _fit_sample(self, data, metadata):
LOGGER.info('Fitting %s', self.__class__.__name__)
model_kwargs = self._MODEL_KWARGS.copy() if self._MODEL_KWARGS else {}
model = self._MODEL(table_metadata=metadata, **model_kwargs)
model.fit(data)
LOGGER.info('Sampling %s', self.__class__.__name__)
return model.sample()
class PAR(SDVTimeseries):
def _fit_sample(self, data, metadata):
LOGGER.info('Fitting %s', self.__class__.__name__)
model = sdv.timeseries.PAR(table_metadata=metadata, epochs=1024, verbose=False)
model.device = select_device()
model.fit(data)
LOGGER.info('Sampling %s', self.__class__.__name__)
return model.sample()