def test_lipschitz_constant_loss_mse(): rng = check_random_state(42) X, _, w, mask = _make_data(rng=rng, masked=True) l1_ratio = 1. alpha = .1 mask = np.ones(X.shape[1]).astype(bool) grad_weight = alpha * X.shape[0] * (1. - l1_ratio) a = _squared_loss_derivative_lipschitz_constant(X, mask, grad_weight) b = spectral_norm_squared(X) np.testing.assert_almost_equal(a, b)
def test_lipschitz_constant_loss_mse(): rng = check_random_state(42) X, _, w, mask = _make_data(rng=rng, masked=True) l1_ratio = 1. alpha = .1 mask = np.ones(X.shape[1]).astype(np.bool) grad_weight = alpha * X.shape[0] * (1. - l1_ratio) a = _squared_loss_derivative_lipschitz_constant(X, mask, grad_weight) b = spectral_norm_squared(X) np.testing.assert_almost_equal(a, b)
def test_squared_loss_lipschitz(n_samples=4, n_features=2, random_state=42): rng = np.random.RandomState(random_state) for scaling in np.logspace(-3, 3, num=7): X = rng.randn(n_samples, n_features) * scaling y = rng.randn(n_samples) n_features = X.shape[1] L = spectral_norm_squared(X) _check_lipschitz_continuous(lambda w: _squared_loss_grad(X, y, w), n_features, L)
def test_squared_loss_lipschitz(n_samples=4, n_features=2, random_state=42): rng = np.random.RandomState(random_state) for scaling in np.logspace(-3, 3, num=7): X = rng.randn(n_samples, n_features) * scaling y = rng.randn(n_samples) n_features = X.shape[1] L = spectral_norm_squared(X) _check_lipschitz_continuous(lambda w: _squared_loss_grad( X, y, w), n_features, L)