Skip to content
Snippets Groups Projects
Select Git revision
  • ec82fd32d33160a5ef9d0f2737f8a82336f1408b
  • main default protected
2 results

nca_test.pl

Blame
  • user avatar
    Dean Samuel Schmitz authored
    ec82fd32
    History
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    nca_test.pl 4.12 KiB
    
    :- module(nca_tests, [run_nca_tests/0]).
    
    :- use_module(library(plunit)).
    
    :- use_module(nca).
    :- use_module('../../helper_files/helper.pl').
    
    
    %%
    %% TESTING predicate nca/17
    %%
    :- begin_tests(nca).      
    
    %% Failure Tests
                                                
    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(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(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(nca_CSV_Input) :-
            open('src/data_csv/iris2.csv', read, File),
            take_csv_row(File, skipFirstRow,10, Data),
            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(nca).
    
    run_nca_tests :-
            run_tests.