# Path: utils/sent_utils.py
# def inf_batch_iterator(n, batch_size, shuffle=True, include_last=False):
#   while True:
#     for indices in iterate_minibatches_indices(n, batch_size,
#                                                shuffle, include_last):
#       yield indices
# 
# def iterate_minibatches_indices(n, batch_size, shuffle=False,
#                                 include_last=True):
#   indices = np.arange(n)
# 
#   num_batches = n // batch_size
#   if include_last:
#     num_batches += (n % batch_size != 0)
# 
#   if num_batches == 0:
#     num_batches = 1
# 
#   if shuffle:
#     np.random.shuffle(indices)
# 
#   for batch_idx in range(num_batches):
#     batch_indices = indices[batch_idx * batch_size:
#                             (batch_idx + 1) * batch_size]
#     yield batch_indices
# 
# Path: utils/common_utils.py
# def log(msg):
#   if msg[-1] != '\n':
#     msg += '\n'
#   sys.stderr.write(msg)
#   sys.stderr.flush()


from utils.sent_utils import inf_batch_iterator, iterate_minibatches_indices
from utils.common_utils import log
import sklearn.linear_model as linear_model
import tensorflow as tf
import numpy as np
  model = WGANGP(x_dim, y_dim, lr=lr, lmbda=lmbda, gamma=gamma, beta1=beta1,
                 activation=activation)

  gen_sampler = inf_batch_iterator(n_data, batch_size)
  disc_sampler = inf_batch_iterator(n_data, batch_size)
  num_batch_per_epoch = n_data // batch_size + (n_data % batch_size) != 0

  sess = tf.Session()
  sess.run(tf.global_variables_initializer())
  for e in range(epoch):
    train_d_loss = []
    train_g_loss = []
    train_l2_loss = []
    for _ in range(num_batch_per_epoch):
      # train disc first
      for _ in range(disc_iters):
        disc_idx = next(disc_sampler)
        disc_x, disc_y = x[disc_idx], y[disc_idx]
        d_err = model.train_disc_one_batch(sess, disc_x, disc_y)
        train_d_loss.append(d_err)

      gen_idx = next(gen_sampler)
      gen_x, gen_y = x[gen_idx], y[gen_idx]
      g_err, l2_err = model.train_gen_one_batch(sess, gen_x, gen_y)
      train_g_loss.append(g_err)
      train_l2_loss.append(l2_err)

    train_d_loss = np.mean(train_d_loss)
    train_g_loss = np.mean(train_g_loss)
    train_l2_loss = np.mean(train_l2_loss)

# Path: utils/sent_utils.py
# def inf_batch_iterator(n, batch_size, shuffle=True, include_last=False):
#   while True:
#     for indices in iterate_minibatches_indices(n, batch_size,
#                                                shuffle, include_last):
#       yield indices
# 
# def iterate_minibatches_indices(n, batch_size, shuffle=False,
#                                 include_last=True):
#   indices = np.arange(n)
# 
#   num_batches = n // batch_size
#   if include_last:
#     num_batches += (n % batch_size != 0)
# 
#   if num_batches == 0:
#     num_batches = 1
# 
#   if shuffle:
#     np.random.shuffle(indices)
# 
#   for batch_idx in range(num_batches):
#     batch_indices = indices[batch_idx * batch_size:
#                             (batch_idx + 1) * batch_size]
#     yield batch_indices
# 
# Path: utils/common_utils.py
# def log(msg):
#   if msg[-1] != '\n':
#     msg += '\n'
#   sys.stderr.write(msg)
#   sys.stderr.flush()


# Path: train_feature_mapper.py
from utils.sent_utils import inf_batch_iterator, iterate_minibatches_indices
from utils.common_utils import log
import sklearn.linear_model as linear_model
import tensorflow as tf
import numpy as np

  model = WGANGP(x_dim, y_dim, lr=lr, lmbda=lmbda, gamma=gamma, beta1=beta1,
                 activation=activation)

  gen_sampler = inf_batch_iterator(n_data, batch_size)
  disc_sampler = inf_batch_iterator(n_data, batch_size)
  num_batch_per_epoch = n_data // batch_size + (n_data % batch_size) != 0

  sess = tf.Session()
  sess.run(tf.global_variables_initializer())
  for e in range(epoch):
    train_d_loss = []
    train_g_loss = []
    train_l2_loss = []
    for _ in range(num_batch_per_epoch):
      # train disc first
      for _ in range(disc_iters):
        disc_idx = next(disc_sampler)
        disc_x, disc_y = x[disc_idx], y[disc_idx]
        d_err = model.train_disc_one_batch(sess, disc_x, disc_y)
        train_d_loss.append(d_err)

      gen_idx = next(gen_sampler)
      gen_x, gen_y = x[gen_idx], y[gen_idx]
      g_err, l2_err = model.train_gen_one_batch(sess, gen_x, gen_y)
      train_g_loss.append(g_err)
      train_l2_loss.append(l2_err)

    train_d_loss = np.mean(train_d_loss)
    train_g_loss = np.mean(train_g_loss)
    train_l2_loss = np.mean(train_l2_loss)

    log('Epoch: {}, disc loss: {:.4f}, gen loss: {:.4f},'