def non_negativity_decomposition_on_coefficients_test(): X = np.random.rand(100, 100)-100 estimator = DictionaryLearning(k=5, non_negativity="coeff") estimator.fit(X) C, D = estimator.decomposition() assert np.min(C) >= 0 assert np.min(D) < 0
def normalization_test(): X = np.random.rand(100, 100)-100 estimator = DictionaryLearning(k=10, dict_normalization=1) estimator.fit(X) C, D = estimator.decomposition() for i in range(D.shape[0]): np.testing.assert_approx_equal(np.linalg.norm(D[0, :]), 1)
def right_number_of_atoms_test(): X = np.random.rand(100, 100) estimator = DictionaryLearning(k=10) estimator.fit(X) C, D = estimator.decomposition() assert C.shape[1] == 10 assert D.shape[0] == 10
def non_negativity_decomposition_on_both_test(): X = np.abs(np.random.rand(100, 100)) estimator = DictionaryLearning(k=5, non_negativity="both") estimator.fit(X) C, D = estimator.decomposition() assert np.min(C) >= 0 assert np.min(D) >= 0
def wrong_range2_test(): X, _, _ = synthetic_data_negative() estimator = DictionaryLearning(k=5, coeff_penalty=L1Penalty(1), dict_penalty=(L1Penalty(2)), non_negativity="coeff") tune_parameters_DL(X, estimator, analysis=1, distributed=0, dict_penalty_range=(-1, 1, 5), coeff_penalty_range=(-1, 1, 5))
def wrong_penalty_type_coeff_test(): X = np.random.rand(100,100) estimator = DictionaryLearning(k=5, coeff_penalty="") estimator.fit(X)
def non_negative_parameter_but_negative_matrix_test(): X = np.random.rand(100, 100) - 50 estimator = DictionaryLearning(k=5, non_negativity="both") estimator.fit(X)
def non_negative_parameter_test(): X = np.random.rand(100, 100) estimator = DictionaryLearning(k=5, non_negativity="not_considered") estimator.fit(X)
def negative_atoms_test(): X = np.random.rand(100,100) estimator = DictionaryLearning(k=-1, dict_penalty=None) estimator.fit(X)