# Path: dlearn/models/block.py
# class Block(object):
# 
#     """Construct a base class to represent an input-output black box.
# 
#     Attributes
#     ----------
#     parameters : list of theano.tensor
#         The block parameters. *Read-only*.
#     input : theano.tensor or list of theano.tensor
#         The input symbol(s) of the block. *Read-only*.
#     output : theano.tensor or list of theano.tensor
#         The output symbol(s) of the block. *Read-only*.
#     dropout_input : None, theano.tensor, or list of theano.tensor
#         None if no dropout input symbol is specified, and the `input` will be
#         used as `dropout_input`. *Read-only*.
#     dropout_output : None, theano.tensor, or list of theano.tensor
#         None if no dropout for this layer, and the `output` will be used as
#         `dropout_output`. *Read-only*.
# 
#     Parameters
#     ----------
#     input : theano.tensor or list of theano.tensor
#         The input symbol(s) of the block.
#     dropout_input : None, theano.tensor, or list of theano.tensor, optional
#         None if no dropout input symbol is specified, and the `input` will be
#         used as `dropout_input`. Default is None.
# 
#     """
# 
#     def __init__(self, input, dropout_input=None):
#         super(Block, self).__init__()
# 
#         self._params = []
#         self._input = input
#         self._output = input
# 
#         if dropout_input is None:
#             self._dropout_input = self._input
#         else:
#             self._dropout_input = dropout_input
# 
#         self._dropout_output = self._dropout_input
# 
#     @property
#     def parameters(self):
#         return self._params
# 
#     @property
#     def input(self):
#         return self._input
# 
#     @property
#     def output(self):
#         return self._output
# 
#     @property
#     def dropout_input(self):
#         return self._dropout_input
# 
#     @property
#     def dropout_output(self):
#         return self._dropout_output
# 
# Path: dlearn/utils/actfuncs.py
# def identity(x):
# def relu(x):
# 
# Path: dlearn/utils/math.py
# def create_shared(x):
# def create_empty(p):
# def dropout(x, ratio):


import numpy as np
import theano
import theano.tensor as T
from .block import Block
from ..utils import actfuncs
from ..utils.math import nprng, dropout
                dtype=theano.config.floatX)

            init_b = np.zeros(fan_out, dtype=theano.config.floatX)

            init_c = np.zeros(fan_in, dtype=theano.config.floatX)

            self._W.append(theano.shared(value=init_W, borrow=True))
            self._b.append(theano.shared(value=init_b, borrow=True))
            self._c.append(theano.shared(value=init_c, borrow=True))

        self._params = self._W + self._b + self._c

        def f(x, is_training):
            z = x
            for W, b in zip(self._W, self._b):
                z = T.dot(z, W) + b
                if self._active_func is not None:
                    z = self._active_func(z)
                if self._dropout_ratio is not None and self._dropout_ratio > 0:
                    if is_training:
                        z = dropout(z, self._dropout_ratio)
                    else:
                        z = (1.0 - self._dropout_ratio) * z                

            y = z
            for W, c in reversed(zip(self._W, self._c)):
                y = T.dot(y, W.T) + c
                if self._active_func is not None:
                    y = self._active_func(y)


# Path: dlearn/models/block.py
# class Block(object):
# 
#     """Construct a base class to represent an input-output black box.
# 
#     Attributes
#     ----------
#     parameters : list of theano.tensor
#         The block parameters. *Read-only*.
#     input : theano.tensor or list of theano.tensor
#         The input symbol(s) of the block. *Read-only*.
#     output : theano.tensor or list of theano.tensor
#         The output symbol(s) of the block. *Read-only*.
#     dropout_input : None, theano.tensor, or list of theano.tensor
#         None if no dropout input symbol is specified, and the `input` will be
#         used as `dropout_input`. *Read-only*.
#     dropout_output : None, theano.tensor, or list of theano.tensor
#         None if no dropout for this layer, and the `output` will be used as
#         `dropout_output`. *Read-only*.
# 
#     Parameters
#     ----------
#     input : theano.tensor or list of theano.tensor
#         The input symbol(s) of the block.
#     dropout_input : None, theano.tensor, or list of theano.tensor, optional
#         None if no dropout input symbol is specified, and the `input` will be
#         used as `dropout_input`. Default is None.
# 
#     """
# 
#     def __init__(self, input, dropout_input=None):
#         super(Block, self).__init__()
# 
#         self._params = []
#         self._input = input
#         self._output = input
# 
#         if dropout_input is None:
#             self._dropout_input = self._input
#         else:
#             self._dropout_input = dropout_input
# 
#         self._dropout_output = self._dropout_input
# 
#     @property
#     def parameters(self):
#         return self._params
# 
#     @property
#     def input(self):
#         return self._input
# 
#     @property
#     def output(self):
#         return self._output
# 
#     @property
#     def dropout_input(self):
#         return self._dropout_input
# 
#     @property
#     def dropout_output(self):
#         return self._dropout_output
# 
# Path: dlearn/utils/actfuncs.py
# def identity(x):
# def relu(x):
# 
# Path: dlearn/utils/math.py
# def create_shared(x):
# def create_empty(p):
# def dropout(x, ratio):


# Path: dlearn/models/autoencoder.py
import numpy as np
import theano
import theano.tensor as T
from .block import Block
from ..utils import actfuncs
from ..utils.math import nprng, dropout

                dtype=theano.config.floatX)

            init_b = np.zeros(fan_out, dtype=theano.config.floatX)

            init_c = np.zeros(fan_in, dtype=theano.config.floatX)

            self._W.append(theano.shared(value=init_W, borrow=True))
            self._b.append(theano.shared(value=init_b, borrow=True))
            self._c.append(theano.shared(value=init_c, borrow=True))

        self._params = self._W + self._b + self._c

        def f(x, is_training):
            z = x
            for W, b in zip(self._W, self._b):
                z = T.dot(z, W) + b
                if self._active_func is not None:
                    z = self._active_func(z)
                if self._dropout_ratio is not None and self._dropout_ratio > 0:
                    if is_training:
                        z = dropout(z, self._dropout_ratio)
                    else:
                        z = (1.0 - self._dropout_ratio) * z                

            y = z
            for W, c in reversed(zip(self._W, self._c)):
                y = T.dot(y, W.T) + c
                if self._active_func is not None:
                    y = self._active_func(y)


            return (z, y)