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

Adding kfn tests

parent ca6ddabe
Branches
No related tags found
No related merge requests found
...@@ -17,6 +17,7 @@ using namespace mlpack::neighbor; ...@@ -17,6 +17,7 @@ using namespace mlpack::neighbor;
// Global Variable of the NSModel object so it can be accessed from all functions // Global Variable of the NSModel object so it can be accessed from all functions
NSModel<FurthestNS> nsModelObj; NSModel<FurthestNS> nsModelObj;
int trainedDimension = 0;
// input: TreeTypes treeType = TreeTypes::KD_TREE, // input: TreeTypes treeType = TreeTypes::KD_TREE,
...@@ -47,23 +48,23 @@ void initAndBuildModel(char const *treeType, char const *algorithm, ...@@ -47,23 +48,23 @@ void initAndBuildModel(char const *treeType, char const *algorithm,
tree = NSModel<FurthestNS>::COVER_TREE; tree = NSModel<FurthestNS>::COVER_TREE;
else if (strcmp(treeType, "r") == 0) else if (strcmp(treeType, "r") == 0)
tree = NSModel<FurthestNS>::R_TREE; tree = NSModel<FurthestNS>::R_TREE;
else if (strcmp(treeType, "r-star") == 0) else if (strcmp(treeType, "r_star") == 0)
tree = NSModel<FurthestNS>::R_STAR_TREE; tree = NSModel<FurthestNS>::R_STAR_TREE;
else if (strcmp(treeType, "ball") == 0) else if (strcmp(treeType, "ball") == 0)
tree = NSModel<FurthestNS>::BALL_TREE; tree = NSModel<FurthestNS>::BALL_TREE;
else if (strcmp(treeType, "x") == 0) else if (strcmp(treeType, "x") == 0)
tree = NSModel<FurthestNS>::X_TREE; tree = NSModel<FurthestNS>::X_TREE;
else if (strcmp(treeType, "hilbert-r") == 0) else if (strcmp(treeType, "hilbert_r") == 0)
tree = NSModel<FurthestNS>::HILBERT_R_TREE; tree = NSModel<FurthestNS>::HILBERT_R_TREE;
else if (strcmp(treeType, "r-plus") == 0) else if (strcmp(treeType, "r_plus") == 0)
tree = NSModel<FurthestNS>::R_PLUS_TREE; tree = NSModel<FurthestNS>::R_PLUS_TREE;
else if (strcmp(treeType, "r-plus-plus") == 0) else if (strcmp(treeType, "r_plus_plus") == 0)
tree = NSModel<FurthestNS>::R_PLUS_PLUS_TREE; tree = NSModel<FurthestNS>::R_PLUS_PLUS_TREE;
else if (strcmp(treeType, "vp") == 0) else if (strcmp(treeType, "vp") == 0)
tree = NSModel<FurthestNS>::VP_TREE; tree = NSModel<FurthestNS>::VP_TREE;
else if (strcmp(treeType, "rp") == 0) else if (strcmp(treeType, "rp") == 0)
tree = NSModel<FurthestNS>::RP_TREE; tree = NSModel<FurthestNS>::RP_TREE;
else if (strcmp(treeType, "max-rp") == 0) else if (strcmp(treeType, "max_rp") == 0)
tree = NSModel<FurthestNS>::MAX_RP_TREE; tree = NSModel<FurthestNS>::MAX_RP_TREE;
else if (strcmp(treeType, "ub") == 0) else if (strcmp(treeType, "ub") == 0)
tree = NSModel<FurthestNS>::UB_TREE; tree = NSModel<FurthestNS>::UB_TREE;
...@@ -92,6 +93,7 @@ void initAndBuildModel(char const *treeType, char const *algorithm, ...@@ -92,6 +93,7 @@ void initAndBuildModel(char const *treeType, char const *algorithm,
nsModelObj.RandomBasis() = (randomBasis == 1); nsModelObj.RandomBasis() = (randomBasis == 1);
trainedDimension = reference.n_rows;
nsModelObj.BuildModel(std::move(reference), size_t(leafSize), searchMode, epsilon); nsModelObj.BuildModel(std::move(reference), size_t(leafSize), searchMode, epsilon);
} }
...@@ -110,6 +112,14 @@ void searchWithQuery( float *queryMatArr, SP_integer queryMatSize, SP_integer ...@@ -110,6 +112,14 @@ void searchWithQuery( float *queryMatArr, SP_integer queryMatSize, SP_integer
float **neighborsMatArr, SP_integer *neighborsMatColNum, SP_integer *neighborsMatRowNum, float **neighborsMatArr, SP_integer *neighborsMatColNum, SP_integer *neighborsMatRowNum,
float **distancesMatArr, SP_integer *distancesMatColNum, SP_integer *distancesMatRowNum) float **distancesMatArr, SP_integer *distancesMatColNum, SP_integer *distancesMatRowNum)
{ {
if (trainedDimension != queryMatRowNum)
{
std::ostringstream stream;
stream << "Queryset has Dim(" << queryMatRowNum << ") but the Referenceset has Dim(" << trainedDimension << ")";
raisePrologSystemExeption(stream.str().c_str());
return;
}
// convert the Prolog array to arma::mat // convert the Prolog array to arma::mat
mat query = convertArrayToMat(queryMatArr, queryMatSize, queryMatRowNum); mat query = convertArrayToMat(queryMatArr, queryMatSize, queryMatRowNum);
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
%% --Input-- %% --Input--
%% string treeType => "kd", "vp", "rp", "max-rp", "ub", "cover", "r", "r-star", "x", "ball", "hilbert-r", "r-plus", "r-plus-plus", "spill", "oct", %% string treeType => "kd", "vp", "rp", "max_rp", "ub", "cover", "r", "r_star", "x", "ball", "hilbert_r", "r_plus", "r_plus_plus", "oct",
%% string searchMode => "naive", "single_tree", "dual_tree", "greedy", %% string searchMode => "naive", "single_tree", "dual_tree", "greedy",
%% bool randomBasis => (1)true / (0)false, %% bool randomBasis => (1)true / (0)false,
%% int leafSize => 20, %% int leafSize => 20,
...@@ -34,6 +34,8 @@ ...@@ -34,6 +34,8 @@
%% Initialize the Model and build it. %% Initialize the Model and build it.
%% %%
initAndBuildModel(TreeType, SearchMode, RandomBasis, LeafSize, Epsilon, ReferenceList, ReferenceRows) :- initAndBuildModel(TreeType, SearchMode, RandomBasis, LeafSize, Epsilon, ReferenceList, ReferenceRows) :-
LeafSize >= 1,
Epsilon >= 0,
convert_list_to_float_array(ReferenceList, ReferenceRows, array(Xsize, Xrownum, X)), convert_list_to_float_array(ReferenceList, ReferenceRows, array(Xsize, Xrownum, X)),
initAndBuildModelI(TreeType, SearchMode, RandomBasis, LeafSize, Epsilon, X, Xsize, Xrownum). initAndBuildModelI(TreeType, SearchMode, RandomBasis, LeafSize, Epsilon, X, Xsize, Xrownum).
...@@ -55,6 +57,7 @@ foreign(initAndBuildModel, c, initAndBuildModelI(+string, +string, ...@@ -55,6 +57,7 @@ foreign(initAndBuildModel, c, initAndBuildModelI(+string, +string,
%% Perform neighbor search on the queryset. %% Perform neighbor search on the queryset.
%% %%
searchWithQuery(QueryList, QueryRows, K, NeighborsList, YCols, DistancesList, ZCols) :- searchWithQuery(QueryList, QueryRows, K, NeighborsList, YCols, DistancesList, ZCols) :-
K > 0,
convert_list_to_float_array(QueryList, QueryRows, array(Xsize, Xrownum, X)), convert_list_to_float_array(QueryList, QueryRows, array(Xsize, Xrownum, X)),
searchWithQueryI(X, Xsize, Xrownum, K, Y, YCols, YRows, Z, ZCols, ZRows), searchWithQueryI(X, Xsize, Xrownum, K, Y, YCols, YRows, Z, ZCols, ZRows),
convert_float_array_to_2d_list(Y, YCols, YRows, NeighborsList), convert_float_array_to_2d_list(Y, YCols, YRows, NeighborsList),
...@@ -78,6 +81,7 @@ foreign(searchWithQuery, c, searchWithQueryI( +pointer(float_array), +integer, ...@@ -78,6 +81,7 @@ foreign(searchWithQuery, c, searchWithQueryI( +pointer(float_array), +integer,
%% Perform monochromatic neighbor search. %% Perform monochromatic neighbor search.
%% %%
searchNoQuery(K, NeighborsList, YCols, DistancesList, ZCols) :- searchNoQuery(K, NeighborsList, YCols, DistancesList, ZCols) :-
K > 0,
searchNoQueryI(K, Y, YCols, YRows, Z, ZCols, ZRows), searchNoQueryI(K, Y, YCols, YRows, Z, ZCols, ZRows),
convert_float_array_to_2d_list(Y, YCols, YRows, NeighborsList), convert_float_array_to_2d_list(Y, YCols, YRows, NeighborsList),
convert_float_array_to_2d_list(Z, ZCols, ZRows, DistancesList). convert_float_array_to_2d_list(Z, ZCols, ZRows, DistancesList).
......
...@@ -7,39 +7,124 @@ ...@@ -7,39 +7,124 @@
:- use_module('../../helper_files/helper.pl'). :- use_module('../../helper_files/helper.pl').
reset_Model :- reset_Model :-
initModel(1,0,50,0.0001). initAndBuildModel(kd, dual_tree, 0, 20, 0.0, [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).
%% %%
%% TESTING predicate initAndBuildModel/7 %% TESTING predicate initAndBuildModel/9
%% %%
:- begin_tests(initAndBuildModel). :- begin_tests(initAndBuildModel).
%% Failure Tests %% Failure Tests
test(testDescription, [error(domain_error('expectation' , culprit), _)]) :- test(kfn_InitAndBuildModel_Wrong_TreeType_Input, [error(domain_error('The given TreeType is unknown!' , wrongInput), _)]) :-
reset_Model_No_Train(perceptron), initAndBuildModel(wrongInput, dual_tree, 0, 20, 0.0, [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).
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(testDescription2, [error(_,system_error('The values of the Label have to start at 0 and be >= 0 and < the given numClass!'))]) :- test(kfn_InitAndBuildModel_Wrong_SearchMode_Input, [error(domain_error('The given SearchMode is unknown!' , wrongInput), _)]) :-
reset_Model_No_Train(perceptron), initAndBuildModel(kd, wrongInput, 0, 20, 0.0, [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).
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(kfn_InitAndBuildModel_Negative_LeafSize, fail) :-
initAndBuildModel(kd, dual_tree, 0, 0, 0.0, [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(kfn_InitAndBuildModel_Negative_Epsilon, fail) :-
initAndBuildModel(kd, dual_tree, 0, 20, -1.0, [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).
%% Successful Tests
test(testDescription3, [true(Error =:= 1)]) :- %% Successful Tests
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(testDescription4, [true(Error =:= 0.9797958971132711)]) :- test(kfn_InitAndBuildModel_KD) :-
reset_Model_No_Train(perceptron), initAndBuildModel(kd, naive, 0, 20, 0.005, [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),
initAndBuildModel(kd, single_tree, 0, 20, 0.005, [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),
initAndBuildModel(kd, dual_tree, 0, 20, 0.005, [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),
initAndBuildModel(kd, greedy, 0, 20, 0.005, [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(kfn_InitAndBuildModel_VP) :-
initAndBuildModel(vp, naive, 0, 20, 0.005, [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),
initAndBuildModel(vp, single_tree, 0, 20, 0.005, [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),
initAndBuildModel(vp, dual_tree, 0, 20, 0.005, [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),
initAndBuildModel(vp, greedy, 0, 20, 0.005, [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(kfn_InitAndBuildModel_RP) :-
initAndBuildModel(rp, naive, 0, 20, 0.005, [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),
initAndBuildModel(rp, single_tree, 0, 20, 0.005, [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),
initAndBuildModel(rp, dual_tree, 0, 20, 0.005, [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),
initAndBuildModel(rp, greedy, 0, 20, 0.005, [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(kfn_InitAndBuildModel_MAX_RP) :-
initAndBuildModel(max_rp, naive, 0, 20, 0.005, [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),
initAndBuildModel(max_rp, single_tree, 0, 20, 0.005, [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),
initAndBuildModel(max_rp, dual_tree, 0, 20, 0.005, [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),
initAndBuildModel(max_rp, greedy, 0, 20, 0.005, [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(kfn_InitAndBuildModel_UB) :-
initAndBuildModel(ub, naive, 0, 20, 0.005, [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),
initAndBuildModel(ub, single_tree, 0, 20, 0.005, [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),
initAndBuildModel(ub, dual_tree, 0, 20, 0.005, [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),
initAndBuildModel(ub, greedy, 0, 20, 0.005, [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(kfn_InitAndBuildModel_COVER) :-
initAndBuildModel(cover, naive, 0, 20, 0.005, [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),
initAndBuildModel(cover, single_tree, 0, 20, 0.005, [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),
initAndBuildModel(cover, dual_tree, 0, 20, 0.005, [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),
initAndBuildModel(cover, greedy, 0, 20, 0.005, [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(kfn_InitAndBuildModel_R) :-
initAndBuildModel(r, naive, 0, 20, 0.005, [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),
initAndBuildModel(r, single_tree, 0, 20, 0.005, [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),
initAndBuildModel(r, dual_tree, 0, 20, 0.005, [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),
initAndBuildModel(r, greedy, 0, 20, 0.005, [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(kfn_InitAndBuildModel_R_STAR) :-
initAndBuildModel(r_star, naive, 0, 20, 0.005, [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),
initAndBuildModel(r_star, single_tree, 0, 20, 0.005, [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),
initAndBuildModel(r_star, dual_tree, 0, 20, 0.005, [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),
initAndBuildModel(r_star, greedy, 0, 20, 0.005, [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(kfn_InitAndBuildModel_X) :-
initAndBuildModel(x, naive, 0, 20, 0.005, [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),
initAndBuildModel(x, single_tree, 0, 20, 0.005, [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),
initAndBuildModel(x, dual_tree, 0, 20, 0.005, [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),
initAndBuildModel(x, greedy, 0, 20, 0.005, [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(kfn_InitAndBuildModel_BALL) :-
initAndBuildModel(ball, naive, 0, 20, 0.005, [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),
initAndBuildModel(ball, single_tree, 0, 20, 0.005, [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),
initAndBuildModel(ball, dual_tree, 0, 20, 0.005, [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),
initAndBuildModel(ball, greedy, 0, 20, 0.005, [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(kfn_InitAndBuildModel_Hilbert_R) :-
initAndBuildModel(hilbert_r, naive, 0, 20, 0.005, [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),
initAndBuildModel(hilbert_r, single_tree, 0, 20, 0.005, [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),
initAndBuildModel(hilbert_r, dual_tree, 0, 20, 0.005, [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),
initAndBuildModel(hilbert_r, greedy, 0, 20, 0.005, [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(kfn_InitAndBuildModel_R_Plus) :-
initAndBuildModel(r_plus, naive, 0, 20, 0.005, [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),
initAndBuildModel(r_plus, single_tree, 0, 20, 0.005, [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),
initAndBuildModel(r_plus, dual_tree, 0, 20, 0.005, [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),
initAndBuildModel(r_plus, greedy, 0, 20, 0.005, [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(kfn_InitAndBuildModel_R_Plus_Plus) :-
initAndBuildModel(r_plus_plus, naive, 0, 20, 0.005, [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),
initAndBuildModel(r_plus_plus, single_tree, 0, 20, 0.005, [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),
initAndBuildModel(r_plus_plus, dual_tree, 0, 20, 0.005, [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),
initAndBuildModel(r_plus_plus, greedy, 0, 20, 0.005, [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(kfn_InitAndBuildModel_OCT) :-
initAndBuildModel(oct, naive, 0, 20, 0.005, [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),
initAndBuildModel(oct, single_tree, 0, 20, 0.005, [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),
initAndBuildModel(oct, dual_tree, 0, 20, 0.005, [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),
initAndBuildModel(oct, greedy, 0, 20, 0.005, [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(kfn_InitAndBuildModel_CSV_Input) :-
reset_Model,
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). initAndBuildModel(kd, dual_tree, 1, 20, 0.005, Data, 4).
:- end_tests(initAndBuildModel). :- end_tests(initAndBuildModel).
%% %%
%% TESTING predicate searchWithQuery/7 %% TESTING predicate searchWithQuery/7
%% %%
...@@ -47,57 +132,78 @@ test(testDescription4, [true(Error =:= 0.9797958971132711)]) :- ...@@ -47,57 +132,78 @@ test(testDescription4, [true(Error =:= 0.9797958971132711)]) :-
%% Failure Tests %% Failure Tests
test(testDescription, [error(domain_error('expectation' , culprit), _)]) :- test(kfn_SearchWithQuery_Wrong_Query_Dims, [error(_,system_error('Queryset has Dim(4) but the Referenceset has Dim(3)'))]) :-
reset_Model_No_Train(perceptron), reset_Model,
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, _). 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, 2, _, _, _, _).
test(kfn_SearchWithQuery_Negative_K, fail) :-
reset_Model,
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, -1, _, _, _, _).
test(testDescription2, [error(_,system_error('The values of the Label have to start at 0 and be >= 0 and < the given numClass!'))]) :- test(kfn_SearchWithQuery_Too_Large_K, [error(_,system_error('Requested value of k (10) is greater than the number of points in the reference set (4)'))]) :-
reset_Model_No_Train(perceptron), reset_Model,
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, _). 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, _, _, _, _).
%% Successful Tests %% Successful Tests
test(testDescription3, [true(Error =:= 1)]) :- test(kfn_SearchWithQuery_Normal) :-
reset_Model_No_Train(perceptron), reset_Model,
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). 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, 2, NeighborsList, _, DistancesList, _),
print('\nNeighbors: '),
print(NeighborsList),
print('\nDistances: '),
print(DistancesList).
test(testDescription4, [true(Error =:= 0.9797958971132711)]) :- test(kfn_SearchWithQuery_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). initAndBuildModel(kd, dual_tree, 0, 20, 0.0, Data, 4),
searchWithQuery([3, 2, 0, 5, 1, 4, 1, 0, 4, 3, 3, 5, 0, 5, 5, 2, 5, 5, 0, 2], 4, 7, NeighborsList, _, DistancesList, _),
print('\nNeighbors: '),
print(NeighborsList),
print('\nDistances: '),
print(DistancesList).
:- end_tests(searchWithQuery). :- end_tests(searchWithQuery).
%% %%
%% TESTING predicate searchNoQuery/5 %% TESTING predicate searchNoQuery/10
%% %%
:- begin_tests(searchNoQuery). :- begin_tests(searchNoQuery).
%% Failure Tests %% Failure Tests
test(testDescription, [error(domain_error('expectation' , culprit), _)]) :- test(kfn_SearchNoQuery_Negative_K, fail) :-
reset_Model_No_Train(perceptron), reset_Model,
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, _). searchNoQuery(-1, _, _, _, _).
test(testDescription2, [error(_,system_error('The values of the Label have to start at 0 and be >= 0 and < the given numClass!'))]) :- test(kfn_SearchNoQuery_Too_Large_K, [error(_,system_error('Requested value of k (15) is greater than the number of points in the reference set (4)'))]) :-
reset_Model_No_Train(perceptron), reset_Model,
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, _). searchNoQuery(15, _, _, _, _).
%% Successful Tests %% Successful Tests
test(testDescription3, [true(Error =:= 1)]) :- test(kfn_SearchNoQuery_Normal) :-
reset_Model_No_Train(perceptron), reset_Model,
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). searchNoQuery(2, NeighborsList, _, DistancesList, _),
print('\nNeighbors: '),
print(NeighborsList),
print('\nDistances: '),
print(DistancesList).
test(testDescription4, [true(Error =:= 0.9797958971132711)]) :- test(kfn_SearchNoQuery_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). initAndBuildModel(kd, dual_tree, 0, 20, 0.0, Data, 4),
searchNoQuery(7, NeighborsList, _, DistancesList, _),
print('\nNeighbors: '),
print(NeighborsList),
print('\nDistances: '),
print(DistancesList).
:- end_tests(searchNoQuery). :- end_tests(searchNoQuery).
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment