Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate GaussianCopula model into the Synthesizer. #241

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading