# Path: seya/utils.py
# def theano_rng(seed=123):
#     return MRG_RandomStreams(seed=seed)
# 
# Path: seya/regularizers.py
# class GaussianKL(Regularizer):
# class ExponentialKL(Regularizer):
# class LambdaRegularizer(Regularizer):
# class CorrentropyActivityRegularizer(Regularizer):
# class CorrentropyWeightRegularizer(Regularizer):
#     def __init__(self, mean, logsigma, prior_mean=0, prior_logsigma=0,
#                  regularizer_scale=1):
#     def __call__(self, loss):
#     def get_config(self):
#     def __init__(self, _lambda, prior_lambda=1.,
#                  regularizer_scale=1):
#     def __call__(self, loss):
#     def get_config(self):
#     def __init__(self, cost):
#     def __call__(self, loss):
#     def get_config(self):
#     def __init__(self, scale, sigma=1.):
#     def set_layer(self, layer):
#     def __call__(self, loss):
#     def get_config(self):
#     def __init__(self, scale, sigma=1):
#     def set_param(self, p):
#     def __call__(self, loss):
#     def get_config(self):
# def correntropy(x, sigma):


import theano.tensor as T
from theano import scan
from keras.layers.recurrent import GRU, Recurrent, LSTM
from keras.utils.theano_utils import shared_zeros  # , alloc_zeros_matrix
from ..utils import theano_rng
from ..regularizers import SimpleCost
            new_h_dec, self.L_dec, self.b_dec, self.N_dec)
        Fx_w, Fy_w = self._get_filterbank(gx_w, gy_w, sigma2_w, delta_w,
                                          self.N_dec)
        write_patch = self._get_patch(new_h_dec)
        new_canvas = canvas + self._write(write_patch, gamma_w, Fx_w, Fy_w)
        return new_canvas, new_h_enc, new_cell_enc, new_h_dec, new_cell_dec, kl

    def get_output(self, train=False):
        self._train_state = train
        X, eps = self.get_input(train).values()
        eps = eps.dimshuffle(1, 0, 2)

        if self.inner_rnn == 'gru':
            outputs, updates = scan(self._step,
                                    sequences=eps,
                                    outputs_info=self._get_initial_states(X) + (None, ),
                                    non_sequences=[X, ] + self.trainable_weights,
                                    # n_steps=self.n_steps,
                                    truncate_gradient=self.truncate_gradient)

        elif self.inner_rnn == 'lstm':
            outputs, updates = scan(self._step_lstm,
                                    sequences=eps,
                                    outputs_info=self._get_initial_states(X) + (None, ),
                                    non_sequences=[X, ] + self.trainable_weights,
                                    truncate_gradient=self.truncate_gradient)

        kl = outputs[-1].sum(axis=0).mean()
        if train:
            # self.updates = updates

# Path: seya/utils.py
# def theano_rng(seed=123):
#     return MRG_RandomStreams(seed=seed)
# 
# Path: seya/regularizers.py
# class GaussianKL(Regularizer):
# class ExponentialKL(Regularizer):
# class LambdaRegularizer(Regularizer):
# class CorrentropyActivityRegularizer(Regularizer):
# class CorrentropyWeightRegularizer(Regularizer):
#     def __init__(self, mean, logsigma, prior_mean=0, prior_logsigma=0,
#                  regularizer_scale=1):
#     def __call__(self, loss):
#     def get_config(self):
#     def __init__(self, _lambda, prior_lambda=1.,
#                  regularizer_scale=1):
#     def __call__(self, loss):
#     def get_config(self):
#     def __init__(self, cost):
#     def __call__(self, loss):
#     def get_config(self):
#     def __init__(self, scale, sigma=1.):
#     def set_layer(self, layer):
#     def __call__(self, loss):
#     def get_config(self):
#     def __init__(self, scale, sigma=1):
#     def set_param(self, p):
#     def __call__(self, loss):
#     def get_config(self):
# def correntropy(x, sigma):


# Path: seya/layers/draw.py
import theano.tensor as T
from theano import scan
from keras.layers.recurrent import GRU, Recurrent, LSTM
from keras.utils.theano_utils import shared_zeros  # , alloc_zeros_matrix
from ..utils import theano_rng
from ..regularizers import SimpleCost

            new_h_dec, self.L_dec, self.b_dec, self.N_dec)
        Fx_w, Fy_w = self._get_filterbank(gx_w, gy_w, sigma2_w, delta_w,
                                          self.N_dec)
        write_patch = self._get_patch(new_h_dec)
        new_canvas = canvas + self._write(write_patch, gamma_w, Fx_w, Fy_w)
        return new_canvas, new_h_enc, new_cell_enc, new_h_dec, new_cell_dec, kl

    def get_output(self, train=False):
        self._train_state = train
        X, eps = self.get_input(train).values()
        eps = eps.dimshuffle(1, 0, 2)

        if self.inner_rnn == 'gru':
            outputs, updates = scan(self._step,
                                    sequences=eps,
                                    outputs_info=self._get_initial_states(X) + (None, ),
                                    non_sequences=[X, ] + self.trainable_weights,
                                    # n_steps=self.n_steps,
                                    truncate_gradient=self.truncate_gradient)

        elif self.inner_rnn == 'lstm':
            outputs, updates = scan(self._step_lstm,
                                    sequences=eps,
                                    outputs_info=self._get_initial_states(X) + (None, ),
                                    non_sequences=[X, ] + self.trainable_weights,
                                    truncate_gradient=self.truncate_gradient)

        kl = outputs[-1].sum(axis=0).mean()
        if train:
            # self.updates = updates

            self.regularizers = [SimpleCost(kl), ]