@@ -0,0 +1,2713 @@
+from theano import Variable, scan, pp%0Afrom theano.tensor import grad, stack, concatenate%0Afrom theano.gradient import format_as%0Afrom theano.printing import debugprint%0A%0Adef hessian_(cost, wrt, consider_constant=None,%0A            disconnected_inputs='raise'):%0A    %22%22%22%0A    :type cost: Scalar (0-dimensional) Variable.%0A    :type wrt: Vector (1-dimensional tensor) 'Variable' or list of%0A               vectors (1-dimensional tensors) Variables%0A    :param consider_constant: a list of expressions not to backpropagate%0A        through%0A    :type disconnected_inputs: string%0A    :param disconnected_inputs: Defines the behaviour if some of the variables%0A        in %60%60wrt%60%60 are not part of the computational graph computing %60%60cost%60%60%0A        (or if all links are non-differentiable). The possible values are:%0A        - 'ignore': considers that the gradient on these parameters is zero.%0A        - 'warn': consider the gradient zero, and print a warning.%0A        - 'raise': raise an exception.%0A    :return: either a instance of Variable or list/tuple of Variables%0A            (depending upon %60wrt%60) repressenting the Hessian of the %60cost%60%0A            with respect to (elements of) %60wrt%60. If an element of %60wrt%60 is not%0A            differentiable with respect to the output, then a zero%0A            variable is returned. The return value is of same type%0A            as %60wrt%60: a list/tuple or TensorVariable in all cases.%0A    %22%22%22%0A    from theano.tensor import arange%0A    # Check inputs have the right format%0A    assert isinstance(cost, Variable), %5C%0A            %22tensor.hessian expects a Variable as %60cost%60%22%0A    assert cost.ndim == 0, %5C%0A            %22tensor.hessian expects a 0 dimensional variable as %60cost%60%22%0A%0A    using_list = isinstance(wrt, list)%0A    using_tuple = isinstance(wrt, tuple)%0A%0A    if isinstance(wrt, (list, tuple)):%0A        wrt = list(wrt)%0A    else:%0A        wrt = %5Bwrt%5D%0A%0A    expr = grad(cost, wrt, consider_constant=consider_constant,%0A                disconnected_inputs=disconnected_inputs)%0A%0A    # It is possible that the inputs are disconnected from expr,%0A    # even if they are connected to cost.%0A    # This should not be an error.%0A    hess, updates = scan(lambda i, y: grad(%0A                        y%5Bi%5D,%0A                        wrt,%0A                        consider_constant=consider_constant,%0A                        disconnected_inputs='ignore'),%0A                   sequences=arange(len(expr)),%0A                   non_sequences=%5Bexpr%5D)%0A    assert not updates, %5C%0A            (%22Scan has returned a list of updates. This should not %22%0A             %22happen! Report this to theano-users (also include the %22%0A             %22script that generated the error)%22)%0A    return format_as(using_list, using_tuple, stack(hess))%0A%0A

Add missing util.py