src.dackar.anomalies.kernel_two_sample_test =========================================== .. py:module:: src.dackar.anomalies.kernel_two_sample_test .. autoapi-nested-parse:: Created on July, 2025 @author: wangc, mandd Attributes ---------- .. autoapisummary:: src.dackar.anomalies.kernel_two_sample_test.logger Functions --------- .. autoapisummary:: src.dackar.anomalies.kernel_two_sample_test.MMD2u src.dackar.anomalies.kernel_two_sample_test.MMD2b src.dackar.anomalies.kernel_two_sample_test.MMD2u_UCB src.dackar.anomalies.kernel_two_sample_test.MMD2b_UCB src.dackar.anomalies.kernel_two_sample_test.compute_null_distribution src.dackar.anomalies.kernel_two_sample_test.compute_null_distribution_given_permutations src.dackar.anomalies.kernel_two_sample_test.kernel_two_sample_test src.dackar.anomalies.kernel_two_sample_test.chebyshevTesting src.dackar.anomalies.kernel_two_sample_test.chebyshevTesting_precomputed_mmd Module Contents --------------- .. py:data:: logger .. py:function:: MMD2u(K, m, n) Method designed to perform MMD^2_u unbiased statistic using U-statistics. :param K: np.array, 2-D matrix :param m: int, size of first vector :param n: int, size of second vector :returns: float, MMD^2_u unbiased statistic using U-statistics :rtype: val .. py:function:: MMD2b(K, m, n) Method designed to perform MMD^2 biased statistics using V-statistics :param K: np.array, 2-D matrix :param m: int, size of first vector :param n: int, size of second vector :returns: float, MMD^2 biased statistics using V-statistics :rtype: out .. py:function:: MMD2u_UCB(K, m, alpha=0.05) Method designed to calculate the uniform convergence bound for MMD2u :param K: np.array, 2-D matrix :param m: int, sample size :param alpha: float, acceptance value for hypothesis testing :returns: float, uniform convergence bound for MMD2u :rtype: ucb .. py:function:: MMD2b_UCB(K, m, alpha=0.05) Method designed to calculate the uniform convergence bound for MMD2b :param K: np.array, 2-D matrix :param m: int, sample size :param alpha: float, acceptance value for hypothesis testing :returns: float, uniform convergence bound for MMD2b :rtype: ucb .. py:function:: compute_null_distribution(K, m, n, iterations=1000, verbose=False, random_state=None, marker_interval=500) Method designed to calculate the bootstrap null-distribution of MMD2u. :param K: np.array, 2-D matrix :param m: int, size of first vector :param n: int, size of second vector :param iterations: int, number of bootstrap iterations :param verbose: bool, flag to provide calculation details :param random_state: np class, numpy random number generator class :param marker_interval: int, interval where calculation details are displayed :returns: np.array, null-distribution of MMD2u :rtype: mmd2u_null .. py:function:: compute_null_distribution_given_permutations(K, m, n, permutation, iterations=None) Method designed to calculate the bootstrap null-distribution of MMD2u given predefined permutations. :param K: np.array, 2-D matrix :param m: int, size of first vector :param n: int, size of second vector :param permutation: np.array, array of permutations :param iterations: int, number of bootstrap iterations :returns: np.array, null-distribution of MMD2u given predefined permutations :rtype: mmd2u_null .. py:function:: kernel_two_sample_test(X, Y, kernel_function='rbf', iterations=2000, verbose=False, random_state=None, alpha=0.05, thin=None, **kwargs) Method designed to calculate MMD^2_u, its null distribution and the p-value of the kernel two-sample test. :param X: np.array, first vector :param Y: np.array, second vector :param kernel_function: string, type of kenerl function. Valid values are: additive_chi2, chi2, linear, poly, polynomial, rbf, laplacian, sigmoid, cosine :param iterations: int, number of iterations :param verbose: bool, flag to provide calculation details :param random_state: np class, numpy random number generator class :param alpha: float, acceptance value for hypothesis testing :param thin: int, sample size for thinning calculation :param \*\*kwargs: dict, dictionary of parameteres that are passed to pairwise_kernels() as kernel parameters. E.g. if kernel_two_sample_test(..., kernel_function='rbf', gamma=0.1), then this will result in getting the kernel through kernel_function(metric='rbf', gamma=0.1). :returns: float, MMD^2_u unbiased statistic using U-statistics mmd2u_null: np.array, null-distribution of MMD2u p_value: float, calculated p-value for hypothesis testing :rtype: mmd2u .. py:function:: chebyshevTesting(X, Y, kernel_function='rbf', iterations=2000, verbose=False, random_state=None, alpha=0.01, **kwargs) Method designed to perform Chebyshev testing using Chebyshev's inequality :param X: np.array, first vector :param Y: np.array, second vector :param kernel_function: string, type of kernel function :param iterations: int, number of bootstrap iterations :param verbose: bool, flag to provide calculation details :param random_state: np class, numpy random number generator class :param alpha: float, acceptance value for hypothesis testing :param \*\*kwargs: dict, dictionary of parameteres that are passed to pairwise_kernels() as kernel parameters. :returns: bool, outcome of Chebyshev testing :rtype: accept .. py:function:: chebyshevTesting_precomputed_mmd(mmd2u, mmd2u_null, alpha=0.01) Method designed to perform MMD Chebyshev testing :param mmd2u: float, MMD^2_u unbiased statistic using U-statistics :param mmd2u_null: np.array, null-distribution of MMD2u :param alpha: float, acceptance value for hypothesis testing :returns: bool, outcome of Chebyshev testing :rtype: accept