예제 #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
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
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
 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)