# Path: code/nn/initialization.py
# USE_XAVIER_INIT = False
# def get_activation_by_name(name):
# def set_default_rng_seed(seed):
# def random_init(size, rng=None, rng_type=None):
# def create_shared(vals, name=None):
# 
# Path: code/nn/initialization.py
# def set_default_rng_seed(seed):
#     global default_rng, default_srng
#     random.seed(seed)
#     default_rng = np.random.RandomState(random.randint(0,9999))
#     default_srng = T.shared_randomstreams.RandomStreams(default_rng.randint(9999))
# 
# def random_init(size, rng=None, rng_type=None):
#     if rng is None: rng = default_rng
#     if rng_type is None:
#         #vals = rng.standard_normal(size)
#         vals = rng.uniform(low=-0.05, high=0.05, size=size)
# 
#     elif rng_type == "normal":
#         vals = rng.standard_normal(size)
# 
#     elif rng_type == "uniform":
#         vals = rng.uniform(low=-3.0**0.5, high=3.0**0.5, size=size)
# 
#     else:
#         raise Exception(
#             "unknown random inittype: {}".format(rng_type)
#           )
# 
#     return vals.astype(theano.config.floatX)
# 
# def create_shared(vals, name=None):
#     return theano.shared(vals, name=name)
# 
# Path: code/nn/initialization.py
# USE_XAVIER_INIT = False
# def get_activation_by_name(name):
# def set_default_rng_seed(seed):
# def random_init(size, rng=None, rng_type=None):
# def create_shared(vals, name=None):


import numpy as np
import theano
import theano.tensor as T
from utils import say
from .initialization import default_srng, default_rng, USE_XAVIER_INIT
from .initialization import set_default_rng_seed, random_init, create_shared
from .initialization import ReLU, sigmoid, tanh, softmax, linear, get_activation_by_name
    Each instance has a forward() method which takes x as input and return the
    post-activation representation y;

    Recurrent layers has two forward methods implemented:
        -- forward(x_t, h_tm1):  one step of forward given input x and previous
                                 hidden state h_tm1; return next hidden state

        -- forward_all(x, h_0):  apply successively steps given all inputs and
                                 initial hidden state, and return all hidden
                                 states h1, ..., h_n

    @author: Tao Lei
'''



class Dropout(object):
    '''
        Dropout layer. forward(x) returns the dropout version of x

        Inputs
        ------

        dropout_prob : theano shared variable that stores the dropout probability
        srng         : theano random stream or None (default rng will be used)
        v2           : which dropout version to use

    '''
    def __init__(self, dropout_prob, srng=None, v2=False):
        self.dropout_prob = dropout_prob

# Path: code/nn/initialization.py
# USE_XAVIER_INIT = False
# def get_activation_by_name(name):
# def set_default_rng_seed(seed):
# def random_init(size, rng=None, rng_type=None):
# def create_shared(vals, name=None):
# 
# Path: code/nn/initialization.py
# def set_default_rng_seed(seed):
#     global default_rng, default_srng
#     random.seed(seed)
#     default_rng = np.random.RandomState(random.randint(0,9999))
#     default_srng = T.shared_randomstreams.RandomStreams(default_rng.randint(9999))
# 
# def random_init(size, rng=None, rng_type=None):
#     if rng is None: rng = default_rng
#     if rng_type is None:
#         #vals = rng.standard_normal(size)
#         vals = rng.uniform(low=-0.05, high=0.05, size=size)
# 
#     elif rng_type == "normal":
#         vals = rng.standard_normal(size)
# 
#     elif rng_type == "uniform":
#         vals = rng.uniform(low=-3.0**0.5, high=3.0**0.5, size=size)
# 
#     else:
#         raise Exception(
#             "unknown random inittype: {}".format(rng_type)
#           )
# 
#     return vals.astype(theano.config.floatX)
# 
# def create_shared(vals, name=None):
#     return theano.shared(vals, name=name)
# 
# Path: code/nn/initialization.py
# USE_XAVIER_INIT = False
# def get_activation_by_name(name):
# def set_default_rng_seed(seed):
# def random_init(size, rng=None, rng_type=None):
# def create_shared(vals, name=None):


# Path: code/nn/basic.py
import numpy as np
import theano
import theano.tensor as T
from utils import say
from .initialization import default_srng, default_rng, USE_XAVIER_INIT
from .initialization import set_default_rng_seed, random_init, create_shared
from .initialization import ReLU, sigmoid, tanh, softmax, linear, get_activation_by_name

    Each instance has a forward() method which takes x as input and return the
    post-activation representation y;

    Recurrent layers has two forward methods implemented:
        -- forward(x_t, h_tm1):  one step of forward given input x and previous
                                 hidden state h_tm1; return next hidden state

        -- forward_all(x, h_0):  apply successively steps given all inputs and
                                 initial hidden state, and return all hidden
                                 states h1, ..., h_n

    @author: Tao Lei
'''



class Dropout(object):
    '''
        Dropout layer. forward(x) returns the dropout version of x

        Inputs
        ------

        dropout_prob : theano shared variable that stores the dropout probability
        srng         : theano random stream or None (default rng will be used)
        v2           : which dropout version to use

    '''
    def __init__(self, dropout_prob, srng=None, v2=False):
        self.dropout_prob = dropout_prob

        self.srng = srng if srng is not None else default_srng