def get_rand_Japprox(s, params, num_inds=<NUM_LIT:1000>, include_cost=False, **kwargs):
start_time = time.time()<EOL>tot_pix = s.residuals.size<EOL>if num_inds < tot_pix:<EOL><INDENT>inds = np.random.choice(tot_pix, size=num_inds, replace=False)<EOL>slicer = None<EOL>return_inds = np.sort(inds)<EOL><DEDENT>else:<EOL><INDENT>inds = None<EOL>return_inds = slice(<NUM_LIT:0>, None)<EOL>slicer = [slice(<NUM_LIT:0>, None)]*len(s.residuals.shape)<EOL><DEDENT>if include_cost:<EOL><INDENT>Jact, ge = s.gradmodel_e(params=params, inds=inds, slicer=slicer,flat=False,<EOL>**kwargs)<EOL>Jact *= -<NUM_LIT:1><EOL>J = [Jact, ge]<EOL><DEDENT>else:<EOL><INDENT>J = -s.gradmodel(params=params, inds=inds, slicer=slicer, flat=False,<EOL>**kwargs)<EOL><DEDENT>CLOG.debug('<STR_LIT>' % (time.time()-start_time))<EOL>return J, return_inds<EOL>
Calculates a random approximation to J by returning J only at a
set of random pixel/voxel locations.

Parameters
----------
    s : :class:`peri.states.State`
        The state to calculate J for.
    params : List
        The list of parameter names to calculate the gradient of.
    num_inds : Int, optional.
        The number of pix/voxels at which to calculate the random
        approximation to J. Default is 1000.
    include_cost : Bool, optional
        Set to True to append a finite-difference measure of the full
        cost gradient onto the returned J.

Other Parameters
----------------
    All kwargs parameters get passed to s.gradmodel only.

Returns
-------
    J : numpy.ndarray
        [d, num_inds] array of J, at the given indices.

    return_inds : numpy.ndarray or slice
        [num_inds] element array or slice(0, None) of the model
        indices at which J was evaluated.