コード例 #1
0
def test_rff_feature_map_derivative2_d():
    X = np.array([[1.]])
    u = np.array([2.])
    omega = np.array([[2.]])
    d = 0
    phi_derivative2 = rff_feature_map_grad2_d(X, omega, u, d)
    phi_derivative2_manual = -rff_feature_map(X, omega, u) * (omega[:, d] ** 2)
    assert_close(phi_derivative2, phi_derivative2_manual)
コード例 #2
0
def test_rff_feature_map_derivative2_d():
    X = np.array([[1.]])
    u = np.array([2.])
    omega = np.array([[2.]])
    d = 0
    phi_derivative2 = rff_feature_map_grad2_d(X, omega, u, d)
    phi_derivative2_manual = -rff_feature_map(X, omega, u) * (omega[:, d]**2)
    assert_close(phi_derivative2, phi_derivative2_manual)
コード例 #3
0
def compute_b(X, omega, u):
    assert len(X.shape) == 2
    m = 1 if np.isscalar(u) else len(u)
    D = X.shape[1]

    projections_sum = np.zeros(m)
    Phi2 = rff_feature_map(X, omega, u)
    for d in range(D):
        projections_sum += np.mean(-Phi2 * (omega[d, :]**2), axis=0)

    return -projections_sum
コード例 #4
0
ファイル: gaussian.py プロジェクト: JHamp/kernel_exp_family
def compute_b(X, omega, u):
    assert len(X.shape) == 2
    m = 1 if np.isscalar(u) else len(u)
    D = X.shape[1]
    
    projections_sum = np.zeros(m)
    Phi2 = rff_feature_map(X, omega, u)
    for d in range(D):
        projections_sum += np.mean(-Phi2 * (omega[d, :] ** 2), axis=0)
        
    return -projections_sum
コード例 #5
0
ファイル: kernels.py プロジェクト: JHamp/kernel_exp_family
def rff_feature_map_grad2_loop(X, omega, u):
    m = 1 if np.isscalar(u) else len(u)
    N = X.shape[0]
    D = X.shape[1]
    
    projections = np.zeros((D, N, m))
    Phi2 = rff_feature_map(X, omega, u)
    for d in range(D):
        projections[d, :, :] = -Phi2
        projections[d, :, :] *= omega[d, :] ** 2
        
    return projections
コード例 #6
0
def rff_feature_map_grad2_loop(X, omega, u):
    m = 1 if np.isscalar(u) else len(u)
    N = X.shape[0]
    D = X.shape[1]
    
    projections = np.zeros((D, N, m))
    Phi2 = rff_feature_map(X, omega, u)
    for d in range(D):
        projections[d, :, :] = -Phi2
        projections[d, :, :] *= omega[d, :] ** 2
        
    return projections
コード例 #7
0
def test_rff_feature_map_single_equals_feature_map():
    N = 10
    D = 20
    m = 3
    X = np.random.randn(N, D)
    omega = np.random.randn(D, m)
    u = np.random.uniform(0, 2 * np.pi, m)
    
    phis = rff_feature_map(X, omega, u)
    
    for i, x in enumerate(X):
        phi = rff_feature_map_single(x, omega, u)
        assert_allclose(phis[i], phi)
コード例 #8
0
def test_rff_feature_map_single_equals_feature_map():
    N = 10
    D = 20
    m = 3
    X = np.random.randn(N, D)
    omega = np.random.randn(D, m)
    u = np.random.uniform(0, 2 * np.pi, m)

    phis = rff_feature_map(X, omega, u)

    for i, x in enumerate(X):
        phi = rff_feature_map_single(x, omega, u)
        assert_allclose(phis[i], phi)
コード例 #9
0
    def log_pdf_multiple(self, X):
        assert_array_shape(X, ndim=2, dims={1: self.D})

        Phi = rff_feature_map(X, self.omega, self.u)
        return np.dot(Phi, self.theta)
コード例 #10
0
ファイル: gaussian.py プロジェクト: JHamp/kernel_exp_family
 def log_pdf_multiple(self, X):
     assert_array_shape(X, ndim=2, dims={1: self.D})
     
     Phi = rff_feature_map(X, self.omega, self.u)
     return np.dot(Phi, self.theta)