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

Finishing hoeffding_tree tests.

parent b8580f72
Branches
No related tags found
No related merge requests found
...@@ -45,6 +45,12 @@ void initAndBuildModel(char const *treeType, ...@@ -45,6 +45,12 @@ void initAndBuildModel(char const *treeType,
{ {
// convert the Prolog arrays to arma::mat // convert the Prolog arrays to arma::mat
mat data = convertArrayToMat(dataMatArr, dataMatSize, dataMatRowNum); mat data = convertArrayToMat(dataMatArr, dataMatSize, dataMatRowNum);
// check if labels fit the data
if (data.n_cols != labelsArrSize)
{
raisePrologSystemExeption("The number of data points does not match the number of labels!");
return;
}
// convert the Prolog arrays to arma::rowvec // convert the Prolog arrays to arma::rowvec
Row< size_t > labelsVector = convertArrayToVec(labelsArr, labelsArrSize); Row< size_t > labelsVector = convertArrayToVec(labelsArr, labelsArrSize);
...@@ -144,6 +150,12 @@ void train(float *dataMatArr, SP_integer dataMatSize, SP_integer dataMatRowNum, ...@@ -144,6 +150,12 @@ void train(float *dataMatArr, SP_integer dataMatSize, SP_integer dataMatRowNum,
// convert the Prolog arrays to arma::mat // convert the Prolog arrays to arma::mat
mat data = convertArrayToMat(dataMatArr, dataMatSize, dataMatRowNum); mat data = convertArrayToMat(dataMatArr, dataMatSize, dataMatRowNum);
// check if labels fit the data
if (data.n_cols != labelsArrSize)
{
raisePrologSystemExeption("The number of data points does not match the number of labels!");
return;
}
// convert the Prolog arrays to arma::rowvec // convert the Prolog arrays to arma::rowvec
Row< size_t > labelsVector = convertArrayToVec(labelsArr, labelsArrSize); Row< size_t > labelsVector = convertArrayToVec(labelsArr, labelsArrSize);
......
...@@ -47,18 +47,18 @@ test(hoeffding_Init_Negative_ObservationsBeforeBinning, fail) :- ...@@ -47,18 +47,18 @@ test(hoeffding_Init_Negative_ObservationsBeforeBinning, fail) :-
hoeffding_tree_initAndBuildModel(gini_binary, [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, 0.95, 5000, 100, 100, 10, -100). hoeffding_tree_initAndBuildModel(gini_binary, [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, 0.95, 5000, 100, 100, 10, -100).
test(hoeffding_Init_With_Wrong_Label_Dims1, [error(_,system_error('Labels Vector is too short or its values are incorrect: should fit into [0,numClasses)!'))]) :- test(hoeffding_Init_With_Wrong_Label_Dims1, [error(_,system_error('The number of data points does not match the number of labels!'))]) :-
hoeffding_tree_initAndBuildModel(gini_binary, [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, 0.95, 5000, 100, 100, 10, 100). hoeffding_tree_initAndBuildModel(gini_binary, [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, 0.95, 5000, 100, 100, 10, 100).
%% If the label vector is to long it seems to cause no problems test(hoeffding_Init_With_Wrong_Label_Dims2, [error(_,system_error('The number of data points does not match the number of labels!'))]) :-
test(hoeffding_Init_With_Wrong_Label_Dims2) :-
hoeffding_tree_initAndBuildModel(gini_binary, [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,0,1], 2, 0, 0.95, 5000, 100, 100, 10, 100). hoeffding_tree_initAndBuildModel(gini_binary, [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,0,1], 2, 0, 0.95, 5000, 100, 100, 10, 100).
%% The same when the label values are out of range %% doesnt cause an error
test(hoeffding_Init_With_Wrong_Label_Value) :- test(hoeffding_Init_With_Wrong_Label_Value) :-
hoeffding_tree_initAndBuildModel(gini_binary, [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, 0.95, 5000, 100, 100, 10, 100). hoeffding_tree_initAndBuildModel(gini_binary, [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, 0.95, 5000, 100, 100, 10, 100).
test(hoeffding_Init_With_Too_Many_Label_Value, [error(_,system_error('The values of the Label have to start at 0 and be >= 0 and < the given numClass!'))]) :- %% doesnt cause an error
test(hoeffding_Init_With_Too_Many_Label_Value) :-
hoeffding_tree_initAndBuildModel(gini_binary, [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,1,0,2], 2, 0, 0.95, 5000, 100, 100, 10, 100). hoeffding_tree_initAndBuildModel(gini_binary, [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,1,0,2], 2, 0, 0.95, 5000, 100, 100, 10, 100).
...@@ -106,9 +106,10 @@ test(hoeffding_Init_InfoBinary_CSV_Input) :- ...@@ -106,9 +106,10 @@ test(hoeffding_Init_InfoBinary_CSV_Input) :-
%% Failure Tests %% Failure Tests
test(hoeffding_Classify_Different_Dims_To_Train, [error(_,system_error('Labels Vector is too short or its values are incorrect: should fit into [0,numClasses)!'))]) :- %% seems to be able to classify diffrent Dimensions than trained
test(hoeffding_Classify_Different_Dims_To_Train) :-
reset_Model, reset_Model,
hoeffding_tree_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, PredicList, ProbsList), hoeffding_tree_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], 2, PredicList, ProbsList),
print('\nPredictions: '), print('\nPredictions: '),
print(PredicList), print(PredicList),
print('\nProbabilities: '), print('\nProbabilities: '),
...@@ -167,23 +168,23 @@ test(hoeffding_Classify_InfoBinary) :- ...@@ -167,23 +168,23 @@ test(hoeffding_Classify_InfoBinary) :-
%% Failure Tests %% Failure Tests
test(hoeffding_Train_With_Wrong_Label_Dims1, [error(_,system_error('Labels Vector is too short or its values are incorrect: should fit into [0,numClasses)!'))]) :- test(hoeffding_Train_With_Wrong_Label_Dims1, [error(_,system_error('The number of data points does not match the number of labels!'))]) :-
reset_Model, reset_Model,
hoeffding_tree_train([3, 2, 0, 5, 1, 4, 1, 0, 4, 3, 3, 5, 0, 5, 5, 2, 5, 5, 0, 2], 4, [0,1,0,0,0], 0). hoeffding_tree_train([3, 2, 0, 5, 1, 4, 1, 0, 4, 3, 3, 5, 0, 5, 5, 2, 5, 5, 0, 2], 4, [0,1,0,0], 0).
%% If the label vector is to long it seems to cause no problems test(hoeffding_Train_With_Wrong_Label_Dims2, [error(_,system_error('The number of data points does not match the number of labels!'))]) :-
test(hoeffding_Train_With_Wrong_Label_Dims2) :-
reset_Model, reset_Model,
hoeffding_tree_train([3, 2, 0, 5, 1, 4, 1, 0, 4, 3, 3, 5, 0, 5, 5, 2, 5, 5, 0, 2], 4, [0,1,0,1,0,0,1], 0). hoeffding_tree_train([3, 2, 0, 5, 1, 4, 1, 0, 4, 3, 3, 5, 0, 5, 5, 2, 5, 5, 0, 2], 4, [0,1,0,1,0,0,1], 0).
%% The same when the label values are out of range
%% all 3 test dont cause an error
test(hoeffding_Train_With_Wrong_Label_Value) :- test(hoeffding_Train_With_Wrong_Label_Value) :-
reset_Model, reset_Model,
hoeffding_tree_train([3, 2, 0, 5, 1, 4, 1, 0, 4, 3, 3, 5, 0, 5, 5, 2, 5, 5, 0, 2], 4, [0,-1,0,-1], 0). hoeffding_tree_train([3, 2, 0, 5, 1, 4, 1, 0, 4, 3, 3, 5, 0, 5, 5, 2, 5, 5, 0, 2], 4, [0,-1,0,-1,0], 0).
test(hoeffding_Train_With_Too_Many_Label_Value, [error(_,system_error('The values of the Label have to start at 0 and be >= 0 and < the given numClass!'))]) :- test(hoeffding_Train_With_Too_Many_Label_Value) :-
reset_Model, reset_Model,
hoeffding_tree_train([3, 2, 0, 5, 1, 4, 1, 0, 4, 3, 3, 5, 0, 5, 5, 2, 5, 5, 0, 2], 4, [1,1,0,2], 0). hoeffding_tree_train([3, 2, 0, 5, 1, 4, 1, 0, 4, 3, 3, 5, 0, 5, 5, 2, 5, 5, 0, 2], 4, [1,1,0,2,3], 0).
test(hoeffding_Train_Bad_Data_Dims) :- test(hoeffding_Train_Bad_Data_Dims) :-
reset_Model, reset_Model,
...@@ -192,7 +193,7 @@ test(hoeffding_Train_Bad_Data_Dims) :- ...@@ -192,7 +193,7 @@ test(hoeffding_Train_Bad_Data_Dims) :-
%% Successful Tests %% Successful Tests
test(testDescription3) :- test(hoeffding_Train_Normal_Use) :-
reset_Model, reset_Model,
hoeffding_tree_train([3, 2, 0, 5, 1, 4, 1, 0, 4, 3, 3, 5, 0, 5, 5, 2, 5, 5, 0, 2], 4, [0,0,1,1,0], 1), hoeffding_tree_train([3, 2, 0, 5, 1, 4, 1, 0, 4, 3, 3, 5, 0, 5, 5, 2, 5, 5, 0, 2], 4, [0,0,1,1,0], 1),
hoeffding_tree_train([3, 2, 0, 5, 1, 4, 1, 0, 4, 3, 3, 5, 0, 5, 5, 2, 5, 5, 0, 2], 4, [0,0,1,1,0], 0). hoeffding_tree_train([3, 2, 0, 5, 1, 4, 1, 0, 4, 3, 3, 5, 0, 5, 5, 2, 5, 5, 0, 2], 4, [0,0,1,1,0], 0).
...@@ -200,5 +201,5 @@ test(testDescription3) :- ...@@ -200,5 +201,5 @@ test(testDescription3) :-
:- end_tests(hoeffding_tree_train). :- end_tests(hoeffding_tree_train).
run_hoeffding_tree_tests :- run_hoeffding_tree_tests :-
run_tests(hoeffding_tree_train). run_tests.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment