diff --git a/src/methods/nmf/nmf.pl b/src/methods/nmf/nmf.pl index eb25a4efb242148db2c661024c174b9540ce9f39..339cfb2e68a64d39d52e08e857ac9816edba729d 100644 --- a/src/methods/nmf/nmf.pl +++ b/src/methods/nmf/nmf.pl @@ -32,6 +32,9 @@ %% Initilizes the nmf model and applies it to the given data. %% nmf(UpdateRule, MaxIterations, MinResidue, DataList, DataRows, Rank, WList, YCols, HList, ZCols) :- + MaxIterations >= 0, + MinResidue >= 0, + Rank > 0, convert_list_to_float_array(DataList, DataRows, array(Xsize, Xrows, X)), nmfI(UpdateRule, MaxIterations, MinResidue, X, Xsize, Xrows, Rank, Y, YCols, YRows, Z, ZCols, ZRows), convert_float_array_to_2d_list(Y, YCols, YRows, WList), diff --git a/src/methods/nmf/nmf_test.pl b/src/methods/nmf/nmf_test.pl index 4b132f776c6f97d6c6e260bb4cc8b279adf18bb8..25a2c39e80c383120014e200278c3535a3a6cdeb 100644 --- a/src/methods/nmf/nmf_test.pl +++ b/src/methods/nmf/nmf_test.pl @@ -6,38 +6,68 @@ :- use_module(nmf). :- use_module('../../helper_files/helper.pl'). -reset_Model :- - initModel(1,0,50,0.0001). + %% -%% TESTING predicate predicate/10 +%% TESTING predicate nmf/10 %% -:- begin_tests(predicate). +:- begin_tests(nmf). %% Failure Tests -test(testDescription, [error(domain_error('expectation' , culprit), _)]) :- - reset_Model_No_Train(perceptron), - train([5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3, [0,0,0,0], 2, culprit, 50, 0.0001, _). +test(nmf_Wrong_UpdateRule_Input, [error(domain_error('expectation' , wrongInput), _)]) :- + nmf(wrongInput, 10000, 0.00001, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3, 3, _, _, _, _). + +test(nmf_Negative_MaxIterations, fail) :- + nmf(multdist, -10000, 0.00001, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3, 3, _, _, _, _). + +test(nmf_Negative_MinResidue, fail) :- + nmf(multdist, 10000, -0.00001, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3, 3, _, _, _, _). -test(testDescription2, [error(_,system_error('The values of the Label have to start at 0 and be >= 0 and < the given numClass!'))]) :- - reset_Model_No_Train(perceptron), - train([5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3, [0,1,0,2], 2, perceptron, 50, 0.0001, _). +test(nmf_Negative_Rank, fail) :- + nmf(multdist, 10000, 0.00001, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3, -3, _, _, _, _). %% Successful Tests -test(testDescription3, [true(Error =:= 1)]) :- - reset_Model_No_Train(perceptron), - train([5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3, [0,0,0,0], 2, perceptron, 50, 0.0001, Error). +test(nmf_Multdist_High_Rank) :- + nmf(multdist, 10000, 0.00001, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3, 6, W, _, H, _), + print('\nW: '), + print(W), + print('\nH: '), + print(H). + +test(nmf_Normal_Use_Multdist) :- + nmf(multdist, 10000, 0.00001, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3, 3, W, _, H, _), + print('\nW: '), + print(W), + print('\nH: '), + print(H). + +test(nmf_Normal_Use_Multdiv) :- + nmf(multdiv, 10000, 0.00001, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3, 3, W, _, H, _), + print('\nW: '), + print(W), + print('\nH: '), + print(H). + +test(nmf_Normal_Use_ALS) :- + nmf(als, 10000, 0.00001, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 3, 3, W, _, H, _), + print('\nW: '), + print(W), + print('\nH: '), + print(H). -test(testDescription4, [true(Error =:= 0.9797958971132711)]) :- - reset_Model_No_Train(perceptron), +test(nmf_CSV_Input) :- open('src/data_csv/iris2.csv', read, File), take_csv_row(File, skipFirstRow,10, Data), - train(Data, 4, [0,1,0,1,1,0,1,1,1,0], 2, perceptron, 50, 0.0001, Error). + nmf(multdist, 100, 0.00042, Data, 4, 2, W, _, H, _), + print('\nW: '), + print(W), + print('\nH: '), + print(H). -:- end_tests(predicate). +:- end_tests(nmf). run_nmf_tests :- run_tests.