diff --git a/src/methods/nca/nca.pl b/src/methods/nca/nca.pl index f083d3adc4a5620e7a1b8ac9d68fdfc4d3d8852f..5e5c22e99cb2dbfdb095141ca688eb16f57af7c1 100644 --- a/src/methods/nca/nca.pl +++ b/src/methods/nca/nca.pl @@ -42,6 +42,17 @@ %% nca(OptimizerType, StepSize, MaxIterations, Tolerance, Shuffle, NumBasis, ArmijoConstant, Wolfe, MaxLine, MinStep, MaxStept, BatchSize, DataList, DataRows, PredictionList, DistanceList, ZCols) :- + StepSize > 0, + MaxIterations >= 0, + Tolerance >= 0, + NumBasis > 0, + ArmijoConstant > 0, + Wolfe > 0, + MaxLineSearchTrials > 0, + MinStep > 0, + MaxStep > 0, + MaxStep >= MinStep, + BatchSize > 0, convert_list_to_float_array(DataList, DataRows, array(Xsize, Xrows, X)), convert_list_to_float_array(PredictionList, array(Ysize, Y)), ncaI(OptimizerType, StepSize, MaxIterations, Tolerance, Shuffle, NumBasis, ArmijoConstant, Wolfe, MaxLine, MinStep, MaxStept, BatchSize, diff --git a/src/methods/nca/nca_test.pl b/src/methods/nca/nca_test.pl index 33e4e0bb567d23d2898e5fb6113a03a1a69d6513..552ae5dd8fe881800c1a41bee135ec4a773fe8a5 100644 --- a/src/methods/nca/nca_test.pl +++ b/src/methods/nca/nca_test.pl @@ -6,39 +6,78 @@ :- use_module(nca). :- use_module('../../helper_files/helper.pl'). -reset_Model :- - initModel(1,0,50,0.0001). - %% -%% TESTING predicate predicate/10 +%% TESTING predicate nca/17 %% -:- begin_tests(predicate). +:- begin_tests(nca). %% 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(nca_Wrong_OptimizerType, [error(domain_error('expectation' , wrongInput), _)]) :- + nca(wrongInput, 0.01, 500000, 0.00001, 1, 5, 0.0001, 0.9, 50, 0.000000001, 100000000, 50, [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,1], _, _). + +test(nca_Negative_StepSize, fail) :- + nca(lbfgs, -0.01, 500000, 0.00001, 1, 5, 0.0001, 0.9, 50, 0.000000001, 100000000, 50, [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,1], _, _). + +test(nca_Negative_MaxIterations, fail) :- + nca(lbfgs, 0.01, -500000, 0.00001, 1, 5, 0.0001, 0.9, 50, 0.000000001, 100000000, 50, [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,1], _, _). + +test(nca_Negative_Tolerance, fail) :- + nca(lbfgs, 0.01, 500000, -0.00001, 1, 5, 0.0001, 0.9, 50, 0.000000001, 100000000, 50, [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,1], _, _). + +test(nca_Negative_NumBasis, fail) :- + nca(lbfgs, 0.01, 500000, 0.00001, 1, -5, 0.0001, 0.9, 50, 0.000000001, 100000000, 50, [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,1], _, _). + +test(nca_Negative_ArmijoConstant, fail) :- + nca(lbfgs, 0.01, 500000, 0.00001, 1, 5, -0.0001, 0.9, 50, 0.000000001, 100000000, 50, [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,1], _, _). + +test(nca_Negative_Wolfe, fail) :- + nca(lbfgs, 0.01, 500000, 0.00001, 1, 5, 0.0001, -0.9, 50, 0.000000001, 100000000, 50, [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,1], _, _). + +test(nca_Negative_MaxLineSearchTrials, fail) :- + nca(lbfgs, 0.01, 500000, 0.00001, 1, 5, 0.0001, 0.9, -50, 0.000000001, 100000000, 50, [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,1], _, _). -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(nca_Negative_MinStep, fail) :- + nca(lbfgs, 0.01, 500000, 0.00001, 1, 5, 0.0001, 0.9, 50, -1, 100000000, 50, [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,1], _, _). + +test(nca_Negative_MaxStep, fail) :- + nca(lbfgs, 0.01, 500000, 0.00001, 1, 5, 0.0001, 0.9, 50, 0.000000001, -1, 50, [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,1], _, _). + +test(nca_Negative_BatchSize, fail) :- + nca(lbfgs, 0.01, 500000, 0.00001, 1, 5, 0.0001, 0.9, 50, 0.000000001, 100000000, -50, [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,1], _, _). + + +test(nca_Too_Short_Label, [error(_,system_error('Error'))]) :- + nca(lbfgs, 0.01, 500000, 0.00001, 1, 5, 0.0001, 0.9, 50, 0.000000001, 100000000, 50, [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], _, _) + +test(nca_Too_Long_Label, [error(_,system_error('Error'))]) :- + nca(lbfgs, 0.01, 500000, 0.00001, 1, 5, 0.0001, 0.9, 50, 0.000000001, 100000000, 50, [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,1,0,1], _, _) + +test(nca_Too_Many_Label_Classes, [error(_,system_error('Error'))]) :- + nca(lbfgs, 0.01, 500000, 0.00001, 1, 5, 0.0001, 0.9, 50, 0.000000001, 100000000, 50, [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,2,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(nca_Normal_Use_SGD) :- + nca(sgd, 0.01, 500000, 0.00001, 1, 5, 0.0001, 0.9, 50, 0.000000001, 100000000, 50, [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,1], DistancesList, _), + print('\nDistances: '), + print(DistancesList). + +test(nca_Normal_Use_LBFGS) :- + nca(lbfgs, 0.01, 500000, 0.00001, 1, 5, 0.0001, 0.9, 50, 0.000000001, 100000000, 50, [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,1], DistancesList, _), + print('\nDistances: '), + print(DistancesList). -test(testDescription4, [true(Error =:= 0.9797958971132711)]) :- - reset_Model_No_Train(perceptron), +test(nca_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). + nca(lbfgs, 0.01, 500000, 0.00001, 1, 5, 0.0001, 0.9, 50, 0.000000001, 100000000, 50, Data, 4, [0,1,0,1,1,0,1,1,1,0], DistancesList, _), + print('\nDistances: '), + print(DistancesList). -:- end_tests(predicate). +:- end_tests(nca). run_nca_tests :- run_tests.