# Calculate gradient of g in point x
def gradient_g(x, H, b, c):
- return -b.T + 0.5 * H.dot(x) + 0.5 * H.T.dot(x) + (1.0/3.0) * x.T.dot(_C(x,c))
+ return -b + H.dot(x) + (1.0/3.0) * _C(x,c).dot(x)
# Calculate hessian of g in point x
def hessian_g(x, H, b, c):
\label{eq:func_g}\r
g(\mathbf{x}) := -\mathbf{b}^{T}\mathbf{x}+\frac{1}{2}\mathbf{x}^{T}H\mathbf{x}+\frac{1}{12}\mathbf{x}^{T}C(\mathbf{x})\mathbf{x}\r
\end{equation}\r
-\r
From equation \ref{eq:func_g} we get\r
-\r
-\begin{equation}\r
+\begin{eqnarray}\r
\label{eq:grad_g}\r
-\nabla g(\mathbf{x}) = -\mathbf{b}^{T}+H\mathbf{x}+\frac{1}{3}\mathbf{x}^{T}C(\mathbf{x}),\r
-\end{equation}\r
-\begin{equation}\r
+\nabla g(\mathbf{x}) &=& -\mathbf{b}+H\mathbf{x}+\frac{1}{3}C(\mathbf{x})\mathbf{x} \\\r
\label{eq:hess_g}\r
-\nabla^{2}g(\mathbf{x}) = H+C(\mathbf{x}).\r
-\end{equation}\r
-\r
+\nabla^{2}g(\mathbf{x}) &=& H+C(\mathbf{x}).\r
+\end{eqnarray}\r
The three functions, \ref{eq:func_g}, \ref{eq:grad_g} and \ref{eq:hess_g}, are implemented in the Python code below.\r
\r
\lstinputlisting[language=Python]{bj_function.py}\r