Skip to content
Snippets Groups Projects
Commit ec82fd32 authored by Dean Samuel Schmitz's avatar Dean Samuel Schmitz
Browse files

Adding nca tests

parent 9a2bcf4d
Branches
Tags
No related merge requests found
...@@ -42,6 +42,17 @@ ...@@ -42,6 +42,17 @@
%% %%
nca(OptimizerType, StepSize, MaxIterations, Tolerance, Shuffle, NumBasis, ArmijoConstant, Wolfe, MaxLine, MinStep, MaxStept, BatchSize, nca(OptimizerType, StepSize, MaxIterations, Tolerance, Shuffle, NumBasis, ArmijoConstant, Wolfe, MaxLine, MinStep, MaxStept, BatchSize,
DataList, DataRows, PredictionList, DistanceList, ZCols) :- 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(DataList, DataRows, array(Xsize, Xrows, X)),
convert_list_to_float_array(PredictionList, array(Ysize, Y)), convert_list_to_float_array(PredictionList, array(Ysize, Y)),
ncaI(OptimizerType, StepSize, MaxIterations, Tolerance, Shuffle, NumBasis, ArmijoConstant, Wolfe, MaxLine, MinStep, MaxStept, BatchSize, ncaI(OptimizerType, StepSize, MaxIterations, Tolerance, Shuffle, NumBasis, ArmijoConstant, Wolfe, MaxLine, MinStep, MaxStept, BatchSize,
......
...@@ -6,39 +6,78 @@ ...@@ -6,39 +6,78 @@
:- use_module(nca). :- use_module(nca).
:- 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 nca/17
%% %%
:- begin_tests(predicate). :- begin_tests(nca).
%% Failure Tests %% Failure Tests
test(testDescription, [error(domain_error('expectation' , culprit), _)]) :- test(nca_Wrong_OptimizerType, [error(domain_error('expectation' , wrongInput), _)]) :-
reset_Model_No_Train(perceptron), 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], _, _).
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_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!'))]) :- test(nca_Negative_MinStep, fail) :-
reset_Model_No_Train(perceptron), 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], _, _).
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_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 %% Successful Tests
test(testDescription3, [true(Error =:= 1)]) :- test(nca_Normal_Use_SGD) :-
reset_Model_No_Train(perceptron), 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, _),
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('\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)]) :- test(nca_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). 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_nca_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