Esempio n. 1
0
def test_logistic_gradient_at_simple_points():
    # Tests gradient of logistic data loss function in points near to zero.
    # This is a not so hard test, just for detecting big errors
    X, y, w, mask = create_graph_net_simulation_data(n_samples=10, size=4)
    grad_weight = 1
    # Add the intercept
    w = np.append(w, 0)
    func = lambda w: _logistic_data_loss_and_spatial_grad(
        X, y, w, mask, grad_weight)
    func_grad = lambda w: _logistic_data_loss_and_spatial_grad_derivative(
        X, y, w, mask, grad_weight)
    for i in range(0, w.size, 7):
        point = np.zeros(*w.shape)
        point[i] = 1
        assert_almost_equal(sp.optimize.check_grad(func, func_grad, point),
                            0, decimal=3)
Esempio n. 2
0
def test_logistic_gradient_at_simple_points():
    # Tests gradient of logistic data loss function in points near to zero.
    # This is a not so hard test, just for detecting big errors
    X, y, w, mask = create_graph_net_simulation_data(n_samples=10, size=4)
    grad_weight = 1
    # Add the intercept
    w = np.append(w, 0)
    func = lambda w: _logistic_data_loss_and_spatial_grad(
        X, y, w, mask, grad_weight)
    func_grad = lambda w: _logistic_data_loss_and_spatial_grad_derivative(
        X, y, w, mask, grad_weight)
    for i in range(0, w.size, 7):
        point = np.zeros(*w.shape)
        point[i] = 1
        assert_almost_equal(sp.optimize.check_grad(func, func_grad, point),
                            0, decimal=3)