# 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 theano.tensor.signal.downsample import max_pool_2d
    from theano.sandbox.cuda.basic_ops import gpu_contiguous
    from pylearn2.sandbox.cuda_convnet.filter_acts import FilterActs
from .block import Block
from ..utils import actfuncs
from ..utils.math import nprng, dropout
        # Initialize parameters
        if w0 is None:
            w0_bound = np.sqrt(6.0 / (self._input_shape + self._output_shape))

            if active_func == actfuncs.sigmoid:
                w0_bound *= 4

            init_w0 = np.asarray(
                nprng.uniform(low=-w0_bound, high=w0_bound,
                              size=(self._input_shape, 1)),
                dtype=theano.config.floatX)

            self._w0 = theano.shared(value=init_w0, borrow=True)
        else:
            self._w0 = w0

        if b0 is None:
            init_b0 = np.asarray(0, theano.config.floatX)

            self._b0 = theano.shared(value=init_b0, borrow=True)
        else:
            self._b0 = b0

        if W is None:
            W_bound = np.sqrt(6.0 / (self._input_shape + self._output_shape))

            if active_func == actfuncs.sigmoid:
                W_bound *= 4

            init_W = np.asarray(

# 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/layer.py
import numpy as np
import theano
import theano.tensor as T
from theano.tensor.signal.downsample import max_pool_2d
    from theano.sandbox.cuda.basic_ops import gpu_contiguous
    from pylearn2.sandbox.cuda_convnet.filter_acts import FilterActs
from .block import Block
from ..utils import actfuncs
from ..utils.math import nprng, dropout

        # Initialize parameters
        if w0 is None:
            w0_bound = np.sqrt(6.0 / (self._input_shape + self._output_shape))

            if active_func == actfuncs.sigmoid:
                w0_bound *= 4

            init_w0 = np.asarray(
                nprng.uniform(low=-w0_bound, high=w0_bound,
                              size=(self._input_shape, 1)),
                dtype=theano.config.floatX)

            self._w0 = theano.shared(value=init_w0, borrow=True)
        else:
            self._w0 = w0

        if b0 is None:
            init_b0 = np.asarray(0, theano.config.floatX)

            self._b0 = theano.shared(value=init_b0, borrow=True)
        else:
            self._b0 = b0

        if W is None:
            W_bound = np.sqrt(6.0 / (self._input_shape + self._output_shape))

            if active_func == actfuncs.sigmoid:
                W_bound *= 4

            init_W = np.asarray(

                nprng.uniform(low=-W_bound, high=W_bound,