# Path: seya/regularizers.py
# class GaussianKL(Regularizer):
#     """ KL-divergence between two gaussians.
#     Useful for Variational AutoEncoders.
#     Use this as an activation regularizer
# 
#     Parameters:
#     -----------
#     mean, logsigma: parameters of the input distributions
#     prior_mean, prior_logsigma: paramaters of the desired distribution (note the
#     log on logsigma)
#     regularizer_scale: Rescales the regularization cost. Keep this 1 for most cases.
# 
#     Notes:
#     ------
#     See seya.layers.variational.VariationalDense for usage example
# 
#     """
#     def __init__(self, mean, logsigma, prior_mean=0, prior_logsigma=0,
#                  regularizer_scale=1):
#         self.regularizer_scale = regularizer_scale
#         self.mean = mean
#         self.logsigma = logsigma
#         self.prior_mean = prior_mean
#         self.prior_logsigma = prior_logsigma
#         super(GaussianKL, self).__init__()
# 
#     def __call__(self, loss):
#         # See Variational Auto-Encoding Bayes by Kingma and Welling.
#         mean, logsigma = self.mean, self.logsigma
#         kl = (self.prior_logsigma - logsigma +
#               0.5 * (-1 + K.exp(2 * logsigma) + (mean - self.prior_mean) ** 2) /
#               K.exp(2 * self.prior_logsigma))
#         loss += K.mean(kl) * self.regularizer_scale
#         return loss
# 
#     def get_config(self):
#         return {"name": self.__class__.__name__}
# 
# class LambdaRegularizer(Regularizer):
#     def __init__(self, cost):
#         super(LambdaRegularizer, self).__init__()
#         self.cost = cost
# 
#     def __call__(self, loss):
#         loss += self.cost
#         return loss
# 
#     def get_config(self):
#         return {"name": self.__class__.__name__}


from collections import OrderedDict
from keras import backend as K
from keras.layers.core import Layer
from keras import initializations, activations
from keras.layers.convolutional import MaxPooling1D
from seya.regularizers import GaussianKL, LambdaRegularizer
        self.init = initializations.get(init)
        self.activation = activations.get(activation)
        self.code_dim = code_dim
        self.initial_weights = weights
        self.input_dim = input_dim
        if self.input_dim:
            kwargs['input_shape'] = (self.input_dim,)
        self.input = K.placeholder(ndim=4)
        super(SlowSiamese, self).__init__(**kwargs)

    def build(self):
        self.encoder.build()
        self.decoder.build()
        self.variational.build()

        outputs = []
        self.regularizers = []
        input_list = self.get_input()
        if isinstance(input_list, OrderedDict):
            assert len(input_list) == 2
            for X in input_list.values():
                Y = self.encoder(X)
                reg = self.variational.get_variational_regularization(Y)
                self.regularizers.append(reg)
                Y = self.variational._get_output(Y, train=True)
                Y = self.decoder(Y)
                outputs.append(Y)
            pool0 = self.max_pool(K.expand_dims(outputs[0], 2))
            pool1 = self.max_pool(K.expand_dims(outputs[1], 2))
            slow = self.beta * ((pool0 - pool1)**2).mean()

# Path: seya/regularizers.py
# class GaussianKL(Regularizer):
#     """ KL-divergence between two gaussians.
#     Useful for Variational AutoEncoders.
#     Use this as an activation regularizer
# 
#     Parameters:
#     -----------
#     mean, logsigma: parameters of the input distributions
#     prior_mean, prior_logsigma: paramaters of the desired distribution (note the
#     log on logsigma)
#     regularizer_scale: Rescales the regularization cost. Keep this 1 for most cases.
# 
#     Notes:
#     ------
#     See seya.layers.variational.VariationalDense for usage example
# 
#     """
#     def __init__(self, mean, logsigma, prior_mean=0, prior_logsigma=0,
#                  regularizer_scale=1):
#         self.regularizer_scale = regularizer_scale
#         self.mean = mean
#         self.logsigma = logsigma
#         self.prior_mean = prior_mean
#         self.prior_logsigma = prior_logsigma
#         super(GaussianKL, self).__init__()
# 
#     def __call__(self, loss):
#         # See Variational Auto-Encoding Bayes by Kingma and Welling.
#         mean, logsigma = self.mean, self.logsigma
#         kl = (self.prior_logsigma - logsigma +
#               0.5 * (-1 + K.exp(2 * logsigma) + (mean - self.prior_mean) ** 2) /
#               K.exp(2 * self.prior_logsigma))
#         loss += K.mean(kl) * self.regularizer_scale
#         return loss
# 
#     def get_config(self):
#         return {"name": self.__class__.__name__}
# 
# class LambdaRegularizer(Regularizer):
#     def __init__(self, cost):
#         super(LambdaRegularizer, self).__init__()
#         self.cost = cost
# 
#     def __call__(self, loss):
#         loss += self.cost
#         return loss
# 
#     def get_config(self):
#         return {"name": self.__class__.__name__}


# Path: seya/layers/temp.py
from collections import OrderedDict
from keras import backend as K
from keras.layers.core import Layer
from keras import initializations, activations
from keras.layers.convolutional import MaxPooling1D
from seya.regularizers import GaussianKL, LambdaRegularizer

        self.init = initializations.get(init)
        self.activation = activations.get(activation)
        self.code_dim = code_dim
        self.initial_weights = weights
        self.input_dim = input_dim
        if self.input_dim:
            kwargs['input_shape'] = (self.input_dim,)
        self.input = K.placeholder(ndim=4)
        super(SlowSiamese, self).__init__(**kwargs)

    def build(self):
        self.encoder.build()
        self.decoder.build()
        self.variational.build()

        outputs = []
        self.regularizers = []
        input_list = self.get_input()
        if isinstance(input_list, OrderedDict):
            assert len(input_list) == 2
            for X in input_list.values():
                Y = self.encoder(X)
                reg = self.variational.get_variational_regularization(Y)
                self.regularizers.append(reg)
                Y = self.variational._get_output(Y, train=True)
                Y = self.decoder(Y)
                outputs.append(Y)
            pool0 = self.max_pool(K.expand_dims(outputs[0], 2))
            pool1 = self.max_pool(K.expand_dims(outputs[1], 2))
            slow = self.beta * ((pool0 - pool1)**2).mean()

            self.regularizers.append(LambdaRegularizer(slow))