def svgd_kernel_gradh(self, h=(- 1), uStat=True):
    (n, d) = self.thetaSubset.shape
    m = self.y.shape[0]
    H = (cdist(self.thetaSubset, self.y) ** 2)
    if (h < 0):
        h = np.median(H)
        h = np.sqrt(((0.5 * h) / np.log((n + 1))))
    Kxy = np.exp((((- H) / (h ** 2)) / 2))
    hGrad = 0
    for yInd in range(m):
        Kxy_cur = Kxy[:, yInd]
        H_cur = H[:, yInd]
        xmy = ((self.thetaSubset - np.tile(self.y[yInd, :], [n, 1])) / (h ** 2))
        Sqxxmy = (self.SqxSubset - xmy)
        part2 = (np.tile(np.array([Kxy_cur]).T, [1, d]) * Sqxxmy)
        part1_1 = (np.tile(np.array([(H_cur / (h ** 3))]).T, [1, d]) * part2)
        part1_2 = (np.tile(np.array([Kxy_cur]).T, [1, d]) * ((2 * xmy) / (h ** 3)))
        part = np.matmul((part1_1 + part1_2), part2.T)
        hGrad = (hGrad + np.sum(np.sum(part, axis=1)))
        if uStat:
            front_u = (((Kxy_cur ** 2) * (H_cur / (h ** 3))) * np.sum((Sqxxmy ** 2), axis=1))
            back_u = np.sum((((2 * xmy) / (h ** 3)) * Sqxxmy), axis=1)
            hGrad = (hGrad - np.sum(((Kxy_cur ** 2) * (front_u + back_u)), axis=0))
    if uStat:
        hGrad = ((hGrad * 2) / ((n * (n - 1)) * m))
    else:
        hGrad = ((hGrad * 2) / ((n ** 2) * m))
    return hGrad
def svgd_kernel_gradh(self, h=(- 1), uStat=True):
    (n, d) = self.thetaSubset.shape
    m = self.y.shape[0]
    H = (cdist(self.thetaSubset, self.y) ** 2)
    if (h < 0):
        h = np.median(H)
        h = np.sqrt(((0.5 * h) / np.log((n + 1))))
    Kxy = np.exp((((- H) / (h ** 2)) / 2))
    hGrad = 0
    for yInd in range(m):
        Kxy_cur = Kxy[:, yInd]
        H_cur = H[:, yInd]
        xmy = ((self.thetaSubset - np.tile(self.y[yInd, :], [n, 1])) / (h ** 2))
        Sqxxmy = (self.SqxSubset - xmy)
        part2 = (np.tile(np.array([Kxy_cur]).T, [1, d]) * Sqxxmy)
        part1_1 = (np.tile(np.array([(H_cur / (h ** 3))]).T, [1, d]) * part2)
        part1_2 = (np.tile(np.array([Kxy_cur]).T, [1, d]) * ((2 * xmy) / (h ** 3)))
        part = np.matmul((part1_1 + part1_2), part2.T)
        hGrad = (hGrad + np.sum(np.sum(part, axis=1)))
        if uStat:
            front_u = (((Kxy_cur ** 2) * (H_cur / (h ** 3))) * np.sum((Sqxxmy ** 2), axis=1))
            back_u = np.sum((((2 * xmy) / (h ** 3)) * Sqxxmy), axis=1)
            hGrad = (hGrad - np.sum(((Kxy_cur ** 2) * (front_u + back_u)), axis=0))
    if uStat:
        hGrad = ((hGrad * 2) / ((n * (n - 1)) * m))
    else:
        hGrad = ((hGrad * 2) / ((n ** 2) * m))
    return hGrad