# 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
    self.gen_params = [v for v in t_vars if v.name.startswith('gen')]
    self.gen_optimizer = tf.train.AdamOptimizer(lr, beta1=beta1)
    self.gen_loss = -tf.reduce_mean(self.fake_score)
    self.gen_train_ops = self.gen_optimizer.minimize(
        self.gen_loss + gamma * self.l2_loss, var_list=self.gen_params)

  def generate(self, sess, x):
    return sess.run(self.fake_y, {self.input_x: x})

  def train_disc_one_batch(self, sess, x, y):
    d_err, _ = sess.run([self.disc_loss, self.disc_train_ops],
                        {self.input_x: x, self.input_y: y})
    return d_err

  def train_gen_one_batch(self, sess, x, y):
    g_err, l2_err, _ = sess.run([-self.gen_loss, self.l2_loss,
                                 self.gen_train_ops],
                                {self.input_x: x, self.input_y: y})
    return g_err, l2_err


def gan_mapping(x, y, lr=1e-4, lmbda=10., gamma=0., beta1=0.5,
                activation=tf.nn.relu, epoch=30, disc_iters=10,
                batch_size=128):
  n_data, x_dim = x.shape
  y_dim = y.shape[1]
  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)

# 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

    self.gen_params = [v for v in t_vars if v.name.startswith('gen')]
    self.gen_optimizer = tf.train.AdamOptimizer(lr, beta1=beta1)
    self.gen_loss = -tf.reduce_mean(self.fake_score)
    self.gen_train_ops = self.gen_optimizer.minimize(
        self.gen_loss + gamma * self.l2_loss, var_list=self.gen_params)

  def generate(self, sess, x):
    return sess.run(self.fake_y, {self.input_x: x})

  def train_disc_one_batch(self, sess, x, y):
    d_err, _ = sess.run([self.disc_loss, self.disc_train_ops],
                        {self.input_x: x, self.input_y: y})
    return d_err

  def train_gen_one_batch(self, sess, x, y):
    g_err, l2_err, _ = sess.run([-self.gen_loss, self.l2_loss,
                                 self.gen_train_ops],
                                {self.input_x: x, self.input_y: y})
    return g_err, l2_err


def gan_mapping(x, y, lr=1e-4, lmbda=10., gamma=0., beta1=0.5,
                activation=tf.nn.relu, epoch=30, disc_iters=10,
                batch_size=128):
  n_data, x_dim = x.shape
  y_dim = y.shape[1]
  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)