# Path: dlearn/utils/math.py
# def create_empty(p):
#     return theano.shared(np.zeros_like(p.get_value(borrow=True)), borrow=True)


import time
import numpy as np
import theano
import theano.tensor as T
from ..utils.math import create_empty
        The number of training epochs. Default is 100.
    valid_freq : None or int, optional
        The number of iterations between validations. If None, then it will be
        set to the size of training batch plus one. Default is None.
    patience_incr : float or double, optional
    lr_decr : float or double, optional
    epoch_waiting : float or double, optional
        `patience` is utilized to stop training when the model converges. It is
        initialized as `n_batches` * 20. After each validation process, if
        `current_valid_error` < `best_valid_error`, then `patience` =
        `current_iter` * `patience_incr`. Otherwise if there is no improvement
        in the last `epoch_waiting` epochs, then `lr` = `lr` * `lr_decr`.
        Default `patience_incr` is 2.0, `lr_decr` is 0.5, and epoch_waiting is
        10.
    never_stop : bool, optional
        If True, then the training process will never stop until user
        interrupts, otherwise it will stop when either reaches `n_epochs` or
        `patience` is consumed.

    """
    n_train_batches = data_provider.train.n_batches
    n_valid_batches = data_provider.valid.n_batches
    n_test_batches = data_provider.test.n_batches

    alpha = T.scalar()  # learning rate
    dummy = T.scalar()  # for parameter updates

    # Comupute updates
    grads = T.grad(model.cost, model.parameters,
                   consider_constant=model.consts)

# Path: dlearn/utils/math.py
# def create_empty(p):
#     return theano.shared(np.zeros_like(p.get_value(borrow=True)), borrow=True)


# Path: dlearn/optimization/sgd.py
import time
import numpy as np
import theano
import theano.tensor as T
from ..utils.math import create_empty

        The number of training epochs. Default is 100.
    valid_freq : None or int, optional
        The number of iterations between validations. If None, then it will be
        set to the size of training batch plus one. Default is None.
    patience_incr : float or double, optional
    lr_decr : float or double, optional
    epoch_waiting : float or double, optional
        `patience` is utilized to stop training when the model converges. It is
        initialized as `n_batches` * 20. After each validation process, if
        `current_valid_error` < `best_valid_error`, then `patience` =
        `current_iter` * `patience_incr`. Otherwise if there is no improvement
        in the last `epoch_waiting` epochs, then `lr` = `lr` * `lr_decr`.
        Default `patience_incr` is 2.0, `lr_decr` is 0.5, and epoch_waiting is
        10.
    never_stop : bool, optional
        If True, then the training process will never stop until user
        interrupts, otherwise it will stop when either reaches `n_epochs` or
        `patience` is consumed.

    """
    n_train_batches = data_provider.train.n_batches
    n_valid_batches = data_provider.valid.n_batches
    n_test_batches = data_provider.test.n_batches

    alpha = T.scalar()  # learning rate
    dummy = T.scalar()  # for parameter updates

    # Comupute updates
    grads = T.grad(model.cost, model.parameters,
                   consider_constant=model.consts)

    incs = [create_empty(p) for p in model.parameters]