Codebase for Time-series Generative Adversarial Networks (TimeGAN)

Overview

Codebase for "Time-series Generative Adversarial Networks (TimeGAN)"

Authors: Jinsung Yoon, Daniel Jarrett, Mihaela van der Schaar

Reference: Jinsung Yoon, Daniel Jarrett, Mihaela van der Schaar, "Time-series Generative Adversarial Networks," Neural Information Processing Systems (NeurIPS), 2019.

Paper Link: https://papers.nips.cc/paper/8789-time-series-generative-adversarial-networks

Contact: [email protected]

This directory contains implementations of TimeGAN framework for synthetic time-series data generation using one synthetic dataset and two real-world datasets.

To run the pipeline for training and evaluation on TimeGAN framwork, simply run python3 -m main_timegan.py or see jupyter-notebook tutorial of TimeGAN in tutorial_timegan.ipynb.

Note that any model architecture can be used as the generator and discriminator model such as RNNs or Transformers.

Code explanation

(1) data_loading.py

  • Transform raw time-series data to preprocessed time-series data (Googld data)
  • Generate Sine data

(2) Metrics directory (a) visualization_metrics.py

  • PCA and t-SNE analysis between Original data and Synthetic data (b) discriminative_metrics.py
  • Use Post-hoc RNN to classify Original data and Synthetic data (c) predictive_metrics.py
  • Use Post-hoc RNN to predict one-step ahead (last feature)

(3) timegan.py

  • Use original time-series data as training set to generater synthetic time-series data

(4) main_timegan.py

  • Report discriminative and predictive scores for the dataset and t-SNE and PCA analysis

(5) utils.py

  • Some utility functions for metrics and timeGAN.

Command inputs:

  • data_name: sine, stock, or energy
  • seq_len: sequence length
  • module: gru, lstm, or lstmLN
  • hidden_dim: hidden dimensions
  • num_layers: number of layers
  • iterations: number of training iterations
  • batch_size: the number of samples in each batch
  • metric_iterations: number of iterations for metric computation

Note that network parameters should be optimized for different datasets.

Example command

$ python3 main_timegan.py --data_name stock --seq_len 24 --module gru
--hidden_dim 24 --num_layer 3 --iteration 50000 --batch_size 128 
--metric_iteration 10

Outputs

  • ori_data: original data
  • generated_data: generated synthetic data
  • metric_results: discriminative and predictive scores
  • visualization: PCA and tSNE analysis
Comments
  • Question on supervisor function

    Question on supervisor function

    I am struggling to understand the actual function of supervisor. G_loss_S = tf.losses.mean_squared_error(H[:,1:,:], H_hat_supervise[:,1:,:]) What this line acutally does? Doesn't it force supervisor to learn identity between H and H_hat_supervise?

    What sequence should the supervisor generate? Is it generating from [0, T] to [1, T+1] or is it trying to reflect the original sequence [0, T]?

    opened by karkawal 7
  • TF is depreciated

    TF is depreciated

    Hi !

    First, thanks for the amazing work. I would like to use this code but unfortunately, all the warning from your Jupiter Notebook are now errors since TensorFlow dropped the next version.

    Is there any way to have the code updated?

    Thanks and keep the good job !

    opened by bishlarr 6
  • Error: AttributeError: module 'tensorflow' has no attribute 'reset_default_graph'

    Error: AttributeError: module 'tensorflow' has no attribute 'reset_default_graph'

    Hi, Thanks for the wonderful Time Gans approach. I was trying to execute the Juypter notebook from Colab and while executing the line " generated_data = timegan(ori_data, parameters) " I am getting Attribute Error. Have attached the error detail below. Kindly let me how to overcome this error. Thanks

    Mritula

    AttributeError Traceback (most recent call last) in () 1 # Run TimeGAN ----> 2 generated_data = timegan(ori_data, parameters) 3 print('Finish Synthetic Data Generation')

    /content/cloned-repo/cloned-repo/timegan.py in timegan(ori_data, parameters) 36 """ 37 # Initialization on the Graph ---> 38 tf.reset_default_graph() 39 40 # Basic Parameters

    AttributeError: module 'tensorflow' has no attribute 'reset_default_graph'

    opened by MritulaC 6
  • Output from TimeGAN for time series with data of each day

    Output from TimeGAN for time series with data of each day

    Hello @jsyoon0823 , As the ouput is synthetic time series, as for example I am using time series data from start date to end date. So, how to determine what would be start date and end date of synthetic time series generated?

    opened by Nasrin15 5
  • Format of output of generated data

    Format of output of generated data

    Hi!

    When I generate data, let's say with da dataset with 1000 samples and sequence length 10 and 20 features, the output of the generated data should have the shape (1000, 10, 20), am I right? How can I convert the data back in the shape of the original data, so (1000, 20)?

    opened by Zepp3 5
  • How to process the unfixed length samples of the datasets?

    How to process the unfixed length samples of the datasets?

    Hi, Yoon! It is a great work for sequence generation! And I am a new at this field, May I ask a question that if I could use my own dataset with different length(timestamp) of each multidimensional sample(in another word,the sample has the shape as [timestamp, features], whose 'timestamp' is unfixed while 'features' is fixed), what should I do to process the data as well as the training model? Yours, Hu!

    opened by hujb48 4
  • Why flip the data?

    Why flip the data?

    Hi!

    Why does the data get flipped for the purpose of chronology. As far as I can see, the original dataset of energy data for example is already in chronological order.

    Kind regards!

    opened by Zepp3 4
  • Supervised loss

    Supervised loss

    Hi @jsyoon0823, Thank you for your great work and for sharing your code.

    I have a few questions related to the implementation of supervised loss introduced in the paper. First, in Eq. 9: image the generator takes in z_t as the input, while in the code, I see no z in the arguments here https://github.com/jsyoon0823/TimeGAN/blob/master/timegan.py#L132.

    Second, I see you create another supervisor network for that purpose instead of using the generator, and the loss here https://github.com/jsyoon0823/TimeGAN/blob/master/timegan.py#L200 (between H=embedder(X, T) and H_hat_supervise=supervisor(H, T)) has no connection with the generator, so I wonder how the supervision loss helps training generator (same question with issue #35).

    Third, what is the motivation for using num_layers-1 layers in the supervisor network? (https://github.com/jsyoon0823/TimeGAN/blob/master/timegan.py#L143)

    Please correct me if I misunderstand something.

    Best, Hieu

    opened by hieuvt29 3
  • Random vector z_t from the Wiener process

    Random vector z_t from the Wiener process

    Firstly, many thanks for your countless efforts on the work of TimeGAN and the distribution of the package to the community. I'm really enjoying implementing it!

    One question to ask regarding the random vector, from the theory within the paper and the code implementation.

    In the paper, z_t is thought to be the Wiener process which I think is reasonable since the time correlation is present throughout the series. In the code implementation, however, I've noticed that the way you generate the random vector is via the random_generator function from the utils.py, which samples its element from the NumPy uniform function.

    As far as I know, the NumPy uniform function is independent of the previously sampled value and does not form a Wiener process.

    Am I missing something here?

    Thanks.

    opened by TMmichi 3
  • Supervised Loss

    Supervised Loss

    First of all, great work with TimeGAN! Really an interesting paper.

    I have a question regarding the supervised loss, computed as follows: G_loss_S = tf.losses.mean_squared_error(H[:,1:,:], H_hat_supervise[:,:-1,:]) .

    I understand the purpose of the supervisor. However, I am confused by the fact that the generator is supposed to be trained on G_loss_S in the second step of training TimeGAN (you call it 'Training only with supervised loss'), although it does not contribute to the computation and consequently no gradients are available. Why is that?

    opened by gmbss0 3
  • Simulation Reproducibility

    Simulation Reproducibility

    Hi, I have a trouble about how to reproduce the results on autoregressive multivariate Gaussian data on section 5.1. I write multivariate gaussian data generation code according to your description, but I failed finally. So, What should I do to reproduce it? Here is my code, can you help me to solve this difficult? Thanks in advance!

    def normalize(data):
        def min_max_norm(data):
            """ Normalize data to range [0, 1]. """
            min_val = np.min(data, axis=0)
            max_val = np.max(data, axis=0)
            data = (data - min_val)/(max_val - min_val + 1e-7)
    
            return data
        
        ori_data = np.array(data)
    
        return min_max_norm(ori_data)
    
    def get_multi_gaussian_data(num_samples, seq_len, num_features, phi, sigma, burn_in=0):
        """ Multivariate Gaussian Data Generation
    
        Args:
            - num_samples: the number of samples
            - seq_len: sequence length of each time-series sample
            - num_features: the number of features of multivariate gaussian data
            - phi: control the correlation across time steps
            - sigma: control the correlation across features
    
        Returns:
            - data: generated multi-gaussian data, [num_samples, seq_len, num_features]    
        """
        # First: generate time-series data
        total_len = num_samples + seq_len + burn_in
        x = np.zeros((total_len, num_features))
        ## Set mean and covariace matrix for multivariate normal distribution
        one = np.ones(num_features)
        ide_mat = np.identity(num_features)     # identity matrix
        mu = np.zeros(num_features)
        cov_mat = sigma*one + (1-sigma)*ide_mat
        ## epsilon matrix
        eps_mat = np.random.multivariate_normal(mu, cov_mat, total_len)
        ## generate t+1 step from t step
        x[0, :] = 0     # x_0 = 0
        for t in range(1, total_len):   # x_1, x_2, ..., x_{total_len-1}
            x[t, :] = phi*x[t-1, :] + eps_mat[t-1, :]
        ## delete first burn_in samples
        x = x[burn_in:, :]
    
        # Second: data normalization
        x = normalize(x)
    
        # Third: samples generation
        ## Initialize the output
        data = []
        ## each sample has shape seq_len*num_features
        for i in range(x.shape[0] - seq_len):
            data_ = x[i:(i+seq_len), :]
            data.append(data_)
        
        return np.array(data)       # [num_samples, seq_len, num_features]
    
    opened by doer-lab 3
  • Bump tensorflow from 1.15.0 to 2.9.3

    Bump tensorflow from 1.15.0 to 2.9.3

    Bumps tensorflow from 1.15.0 to 2.9.3.

    Release notes

    Sourced from tensorflow's releases.

    TensorFlow 2.9.3

    Release 2.9.3

    This release introduces several vulnerability fixes:

    TensorFlow 2.9.2

    Release 2.9.2

    This releases introduces several vulnerability fixes:

    ... (truncated)

    Changelog

    Sourced from tensorflow's changelog.

    Release 2.9.3

    This release introduces several vulnerability fixes:

    Release 2.8.4

    This release introduces several vulnerability fixes:

    ... (truncated)

    Commits
    • a5ed5f3 Merge pull request #58584 from tensorflow/vinila21-patch-2
    • 258f9a1 Update py_func.cc
    • cd27cfb Merge pull request #58580 from tensorflow-jenkins/version-numbers-2.9.3-24474
    • 3e75385 Update version numbers to 2.9.3
    • bc72c39 Merge pull request #58482 from tensorflow-jenkins/relnotes-2.9.3-25695
    • 3506c90 Update RELEASE.md
    • 8dcb48e Update RELEASE.md
    • 4f34ec8 Merge pull request #58576 from pak-laura/c2.99f03a9d3bafe902c1e6beb105b2f2417...
    • 6fc67e4 Replace CHECK with returning an InternalError on failing to create python tuple
    • 5dbe90a Merge pull request #58570 from tensorflow/r2.9-7b174a0f2e4
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
Owner
Jinsung Yoon
Research Scientist at Google Cloud AI
Jinsung Yoon
TAug :: Time Series Data Augmentation using Deep Generative Models

TAug :: Time Series Data Augmentation using Deep Generative Models Note!!! The package is under development so be careful for using in production! Fea

null 35 Dec 6, 2022
Minimal PyTorch implementation of Generative Latent Optimization from the paper "Optimizing the Latent Space of Generative Networks"

Minimal PyTorch implementation of Generative Latent Optimization This is a reimplementation of the paper Piotr Bojanowski, Armand Joulin, David Lopez-

Thomas Neumann 117 Nov 27, 2022
StudioGAN is a Pytorch library providing implementations of representative Generative Adversarial Networks (GANs) for conditional/unconditional image generation.

StudioGAN is a Pytorch library providing implementations of representative Generative Adversarial Networks (GANs) for conditional/unconditional image generation.

null 3k Jan 8, 2023
[ICLR 2021, Spotlight] Large Scale Image Completion via Co-Modulated Generative Adversarial Networks

Large Scale Image Completion via Co-Modulated Generative Adversarial Networks, ICLR 2021 (Spotlight) Demo | Paper [NEW!] Time to play with our interac

Shengyu Zhao 373 Jan 2, 2023
Regularizing Generative Adversarial Networks under Limited Data (CVPR 2021)

Regularizing Generative Adversarial Networks under Limited Data [Project Page][Paper] Implementation for our GAN regularization method. The proposed r

Google 148 Nov 18, 2022
NR-GAN: Noise Robust Generative Adversarial Networks

NR-GAN: Noise Robust Generative Adversarial Networks (CVPR 2020) This repository provides PyTorch implementation for noise robust GAN (NR-GAN). NR-GAN

Takuhiro Kaneko 59 Dec 11, 2022
HiFi-GAN: Generative Adversarial Networks for Efficient and High Fidelity Speech Synthesis

HiFi-GAN: Generative Adversarial Networks for Efficient and High Fidelity Speech Synthesis Jungil Kong, Jaehyeon Kim, Jaekyoung Bae In our paper, we p

Rishikesh (ऋषिकेश) 31 Dec 8, 2022
Generating Anime Images by Implementing Deep Convolutional Generative Adversarial Networks paper

AnimeGAN - Deep Convolutional Generative Adverserial Network PyTorch implementation of DCGAN introduced in the paper: Unsupervised Representation Lear

Rohit Kukreja 23 Jul 21, 2022
π-GAN: Periodic Implicit Generative Adversarial Networks for 3D-Aware Image Synthesis

π-GAN: Periodic Implicit Generative Adversarial Networks for 3D-Aware Image Synthesis Project Page | Paper | Data Eric Ryan Chan*, Marco Monteiro*, Pe

null 375 Dec 31, 2022
Unofficial implementation of Alias-Free Generative Adversarial Networks. (https://arxiv.org/abs/2106.12423) in PyTorch

alias-free-gan-pytorch Unofficial implementation of Alias-Free Generative Adversarial Networks. (https://arxiv.org/abs/2106.12423) This implementation

Kim Seonghyeon 502 Jan 3, 2023
PyTorch implementations of Generative Adversarial Networks.

This repository has gone stale as I unfortunately do not have the time to maintain it anymore. If you would like to continue the development of it as

Erik Linder-Norén 13.4k Jan 8, 2023
Image Deblurring using Generative Adversarial Networks

DeblurGAN arXiv Paper Version Pytorch implementation of the paper DeblurGAN: Blind Motion Deblurring Using Conditional Adversarial Networks. Our netwo

Orest Kupyn 2.2k Jan 1, 2023
Partial implementation of ODE-GAN technique from the paper Training Generative Adversarial Networks by Solving Ordinary Differential Equations

ODE GAN (Prototype) in PyTorch Partial implementation of ODE-GAN technique from the paper Training Generative Adversarial Networks by Solving Ordinary

Somshubra Majumdar 15 Feb 10, 2022
Pytorch implementation for reproducing StackGAN_v2 results in the paper StackGAN++: Realistic Image Synthesis with Stacked Generative Adversarial Networks

StackGAN-v2 StackGAN-v1: Tensorflow implementation StackGAN-v1: Pytorch implementation Inception score evaluation Pytorch implementation for reproduci

Han Zhang 809 Dec 16, 2022
Code for "On the Effects of Batch and Weight Normalization in Generative Adversarial Networks"

Note: this repo has been discontinued, please check code for newer version of the paper here Weight Normalized GAN Code for the paper "On the Effects

Sitao Xiang 182 Sep 6, 2021
PyTorch implementation of "Learning to Discover Cross-Domain Relations with Generative Adversarial Networks"

DiscoGAN in PyTorch PyTorch implementation of Learning to Discover Cross-Domain Relations with Generative Adversarial Networks. * All samples in READM

Taehoon Kim 1k Jan 4, 2023
Official implementation of "Learning to Discover Cross-Domain Relations with Generative Adversarial Networks"

DiscoGAN Official PyTorch implementation of Learning to Discover Cross-Domain Relations with Generative Adversarial Networks. Prerequisites Python 2.7

SK T-Brain 754 Dec 29, 2022
A simple PyTorch Implementation of Generative Adversarial Networks, focusing on anime face drawing.

AnimeGAN A simple PyTorch Implementation of Generative Adversarial Networks, focusing on anime face drawing. Randomly Generated Images The images are

Jie Lei 雷杰 1.2k Jan 3, 2023
Alias-Free Generative Adversarial Networks (StyleGAN3) Official PyTorch implementation

Alias-Free Generative Adversarial Networks (StyleGAN3) Official PyTorch implementation

NVIDIA Research Projects 4.8k Jan 9, 2023