Skip to content

Commit

Permalink
feat: Make GaussianCopula extend with SynthesizerModel. (#241)
Browse files Browse the repository at this point in the history
  • Loading branch information
jalr4ever authored Nov 19, 2024
1 parent ef33803 commit edfab2e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
14 changes: 9 additions & 5 deletions sdgx/models/statistics/single_table/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,28 @@
# Which is Lincensed by MIT License

import os
from copy import deepcopy
from typing import List, Optional

import numpy as np
import torch

from sdgx.data_loader import DataLoader
from sdgx.data_models.metadata import Metadata
from sdgx.models.base import SynthesizerModel

class StatisticSynthesizerModel:

class StatisticSynthesizerModel(SynthesizerModel):
random_states = None

def __init__(self, transformer=None, sampler=None) -> None:
def __init__(self, transformer=None, sampler=None, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
self._generator = None
self.model = None
self.status = "UNFINED"
self.model_type = "MODEL_TYPE_UNDEFINED"
# self.epochs = epochs
self._device = "CPU"

def fit(self, input_df, discrete_cols: Optional[List] = None):
def fit(self, metadata: Metadata, dataloader: DataLoader, *args, **kwargs):
raise NotImplementedError

def set_device(self, device):
Expand Down
7 changes: 2 additions & 5 deletions sdgx/models/statistics/single_table/copula.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@
import sdgx.models.components.sdv_copulas as copulas
from sdgx.data_loader import DataLoader
from sdgx.data_models.metadata import Metadata
from sdgx.exceptions import NonParametricError, SynthesizerInitError
from sdgx.exceptions import NonParametricError
from sdgx.models.components.optimize.sdv_copulas.data_transformer import (
StatisticDataTransformer,
)
from sdgx.models.components.sdv_copulas import multivariate
from sdgx.models.components.sdv_ctgan.data_transformer import DataTransformer
from sdgx.models.components.sdv_rdt.transformers import OneHotEncoder
from sdgx.models.components.utils import (
flatten_dict,
log_numerical_distributions_error,
unflatten_dict,
validate_numerical_distributions,
)
Expand All @@ -27,7 +24,7 @@
LOGGER = logging.getLogger(__name__)


class GaussianCopulaSynthesizer(StatisticSynthesizerModel):
class GaussianCopulaSynthesizerModel(StatisticSynthesizerModel):
"""Model wrapping ``copulas.multivariate.GaussianMultivariate`` copula.
Args:
Expand Down
7 changes: 2 additions & 5 deletions tests/models/test_copula.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
from pathlib import Path

import pandas as pd
import pytest

from sdgx.models.statistics.single_table.copula import GaussianCopulaSynthesizer
from sdgx.utils import get_demo_single_table
from sdgx.models.statistics.single_table.copula import GaussianCopulaSynthesizerModel


@pytest.fixture
Expand All @@ -13,7 +10,7 @@ def dummy_data(dummy_single_table_path):


def test_gaussian_copula(dummy_single_table_metadata, dummy_single_table_data_loader):
model = GaussianCopulaSynthesizer()
model = GaussianCopulaSynthesizerModel()
model.fit(dummy_single_table_metadata, dummy_single_table_data_loader)

sampled_data = model.sample(10)
Expand Down

0 comments on commit edfab2e

Please sign in to comment.