scmkl.projections

  1import numpy as np
  2import numba as nb        
  3
  4
  5@nb.njit(fastmath = True, cache = True)
  6def gaussian_trans(X: np.ndarray, sigma: float, 
  7                   seed_obj: np.random._generator.Generator,
  8                   D: int):
  9    """
 10    Function to sample the projection direction vector W
 11    for calculating gaussian Random Fourier Features (RFF)
 12    for X.
 13
 14    Parameters
 15    ----------
 16    X : np.ndarray
 17        Data matrix X to calculate an approximate kernel of.
 18    
 19    sigma : float
 20        Parameter from data distribution controlling the approximate 
 21        kernel width.
 22
 23    seed_obj : np.random._generator.Generator
 24        Numpy random generator object from `adata.uns['seed_obj']`.
 25
 26    D : int
 27        Parameter determining the number of RFF used to approximate 
 28        the kernel function.
 29
 30    Returns
 31    -------
 32    W : np.ndarray
 33        Vector defining the direction of the projection of RFF.
 34    """
 35    gamma = 1 / ( 2*sigma**2)
 36    sigma_p = 0.5*np.sqrt(2*gamma)
 37
 38    W = seed_obj.normal(0, sigma_p, X.shape[1]*D)
 39    W = W.reshape((X.shape[1]), D)
 40
 41    return W
 42
 43
 44@nb.njit(fastmath = True, cache = True)
 45def laplacian_trans(X: np.ndarray, sigma: float, seed_obj, d: int):
 46    """
 47    Function to sample the projection direction vector W
 48    for calculating laplacian Random Fourier Features (RFF)
 49    for X.
 50
 51    Parameters
 52    ----------
 53    X : np.ndarray
 54        Data matrix X to calculate an approximate kernel of.
 55    
 56    sigma : float
 57        Parameter from data distribution controlling the approximate 
 58        kernel width.
 59
 60    seed_obj : np.random._generator.Generator
 61        Numpy random generator object from `adata.uns['seed_obj']`.
 62
 63    D : int
 64        Parameter determining the number of RFF used to approximate 
 65        the kernel function.
 66
 67    Returns
 68    -------
 69    W : np.ndarray
 70        Vector defining the direction of the projection of RFF.
 71    """
 72    gamma = 1 / (2 * sigma)
 73
 74    W = seed_obj.standard_cauchy(X.shape[1] * d)
 75    W = gamma * W.reshape((X.shape[1], d))
 76
 77    return W
 78
 79
 80@nb.njit(fastmath = True, cache = True)
 81def cauchy_trans(X: np.ndarray, sigma: float, seed_obj, d: int):
 82    """
 83    Function to sample the projection direction vector W
 84    for calculating cauchy Random Fourier Features (RFF)
 85    for X.
 86
 87    Parameters
 88    ----------
 89    X : np.ndarray
 90        Data matrix X to calculate an approximate 
 91        kernel of.
 92    
 93    sigma : float
 94        Parameter from data distribution controlling the approximate 
 95        kernel width.
 96
 97    seed_obj : np.random._generator.Generator
 98        Numpy random generator object from `adata.uns['seed_obj']`.
 99
100    D : int
101        Parameter determining the number of RFF used to approximate 
102        the kernel function.
103
104    Returns
105    -------
106    W : np.ndarray
107        Vector defining the direction of the projection of RFF.
108    """
109    gamma = 1 / (2 * sigma ** 2)
110    b = 0.5 * np.sqrt(gamma)
111
112    W = seed_obj.laplace(0, b, X.shape[1] * d)
113    W = W.reshape((X.shape[1], d))
114
115    return W
@nb.njit(fastmath=True, cache=True)
def gaussian_trans( X: numpy.ndarray, sigma: float, seed_obj: numpy.random._generator.Generator, D: int):
 6@nb.njit(fastmath = True, cache = True)
 7def gaussian_trans(X: np.ndarray, sigma: float, 
 8                   seed_obj: np.random._generator.Generator,
 9                   D: int):
10    """
11    Function to sample the projection direction vector W
12    for calculating gaussian Random Fourier Features (RFF)
13    for X.
14
15    Parameters
16    ----------
17    X : np.ndarray
18        Data matrix X to calculate an approximate kernel of.
19    
20    sigma : float
21        Parameter from data distribution controlling the approximate 
22        kernel width.
23
24    seed_obj : np.random._generator.Generator
25        Numpy random generator object from `adata.uns['seed_obj']`.
26
27    D : int
28        Parameter determining the number of RFF used to approximate 
29        the kernel function.
30
31    Returns
32    -------
33    W : np.ndarray
34        Vector defining the direction of the projection of RFF.
35    """
36    gamma = 1 / ( 2*sigma**2)
37    sigma_p = 0.5*np.sqrt(2*gamma)
38
39    W = seed_obj.normal(0, sigma_p, X.shape[1]*D)
40    W = W.reshape((X.shape[1]), D)
41
42    return W

Function to sample the projection direction vector W for calculating gaussian Random Fourier Features (RFF) for X.

Parameters
  • X (np.ndarray): Data matrix X to calculate an approximate kernel of.
  • sigma (float): Parameter from data distribution controlling the approximate kernel width.
  • seed_obj (np.random._generator.Generator): Numpy random generator object from adata.uns['seed_obj'].
  • D (int): Parameter determining the number of RFF used to approximate the kernel function.
Returns
  • W (np.ndarray): Vector defining the direction of the projection of RFF.
@nb.njit(fastmath=True, cache=True)
def laplacian_trans(X: numpy.ndarray, sigma: float, seed_obj, d: int):
45@nb.njit(fastmath = True, cache = True)
46def laplacian_trans(X: np.ndarray, sigma: float, seed_obj, d: int):
47    """
48    Function to sample the projection direction vector W
49    for calculating laplacian Random Fourier Features (RFF)
50    for X.
51
52    Parameters
53    ----------
54    X : np.ndarray
55        Data matrix X to calculate an approximate kernel of.
56    
57    sigma : float
58        Parameter from data distribution controlling the approximate 
59        kernel width.
60
61    seed_obj : np.random._generator.Generator
62        Numpy random generator object from `adata.uns['seed_obj']`.
63
64    D : int
65        Parameter determining the number of RFF used to approximate 
66        the kernel function.
67
68    Returns
69    -------
70    W : np.ndarray
71        Vector defining the direction of the projection of RFF.
72    """
73    gamma = 1 / (2 * sigma)
74
75    W = seed_obj.standard_cauchy(X.shape[1] * d)
76    W = gamma * W.reshape((X.shape[1], d))
77
78    return W

Function to sample the projection direction vector W for calculating laplacian Random Fourier Features (RFF) for X.

Parameters
  • X (np.ndarray): Data matrix X to calculate an approximate kernel of.
  • sigma (float): Parameter from data distribution controlling the approximate kernel width.
  • seed_obj (np.random._generator.Generator): Numpy random generator object from adata.uns['seed_obj'].
  • D (int): Parameter determining the number of RFF used to approximate the kernel function.
Returns
  • W (np.ndarray): Vector defining the direction of the projection of RFF.
@nb.njit(fastmath=True, cache=True)
def cauchy_trans(X: numpy.ndarray, sigma: float, seed_obj, d: int):
 81@nb.njit(fastmath = True, cache = True)
 82def cauchy_trans(X: np.ndarray, sigma: float, seed_obj, d: int):
 83    """
 84    Function to sample the projection direction vector W
 85    for calculating cauchy Random Fourier Features (RFF)
 86    for X.
 87
 88    Parameters
 89    ----------
 90    X : np.ndarray
 91        Data matrix X to calculate an approximate 
 92        kernel of.
 93    
 94    sigma : float
 95        Parameter from data distribution controlling the approximate 
 96        kernel width.
 97
 98    seed_obj : np.random._generator.Generator
 99        Numpy random generator object from `adata.uns['seed_obj']`.
100
101    D : int
102        Parameter determining the number of RFF used to approximate 
103        the kernel function.
104
105    Returns
106    -------
107    W : np.ndarray
108        Vector defining the direction of the projection of RFF.
109    """
110    gamma = 1 / (2 * sigma ** 2)
111    b = 0.5 * np.sqrt(gamma)
112
113    W = seed_obj.laplace(0, b, X.shape[1] * d)
114    W = W.reshape((X.shape[1], d))
115
116    return W

Function to sample the projection direction vector W for calculating cauchy Random Fourier Features (RFF) for X.

Parameters
  • X (np.ndarray): Data matrix X to calculate an approximate kernel of.
  • sigma (float): Parameter from data distribution controlling the approximate kernel width.
  • seed_obj (np.random._generator.Generator): Numpy random generator object from adata.uns['seed_obj'].
  • D (int): Parameter determining the number of RFF used to approximate the kernel function.
Returns
  • W (np.ndarray): Vector defining the direction of the projection of RFF.