Skip to content
Snippets Groups Projects
Commit 48d3f4a5 authored by Jakhes's avatar Jakhes
Browse files

Updating Tests

parent 52e5272b
Branches
No related tags found
No related merge requests found
...@@ -34,13 +34,14 @@ test(linear_SVM_InitModelWithTrain_Negative_Delta, fail) :- ...@@ -34,13 +34,14 @@ test(linear_SVM_InitModelWithTrain_Negative_Delta, fail) :-
test(linear_SVM_InitModelWithTrain_Wrong_Optimizer_Input, [error(domain_error('The given Optimizer is unkown!' , wrongInput), _)]) :- test(linear_SVM_InitModelWithTrain_Wrong_Optimizer_Input, [error(domain_error('The given Optimizer is unkown!' , wrongInput), _)]) :-
linear_SVM_initModelWithTrain([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], 2, 0.0001, 1.0, 0, wrongInput). linear_SVM_initModelWithTrain([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], 2, 0.0001, 1.0, 0, wrongInput).
test(linear_SVM_InitModelWithTrain_Too_Few_Labels, [error(_,system_error('Error'))]) :- test(linear_SVM_InitModelWithTrain_Too_Few_Labels, [error(_,system_error('The number of data points does not match the number of labels!'))]) :-
linear_SVM_initModelWithTrain([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, 0.0001, 1.0, 0, lbfgs). linear_SVM_initModelWithTrain([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, 0.0001, 1.0, 0, lbfgs).
test(linear_SVM_InitModelWithTrain_Too_Many_Labels, [error(_,system_error('Error'))]) :- test(linear_SVM_InitModelWithTrain_Too_Many_Labels, [error(_,system_error('The number of data points does not match the number of labels!'))]) :-
linear_SVM_initModelWithTrain([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], 2, 0.0001, 1.0, 0, lbfgs). linear_SVM_initModelWithTrain([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], 2, 0.0001, 1.0, 0, lbfgs).
test(linear_SVM_InitModelWithTrain_Too_Many_LabelClasses, [error(_,system_error('Error'))]) :- %% doesnt cause error
test(linear_SVM_InitModelWithTrain_Too_Many_LabelClasses) :-
linear_SVM_initModelWithTrain([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], 2, 0.0001, 1.0, 0, lbfgs). linear_SVM_initModelWithTrain([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], 2, 0.0001, 1.0, 0, lbfgs).
...@@ -97,11 +98,11 @@ test(linear_SVM_InitModelNoTrain_Alternative) :- ...@@ -97,11 +98,11 @@ test(linear_SVM_InitModelNoTrain_Alternative) :-
%% Failure Tests %% Failure Tests
test(linear_SVM_Classify_Before_Train, [error(_,system_error('Error'))]) :- test(linear_SVM_Classify_Before_Train, [error(_,system_error('The Model is not trained!'))]) :-
reset_Model_NoTrain, reset_Model_NoTrain,
linear_SVM_classify([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, _, _, _). linear_SVM_classify([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, _, _, _).
test(linear_SVM_Classify_Diffrent_Dims_Than_Train, [error(_,system_error('Error'))]) :- test(linear_SVM_Classify_Diffrent_Dims_Than_Train, [error(_,system_error('The given Datapoints Dimension is != the trained Datapoints Dimension!'))]) :-
reset_Model_WithTrain, reset_Model_WithTrain,
linear_SVM_classify([5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 4, _, _, _). linear_SVM_classify([5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 4, _, _, _).
...@@ -145,11 +146,11 @@ test(linear_SVM_Classify_CSV_Input) :- ...@@ -145,11 +146,11 @@ test(linear_SVM_Classify_CSV_Input) :-
%% Failure Tests %% Failure Tests
test(linear_SVM_ClassifyPoint_Before_Train, [error(_,system_error('Error'))]) :- test(linear_SVM_ClassifyPoint_Before_Train, [error(_,system_error('The Model is not trained!'))]) :-
reset_Model_NoTrain, reset_Model_NoTrain,
linear_SVM_classifyPoint([5.1,3.5,1.4], _). linear_SVM_classifyPoint([5.1,3.5,1.4], _).
test(linear_SVM_ClassifyPoint_Diffrent_Dims_Than_Train, [error(_,system_error('Error'))]) :- test(linear_SVM_ClassifyPoint_Diffrent_Dims_Than_Train, [error(_,system_error('The given Datapoint Dimension is != the trained Datapoints Dimension!'))]) :-
reset_Model_WithTrain, reset_Model_WithTrain,
linear_SVM_classifyPoint([5.1,3.5,1.4,4.9], _). linear_SVM_classifyPoint([5.1,3.5,1.4,4.9], _).
...@@ -187,23 +188,24 @@ test(linear_SVM_ClassifyPoint_CSV_Input) :- ...@@ -187,23 +188,24 @@ test(linear_SVM_ClassifyPoint_CSV_Input) :-
%% Failure Tests %% Failure Tests
test(linear_SVM_ComputeAccuracy_Before_Train, [error(_,system_error('Error'))]) :- test(linear_SVM_ComputeAccuracy_Before_Train, [error(_,system_error('The Model is not trained!'))]) :-
reset_Model_NoTrain, reset_Model_NoTrain,
linear_SVM_computeAccuracy([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], _). linear_SVM_computeAccuracy([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(linear_SVM_ComputeAccuracy_Too_Few_Labels, [error(_,system_error('Error'))]) :- test(linear_SVM_ComputeAccuracy_Too_Few_Labels, [error(_,system_error('The number of data points does not match the number of labels!'))]) :-
reset_Model_WithTrain, reset_Model_WithTrain,
linear_SVM_computeAccuracy([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], _). linear_SVM_computeAccuracy([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(linear_SVM_ComputeAccuracy_Too_Many_Labels, [error(_,system_error('Error'))]) :- test(linear_SVM_ComputeAccuracy_Too_Many_Labels, [error(_,system_error('The number of data points does not match the number of labels!'))]) :-
reset_Model_WithTrain, reset_Model_WithTrain,
linear_SVM_computeAccuracy([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], _). linear_SVM_computeAccuracy([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(linear_SVM_ComputeAccuracy_Too_Many_LabelClasses, [error(_,system_error('Error'))]) :- %% doesnt cause error
test(linear_SVM_ComputeAccuracy_Too_Many_LabelClasses) :-
reset_Model_WithTrain, reset_Model_WithTrain,
linear_SVM_computeAccuracy([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], _). linear_SVM_computeAccuracy([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], _).
test(linear_SVM_ComputeAccuracy_Wrong_Data_Dims, [error(_,system_error('Error'))]) :- test(linear_SVM_ComputeAccuracy_Wrong_Data_Dims, [error(_,system_error('The given Datapoints Dimension is != the trained Datapoints Dimension!'))]) :-
reset_Model_WithTrain, reset_Model_WithTrain,
linear_SVM_computeAccuracy([5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 4, [0,1,0], _). linear_SVM_computeAccuracy([5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 4, [0,1,0], _).
...@@ -225,7 +227,7 @@ test(linear_SVM_ComputeAccuracy_Normal_Use_PSGD) :- ...@@ -225,7 +227,7 @@ test(linear_SVM_ComputeAccuracy_Normal_Use_PSGD) :-
test(linear_SVM_ComputeAccuracy_CSV_Input) :- test(linear_SVM_ComputeAccuracy_CSV_Input) :-
linear_SVM_initModelWithTrain([5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 4, [0,1,0], 2, 0.0001, 2.0, 1, lbfgs), linear_SVM_initModelWithTrain([5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 4, [0,1,0], 2, 0.0001, 2.0, 1, lbfgs),
open('src/data_csv/iris2.csv', read, File), open('src/data_csv/iris2.csv', read, File),
take_csv_row(File, skipFirstRow,1, Data), take_csv_row(File, skipFirstRow,10, Data),
linear_SVM_computeAccuracy(Data, 4, [0,1,0,1,1,0,1,1,1,0], Accuracy), linear_SVM_computeAccuracy(Data, 4, [0,1,0,1,1,0,1,1,1,0], Accuracy),
print('\nAccuracy: '), print('\nAccuracy: '),
print(Accuracy). print(Accuracy).
...@@ -249,15 +251,16 @@ test(linear_SVM_Train_Wrong_Optimizer_Input, [error(domain_error('The given Opti ...@@ -249,15 +251,16 @@ test(linear_SVM_Train_Wrong_Optimizer_Input, [error(domain_error('The given Opti
reset_Model_NoTrain, reset_Model_NoTrain,
linear_SVM_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,1], 2, wrongInput, _). linear_SVM_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,1], 2, wrongInput, _).
test(linear_SVM_Train_Too_Few_Labels, [error(_,system_error('Error'))]) :- test(linear_SVM_Train_Too_Few_Labels, [error(_,system_error('The number of data points does not match the number of labels!'))]) :-
reset_Model_NoTrain, reset_Model_NoTrain,
linear_SVM_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], 2, lbfgs, _). linear_SVM_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], 2, lbfgs, _).
test(linear_SVM_Train_Too_Many_Labels, [error(_,system_error('Error'))]) :- test(linear_SVM_Train_Too_Many_Labels, [error(_,system_error('The number of data points does not match the number of labels!'))]) :-
reset_Model_NoTrain, reset_Model_NoTrain,
linear_SVM_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,1,0,1], 2, lbfgs, _). linear_SVM_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,1,0,1], 2, lbfgs, _).
test(linear_SVM_Train_Too_Many_LabelClasses, [error(_,system_error('Error'))]) :- %% doesnt cause error
test(linear_SVM_Train_Too_Many_LabelClasses) :-
reset_Model_NoTrain, reset_Model_NoTrain,
linear_SVM_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,2,3], 2, lbfgs, _). linear_SVM_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,2,3], 2, lbfgs, _).
......
...@@ -14,13 +14,13 @@ ...@@ -14,13 +14,13 @@
%% Failure Tests %% Failure Tests
test(lmnn_Wrong_Optimizer_Input, [error(domain_error('expectation' , wrongInput), _)]) :- test(lmnn_Wrong_Optimizer_Input, [error(domain_error('The given Optimizer is unkown!' , wrongInput), _)]) :-
lmnn(wrongInput, [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], 2, 0.5, 0.01, 50, 100000, 0.000001, 0, 0, 50, 1, 0, _, _). lmnn(wrongInput, [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], 2, 0.5, 0.01, 50, 100000, 0.000001, 0, 0, 50, 1, 0, _, _).
test(lmnn_Negative_K, fail) :- test(lmnn_Negative_K, fail) :-
lmnn(lbfgs, [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], -2, 0.5, 0.01, 50, 100000, 0.000001, 0, 0, 50, 1, 0, _, _). lmnn(lbfgs, [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], -2, 0.5, 0.01, 50, 100000, 0.000001, 0, 0, 50, 1, 0, _, _).
test(lmnn_Too_Many_K, fail) :- test(lmnn_Too_Many_K, error(_, system_error('fatal error; see Log::Fatal output'))) :-
lmnn(lbfgs, [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], 10, 0.5, 0.01, 50, 100000, 0.000001, 0, 0, 50, 1, 0, _, _). lmnn(lbfgs, [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], 10, 0.5, 0.01, 50, 100000, 0.000001, 0, 0, 50, 1, 0, _, _).
test(lmnn_Negative_Regularization, fail) :- test(lmnn_Negative_Regularization, fail) :-
...@@ -48,43 +48,44 @@ test(lmnn_Negative_Rank, fail) :- ...@@ -48,43 +48,44 @@ test(lmnn_Negative_Rank, fail) :-
lmnn(lbfgs, [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], 2, 0.5, 0.01, 50, 100000, 0.000001, 0, 0, 50, 1, -1, _, _). lmnn(lbfgs, [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], 2, 0.5, 0.01, 50, 100000, 0.000001, 0, 0, 50, 1, -1, _, _).
test(lmnn_Negative_Too_Few_Labels, [error(_, system_error('Error'))]) :- test(lmnn_Negative_Too_Few_Labels, [error(_, system_error('The number of data points does not match the number of labels!'))]) :-
lmnn(lbfgs, [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, 0.5, 0.01, 50, 100000, 0.000001, 0, 0, 50, 1, 0, _, _). lmnn(lbfgs, [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, 0.5, 0.01, 50, 100000, 0.000001, 0, 0, 50, 1, 0, _, _).
test(lmnn_Negative_Too_Many_Labels, [error(_, system_error('Error'))]) :- test(lmnn_Negative_Too_Many_Labels, [error(_, system_error('The number of data points does not match the number of labels!'))]) :-
lmnn(lbfgs, [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], 2, 0.5, 0.01, 50, 100000, 0.000001, 0, 0, 50, 1, 0, _, _). lmnn(lbfgs, [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], 2, 0.5, 0.01, 50, 100000, 0.000001, 0, 0, 50, 1, 0, _, _).
test(lmnn_Negative_Too_Many_LabelClasses, [error(_, system_error('Error'))]) :- test(lmnn_Negative_Too_Many_LabelClasses, [error(_, system_error('fatal error; see Log::Fatal output'))]) :-
lmnn(lbfgs, [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], 2, 0.5, 0.01, 50, 100000, 0.000001, 0, 0, 50, 1, 0, _, _). lmnn(lbfgs, [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], 2, 0.5, 0.01, 50, 100000, 0.000001, 0, 0, 50, 1, 0, _, _).
%% Successful Tests %% Successful Tests
%% k need to be < than the amount of elements per label class
test(lmnn_Normal_Use_Amsgrad) :- test(lmnn_Normal_Use_Amsgrad) :-
lmnn(amsgrad, [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], 2, 0.5, 0.01, 50, 100000, 0.000001, 0, 0, 50, 1, 0, DistanceList, _), lmnn(amsgrad, [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], 1, 0.5, 0.01, 50, 100000, 0.000001, 0, 0, 50, 1, 0, DistanceList, _),
print('\nDistance: '), print('\nDistance: '),
print(DistanceList). print(DistanceList).
test(lmnn_Normal_Use_BBSGD) :- test(lmnn_Normal_Use_BBSGD) :-
lmnn(bbsgd, [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], 2, 0.5, 0.01, 50, 100000, 0.000001, 0, 0, 50, 1, 0, DistanceList, _), lmnn(bbsgd, [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], 1, 0.5, 0.01, 50, 100000, 0.000001, 0, 0, 50, 1, 0, DistanceList, _),
print('\nDistance: '), print('\nDistance: '),
print(DistanceList). print(DistanceList).
test(lmnn_Normal_Use_SGD) :- test(lmnn_Normal_Use_SGD) :-
lmnn(sgd, [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], 2, 0.5, 0.01, 50, 100000, 0.000001, 0, 0, 50, 1, 0, DistanceList, _), lmnn(sgd, [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], 1, 0.5, 0.01, 50, 100000, 0.000001, 0, 0, 50, 1, 0, DistanceList, _),
print('\nDistance: '), print('\nDistance: '),
print(DistanceList). print(DistanceList).
test(lmnn_Normal_Use_LBFGS) :- test(lmnn_Normal_Use_LBFGS) :-
lmnn(lbfgs, [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], 2, 0.5, 0.01, 50, 100000, 0.000001, 0, 0, 50, 1, 0, DistanceList, _), lmnn(lbfgs, [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.2,1.3,0.5], 3, [0,1,0,1,0], 1, 0.5, 0.01, 50, 100000, 0.000001, 0, 0, 50, 1, 0, DistanceList, _),
print('\nDistance: '), print('\nDistance: '),
print(DistanceList). print(DistanceList).
test(lmnn_CSV_Input) :- test(lmnn_CSV_Input) :-
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),
lmnn(lbfgs, Data, 4, [0,1,0,1,1,0,1,1,1,0], 2, 0.7, 0.00021, 30, 1000, 0.00031, 1, 1, 30, 2, 2, DistanceList, _), lmnn(lbfgs, Data, 4, [0,1,0,1,1,0,1,1,1,0], 3, 0.7, 0.00021, 30, 1000, 0.00031, 1, 1, 30, 2, 2, DistanceList, _),
print('\nDistance: '), print('\nDistance: '),
print(DistanceList). print(DistanceList).
......
...@@ -31,7 +31,7 @@ LSHSearch lshSearch; ...@@ -31,7 +31,7 @@ LSHSearch lshSearch;
// description: // description:
// Initiatzes the model and trains it. // Initiatzes the model and trains it.
// //
void initModel(float *referenceMatArr, SP_integer referenceMatSize, SP_integer referenceMatRowNum, void initAndTrainModel(float *referenceMatArr, SP_integer referenceMatSize, SP_integer referenceMatRowNum,
SP_integer numProj, SP_integer numTables, double hashWidth, SP_integer secondHashSize, SP_integer bucketSize) SP_integer numProj, SP_integer numTables, double hashWidth, SP_integer secondHashSize, SP_integer bucketSize)
{ {
// convert the Prolog array to arma::mat // convert the Prolog array to arma::mat
...@@ -92,6 +92,12 @@ void searchWithQuery(float *querySetMatArr, SP_integer querySetMatSize, SP_integ ...@@ -92,6 +92,12 @@ void searchWithQuery(float *querySetMatArr, SP_integer querySetMatSize, SP_integ
{ {
// convert the Prolog array to arma::mat // convert the Prolog array to arma::mat
mat querySet = convertArrayToMat(querySetMatArr, querySetMatSize, querySetMatRowNum); mat querySet = convertArrayToMat(querySetMatArr, querySetMatSize, querySetMatRowNum);
if (querySet.n_cols < k)
{
raisePrologSystemExeption("K should not be greater than the amount of datapoints!");
return;
}
// create the ReturnMat // create the ReturnMat
Mat< size_t > resultingNeighborsReturnMat; Mat< size_t > resultingNeighborsReturnMat;
...@@ -108,6 +114,9 @@ void searchWithQuery(float *querySetMatArr, SP_integer querySetMatSize, SP_integ ...@@ -108,6 +114,9 @@ void searchWithQuery(float *querySetMatArr, SP_integer querySetMatSize, SP_integ
return; return;
} }
// float32 cant handle values over 1.0e+38
distancesReturnMat.clamp(-1.0e+38, 1.0e+38);
// return the Matrices // return the Matrices
returnMatrixInformation(resultingNeighborsReturnMat, resultingNeighborsMatArr, resultingNeighborsMatColNum, resultingNeighborsMatRowNum); returnMatrixInformation(resultingNeighborsReturnMat, resultingNeighborsMatArr, resultingNeighborsMatColNum, resultingNeighborsMatRowNum);
...@@ -129,11 +138,15 @@ void searchNoQuery(SP_integer k, ...@@ -129,11 +138,15 @@ void searchNoQuery(SP_integer k,
float **distancesMatArr, SP_integer *distancesMatColNum, SP_integer *distancesMatRowNum, float **distancesMatArr, SP_integer *distancesMatColNum, SP_integer *distancesMatRowNum,
SP_integer numTablesToSearch, SP_integer T) SP_integer numTablesToSearch, SP_integer T)
{ {
if (lshSearch.ReferenceSet().n_cols < k)
{
raisePrologSystemExeption("K should not be greater than the amount of datapoints!");
return;
}
// create the ReturnMat // create the ReturnMat
Mat< size_t > resultingNeighborsReturnMat; Mat< size_t > resultingNeighborsReturnMat;
mat distancesReturnMat; mat distancesReturnMat;
try try
{ {
lshSearch.Search(k, resultingNeighborsReturnMat, distancesReturnMat, numTablesToSearch, T); lshSearch.Search(k, resultingNeighborsReturnMat, distancesReturnMat, numTablesToSearch, T);
...@@ -144,38 +157,10 @@ void searchNoQuery(SP_integer k, ...@@ -144,38 +157,10 @@ void searchNoQuery(SP_integer k,
return; return;
} }
// float32 cant handle values over 1.0e+38
distancesReturnMat.clamp(-1.0e+38, 1.0e+38);
// return the Matrices // return the Matrices
returnMatrixInformation(resultingNeighborsReturnMat, resultingNeighborsMatArr, resultingNeighborsMatColNum, resultingNeighborsMatRowNum); returnMatrixInformation(resultingNeighborsReturnMat, resultingNeighborsMatArr, resultingNeighborsMatColNum, resultingNeighborsMatRowNum);
returnMatrixInformation(distancesReturnMat, distancesMatArr, distancesMatColNum, distancesMatRowNum); returnMatrixInformation(distancesReturnMat, distancesMatArr, distancesMatColNum, distancesMatRowNum);
} }
// input: MatType referenceSet,
// const size_t numProj,
// const size_t numTables,
// const double hashWidth = 0.0,
// const size_t secondHashSize = 99901,
// const size_t bucketSize = 500,
// const arma::cube & projection = arma::cube()
// output:
// description:
// Train the LSH model on the given dataset.
//
void train(float *referencesMatArr, SP_integer referencesMatSize, SP_integer referencesMatRowNum,
SP_integer numProj, SP_integer numTables, double hashWidth, SP_integer secondHashSize, SP_integer bucketSize)
{
// convert the Prolog arrays to arma::mat
mat references = convertArrayToMat(referencesMatArr, referencesMatSize, referencesMatRowNum);
try
{
lshSearch.Train(references, numProj, numTables, hashWidth, secondHashSize, bucketSize);
}
catch(const std::exception& e)
{
raisePrologSystemExeption(e.what());
return;
}
}
...@@ -54,7 +54,7 @@ test(lsh_InitAndTrainModel_CSV_Input) :- ...@@ -54,7 +54,7 @@ test(lsh_InitAndTrainModel_CSV_Input) :-
%% Failure Tests %% Failure Tests
test(lsh_ComputeRecall_Wrong_Dimensions, [error(_, system_error('Error'))]) :- test(lsh_ComputeRecall_Wrong_Dimensions, [error(_, system_error('LSHSearch::ComputeRecall(): matrices provided must have equal size'))]) :-
reset_Model, reset_Model,
lsh_computeRecall([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, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 4, _). lsh_computeRecall([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, [5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 4, _).
...@@ -77,11 +77,11 @@ test(lsh_ComputeRecall_Normal_Use) :- ...@@ -77,11 +77,11 @@ test(lsh_ComputeRecall_Normal_Use) :-
%% Failure Tests %% Failure Tests
test(lsh_SearchWithQuery_Wrong_Dimensions, [error(_, system_error('Error'))]) :- test(lsh_SearchWithQuery_Wrong_Dimensions, [error(_, system_error('LSHSearch::Search(): dimensionality of query set (4) is not equal to the dimensionality the model was trained on (3)!\n'))]) :-
reset_Model, reset_Model,
lsh_searchWithQuery([5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 4, 3, _, _, _, _, 0, 0). lsh_searchWithQuery([5.1,3.5,1.4,4.9,3.0,1.4,4.7,3.2,1.3,4.6,3.1,1.5], 4, 3, _, _, _, _, 0, 0).
test(lsh_SearchWithQuery_Too_High_K, [error(_, system_error('Error'))]) :- test(lsh_SearchWithQuery_Too_High_K, [error(_, system_error('K should not be greater than the amount of datapoints!'))]) :-
reset_Model, reset_Model,
lsh_searchWithQuery([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, 10, _, _, _, _, 0, 0). lsh_searchWithQuery([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, 10, _, _, _, _, 0, 0).
...@@ -119,7 +119,7 @@ test(lsh_SearchWithQuery_Normal_Use) :- ...@@ -119,7 +119,7 @@ test(lsh_SearchWithQuery_Normal_Use) :-
%% Failure Tests %% Failure Tests
test(lsh_SearchNoQuery_Too_High_K, [error(_, system_error('Error'))]) :- test(lsh_SearchNoQuery_Too_High_K, [error(_, system_error('K should not be greater than the amount of datapoints!'))]) :-
reset_Model, reset_Model,
lsh_searchNoQuery(10, _, _, _, _, 0, 0). lsh_searchNoQuery(10, _, _, _, _, 0, 0).
...@@ -139,8 +139,10 @@ test(lsh_SearchNoQuery_Negative_T, fail) :- ...@@ -139,8 +139,10 @@ test(lsh_SearchNoQuery_Negative_T, fail) :-
%% Successful Tests %% Successful Tests
test(lsh_SearchNoQuery_Normal_Use) :- test(lsh_SearchNoQuery_Normal_Use) :-
reset_Model, open('src/data_csv/iris2.csv', read, File),
lsh_searchNoQuery(3, NeighborResultsList, _, DistancesList, _, 0, 0), take_csv_row(File, skipFirstRow,10, Data),
lsh_initAndTrainModel(Data, 4, 25, 15, 1.5, 99901, 200),
lsh_searchNoQuery(6, NeighborResultsList, _, DistancesList, _, 0, 0),
print('\nNeighborResults: '), print('\nNeighborResults: '),
print(NeighborResultsList), print(NeighborResultsList),
print('\nDistances: '), print('\nDistances: '),
......
...@@ -18,8 +18,13 @@ ...@@ -18,8 +18,13 @@
test(mean_shift_Negative_MaxIterations, fail) :- test(mean_shift_Negative_MaxIterations, fail) :-
meanShift(1, -1000, [5.1,3.5,1.4,4.9, 3.0,1.4,4.7,3.2, 1.3,4.6,3.1,1.5, 1.4,3.0,2.1,0.1],4, _, _, _, 0, 0). meanShift(1, -1000, [5.1,3.5,1.4,4.9, 3.0,1.4,4.7,3.2, 1.3,4.6,3.1,1.5, 1.4,3.0,2.1,0.1],4, _, _, _, 0, 0).
test(mean_shift_Too_Few_Data_Points, fail) :- %% doesnt cause an error
meanShift(1, 1000, [5.1,3.5,1.4,4.9],4, _, _, _, 0, 0). test(mean_shift_Too_Few_Data_Points) :-
meanShift(1, 1000, [5.1,3.5,1.4,4.9],4, AssignList, CentroidsList, _, 0, 0),
print('\nAssignments: '),
print(AssignList),
print('\nCentroids: '),
print(CentroidsList).
%% Successful Tests %% Successful Tests
......
...@@ -40,17 +40,17 @@ ...@@ -40,17 +40,17 @@
%%:- use_module('src/methods/linear_regression/linear_regression_test.pl'). %%:- use_module('src/methods/linear_regression/linear_regression_test.pl').
%%:- use_module('src/methods/linear_SVM/linear_SVM_test.pl'). :- use_module('src/methods/linear_SVM/linear_SVM_test.pl').
%%:- use_module('src/methods/lmnn/lmnn_test.pl'). :- use_module('src/methods/lmnn/lmnn_test.pl').
%%:- use_module('src/methods/local_coordinate_coding/local_coordinate_coding_test.pl'). %%:- use_module('src/methods/local_coordinate_coding/local_coordinate_coding_test.pl').
%%:- use_module('src/methods/logistic_regression/logistic_regression_test.pl'). %%:- use_module('src/methods/logistic_regression/logistic_regression_test.pl').
%%:- use_module('src/methods/lsh/lsh_test.pl'). :- use_module('src/methods/lsh/lsh_test.pl').
%%:- use_module('src/methods/mean_shift/mean_shift_test.pl'). :- use_module('src/methods/mean_shift/mean_shift_test.pl').
%%:- use_module('src/methods/naive_bayes_classifier/naive_bayes_classifier_test.pl'). %%:- use_module('src/methods/naive_bayes_classifier/naive_bayes_classifier_test.pl').
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment