Skip to main content

No project description provided

Project description

DP-CGANS (Differentially Private - Conditional Generative Adversarial NetworkS)

PyPi Shield Py versions Test package Publish package

Abstract: This repository presents a Conditional Generative Adversary Networks (GANs) on tabular data (and RDF data) combining with Differential Privacy techniques.

Author: Chang Sun, Institute of Data Science, Maastricht University Start date: Nov-2021 Status: Under development

Note: "Standing on the shoulders of giants". This repository is inspired by the excellent work of CTGAN from Synthetic Data Vault (SDV), Tensorflow Privacy, and RdfPdans. Highly appreciate they shared the ideas and implementations, made code publicly available, well-written documentation. More related work can be found in the References below.

Prerequisites

You will need Python 3.7+ and

Installation

The library is still under development, so it is still in the pypi testing environment.

pip install dp-cgans

Use as a command-line interface

You can easily generated synthetic data using your terminal.

dp-cgans gen dataset/example_tabular_data_UCIAdult.csv --epochs 2 --output out.csv --gen_size 100

Get a full rundown of the available options with

dp-cgans --help

Use with python

  1. if your input is tabular data (e.g., csv):
from dp_cgans import DP_CGAN
import pandas as pd

tabular_data=pd.read_csv("../dataset/example_tabular_data_UCIAdult.csv")

# We adjusted the original CTGAN model from SDV. Instead of looking at the distribution of individual variable, we extended to two variables and keep their corrll
model = DP_CGAN(
   epochs=100, # number of training epochs
   batch_size=1000, # the size of each batch
   log_frequency=True,
   verbose=True,
   generator_dim=(128, 128, 128),
   discriminator_dim=(128, 128, 128),
   generator_lr=2e-4, 
   discriminator_lr=2e-4,
   discriminator_steps=1, 
   private=False,
)

print("Start training model")
model.fit(tabular_data)

# Sample the generated synthetic data
model.sample(100)
  1. If your input data is in RDF format:
from dp_cgans import DP_CGAN
from dp_cgans import RDF_to_Tabular

# Step 1. Load RDF to a plain table (dataframe)
plain_tabular=RDF_to_Tabular(file_path="../dataset/example_rdf_data.ttl")

# Step 2. Convert plain table to a structured table 
# After step 1, RDF data will be converted a plain tabular dataset (all the nodes/entities will be presented as rows. Step 2 will structure the table by recognizing and sorting the types of the entities, replacing the URI with actual value which is attached to that URI. Users can decide how many levels they want to unfold their RDF models to tabular datasets.)
tabular_data,rel_pred_obj=plain_tabular.fit_convert(user_define_data_instance="http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#C16960", 
                                                  user_define_is_a=["rdf:type{URIRef}"], 
                                                  user_define_has_value=["http://www.cancerdata.org/roo/P100042"], 
                                                  set_level="full", 
                                                  as_column='object', 
                                                  remove_columns_unique_values=True)

# Step 3. Define your GANS model
model = DP_CGAN(
  epochs=100, # number of training epochs
  batch_size=1000, # the size of each batch
  log_frequency=True,
  verbose=True,
  generator_dim=(128, 128, 128),
  discriminator_dim=(128, 128, 128),
  generator_lr=2e-4, 
  discriminator_lr=2e-4,
  discriminator_steps=1, 
  private=False,
)

print("Start training model")
model.fit(tabular_data)

# Sample the generated synthetic data
model.sample(100)

Development installation

You will need to install Poetry. Be careful as the devs of poetry are not competent enough to properly set the right python version, poetry will use 3.10 by default, but you need to use 3.9

poetry env use $(which python)

Clone the repository:

git clone https://github.com/sunchang0124/dp_cgans

Install the dependencies:

poetry install

Run tests:

poetry run pytest -s

Add a dependency (e.g. pandas here):

poetry add pandas

Compile:

poetry build

Publish:

poetry publish

References / Further reading

There are many excellent work on generating synthetic data using GANS and other methods. We list the studies that made great conbributions for the field and inspiring for our work.

GANS
  1. Synthetic Data Vault (SDV) [Paper] [Github]
  2. Modeling Tabular Data using Conditional GAN (a part of SDV) [Paper] [Github]
  3. Wasserstein GAN [Paper]
  4. Improved Training of Wasserstein GANs [Paper]
  5. Synthesising Tabular Data using Wasserstein Conditional GANs with Gradient Penalty (WCGAN-GP) [Paper]
  6. PacGAN: The power of two samples in generative adversarial networks [Paper]
  7. CTAB-GAN: Effective Table Data Synthesizing [Paper]
  8. Conditional Tabular GAN-Based Two-Stage Data Generation Scheme for Short-Term Load Forecasting [Paper]
  9. TabFairGAN: Fair Tabular Data Generation with Generative Adversarial Networks [Paper]
  10. Conditional Wasserstein GAN-based Oversampling of Tabular Data for Imbalanced Learning [Paper]
Differential Privacy
  1. Tensorflow Privacy [Github]
  2. Renyi Differential Privacy [Paper]
  3. DP-CGAN : Differentially Private Synthetic Data and Label Generation [Paper]
  4. Differentially Private Generative Adversarial Network [Paper] [Github] Another implementation [Github]
  5. Private Data Generation Toolbox [Github]
  6. autodp: Automating differential privacy computation [Github]
  7. Differentially Private Synthetic Medical Data Generation using Convolutional GANs [Paper]
  8. DTGAN: Differential Private Training for Tabular GANs [Paper]
  9. DIFFERENTIALLY PRIVATE SYNTHETIC DATA: APPLIED EVALUATIONS AND ENHANCEMENTS [Paper]
  10. FFPDG: FAST, FAIR AND PRIVATE DATA GENERATION [Paper]
Others
  1. EvoGen: a Generator for Synthetic Versioned RDF [Paper]
  2. Generation and evaluation of synthetic patient data [Paper]
  3. Fake It Till You Make It: Guidelines for Effective Synthetic Data Generation [Paper]
  4. Generating and evaluating cross-sectional synthetic electronic healthcare data: Preserving data utility and patient privacy [Paper]
  5. Synthetic data for open and reproducible methodological research in social sciences and official statistics [Paper]
  6. A Study of the Impact of Synthetic Data Generation Techniques on Data Utility using the 1991 UK Samples of Anonymised Records [Paper]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dp-cgans-0.0.3.tar.gz (65.5 kB view hashes)

Uploaded Source

Built Distribution

dp_cgans-0.0.3-py3-none-any.whl (69.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page