Skip to content
Snippets Groups Projects
Commit 28c7c521 authored by Jakhes's avatar Jakhes
Browse files

Adding nmf tests

parent 64079773
No related branches found
No related tags found
No related merge requests found
...@@ -32,6 +32,9 @@ ...@@ -32,6 +32,9 @@
%% Initilizes the nmf model and applies it to the given data. %% Initilizes the nmf model and applies it to the given data.
%% %%
nmf(UpdateRule, MaxIterations, MinResidue, DataList, DataRows, Rank, WList, YCols, HList, ZCols) :- 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)), 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), nmfI(UpdateRule, MaxIterations, MinResidue, X, Xsize, Xrows, Rank, Y, YCols, YRows, Z, ZCols, ZRows),
convert_float_array_to_2d_list(Y, YCols, YRows, WList), convert_float_array_to_2d_list(Y, YCols, YRows, WList),
......
...@@ -6,38 +6,68 @@ ...@@ -6,38 +6,68 @@
:- use_module(nmf). :- use_module(nmf).
:- use_module('../../helper_files/helper.pl'). :- 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 %% Failure Tests
test(testDescription, [error(domain_error('expectation' , culprit), _)]) :- test(nmf_Wrong_UpdateRule_Input, [error(domain_error('expectation' , wrongInput), _)]) :-
reset_Model_No_Train(perceptron), 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, _, _, _, _).
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_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!'))]) :- test(nmf_Negative_Rank, fail) :-
reset_Model_No_Train(perceptron), 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, _, _, _, _).
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, _).
%% Successful Tests %% Successful Tests
test(testDescription3, [true(Error =:= 1)]) :- test(nmf_Multdist_High_Rank) :-
reset_Model_No_Train(perceptron), 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, _),
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). 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)]) :- test(nmf_CSV_Input) :-
reset_Model_No_Train(perceptron),
open('src/data_csv/iris2.csv', read, File), open('src/data_csv/iris2.csv', read, File),
take_csv_row(File, skipFirstRow,10, Data), 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_nmf_tests :-
run_tests. run_tests.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment