def checkgrad(self, target_param=None, verbose=False, step=<NUM_LIT>, tolerance=<NUM_LIT>, block_indices=None, plot=False, super_plot=False):
try:<EOL><INDENT>import numdifftools as nd<EOL><DEDENT>except:<EOL><INDENT>raise ImportError("<STR_LIT>")<EOL><DEDENT>if target_param:<EOL><INDENT>raise NotImplementedError('<STR_LIT>')<EOL><DEDENT>current_index = <NUM_LIT:0><EOL>for name, n_shape in zip(self.names, self.shapes):<EOL><INDENT>current_size = numpy.prod(n_shape)<EOL>x = self.optimizer_array.copy()<EOL>x = x[current_index:current_index + current_size].reshape(n_shape)<EOL>analytic_hess = self._ddf(x)<EOL>numeric_hess_partial = nd.Jacobian(self._df, vectorized=True)<EOL>numeric_hess = numeric_hess_partial(x)<EOL>print("<STR_LIT>")<EOL>if analytic_hess.dtype is np.dtype('<STR_LIT:object>'):<EOL><INDENT>blocksizes, pagesizes = get_block_shapes_3d(analytic_hess)<EOL>real_block_size = np.sum(blocksizes)<EOL>numeric_hess = numeric_hess.reshape(real_block_size, real_block_size, pagesizes)<EOL><DEDENT>else:<EOL><INDENT>numeric_hess = numeric_hess.reshape(*analytic_hess.shape)<EOL><DEDENT>check_passed = [False]*numeric_hess.shape[<NUM_LIT:2>]<EOL>for block_ind in range(numeric_hess.shape[<NUM_LIT:2>]):<EOL><INDENT>p = True if (plot and block_ind == numeric_hess.shape[<NUM_LIT:2>]-<NUM_LIT:1>) or super_plot else False<EOL>if verbose:<EOL><INDENT>print("<STR_LIT>".format(block_ind))<EOL><DEDENT>check_passed[block_ind] = self.checkgrad_block(analytic_hess[:,:,block_ind], numeric_hess[:,:,block_ind], verbose=verbose, step=step, tolerance=tolerance, block_indices=block_indices, plot=p)<EOL><DEDENT>current_index += current_size<EOL><DEDENT>return np.all(check_passed)<EOL>
Gradient checker that just checks each hessian individually

super_plot will plot the hessian wrt every parameter, plot will just do the first one