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

Updating adaboost

parent e45dce56
No related branches found
No related tags found
No related merge requests found
...@@ -78,11 +78,6 @@ void initModelWithTraining(float *dataMatArr, SP_integer dataMatSize, SP_integer ...@@ -78,11 +78,6 @@ void initModelWithTraining(float *dataMatArr, SP_integer dataMatSize, SP_integer
void initModelNoTraining(double tol = 1e-6, void initModelNoTraining(double tol = 1e-6,
char const *learner = "perceptron") char const *learner = "perceptron")
{ {
if(tol <= 0)
{
raisePrologDomainExeption(tol, 1, ">0", "initModelNoTraining");
}
if(strcmp(learner, "perceptron") == 0) if(strcmp(learner, "perceptron") == 0)
{ {
usingPerceptron = true; usingPerceptron = true;
...@@ -215,11 +210,6 @@ double getTolerance() ...@@ -215,11 +210,6 @@ double getTolerance()
// //
void modifyTolerance(double newTol) void modifyTolerance(double newTol)
{ {
if(newTol <= 0)
{
raisePrologDomainExeption(newTol, 1, ">0", "modifyTolerance");
}
if(usingPerceptron) if(usingPerceptron)
{ {
double& tol = adaBoostPerceptron.Tolerance(); double& tol = adaBoostPerceptron.Tolerance();
......
...@@ -38,23 +38,25 @@ ...@@ -38,23 +38,25 @@
%% %%
%% Initiates the Adaboostmodel and trains it, so classify can be used immediately. %% Initiates the Adaboostmodel and trains it, so classify can be used immediately.
%% %%
foreign(initModelWithTraining, c, initModelWithTraining(+pointer(float_array), +integer, +integer,
+pointer(float_array), +integer,
+integer,
+string,
+integer , +float32)).
initModelWithTraining(MatList, MatRows, VecList, NumClasses, Learner, Iterations, Tolerance) :- initModelWithTraining(MatList, MatRows, VecList, NumClasses, Learner, Iterations, Tolerance) :-
NumClasses >= 0, NumClasses >= 0,
Iterations >= 0, Iterations >= 0,
Tolerance >= 0, Tolerance > 0,
convert_list_to_float_array(MatList, MatRows, array(Xsize, Xrownum, X)), convert_list_to_float_array(MatList, MatRows, array(Xsize, Xrownum, X)),
convert_list_to_float_array(VecList, array(Ysize, Y)), convert_list_to_float_array(VecList, array(Ysize, Y)),
initModelWithTraining(X, Xsize, Xrownum, Y, Ysize, NumClasses, Learner, Iterations, Tolerance). initModelWithTrainingI(X, Xsize, Xrownum, Y, Ysize, NumClasses, Learner, Iterations, Tolerance).
foreign(initModelWithTraining, c, initModelWithTrainingI(+pointer(float_array), +integer, +integer,
+pointer(float_array), +integer,
+integer,
+string,
+integer , +float32)).
%% --Input-- %% --Input--
%% string learner => "decision_stump", "perceptron",
%% float tolerance => 1e-6 %% float tolerance => 1e-6
%% string learner => "decision_stump", "perceptron",
%% %%
%% --Output-- %% --Output--
%% %%
...@@ -62,7 +64,11 @@ initModelWithTraining(MatList, MatRows, VecList, NumClasses, Learner, Iterations ...@@ -62,7 +64,11 @@ initModelWithTraining(MatList, MatRows, VecList, NumClasses, Learner, Iterations
%% Needs to be called first before all other predicates exept initModelWithTraining! %% Needs to be called first before all other predicates exept initModelWithTraining!
%% Initiates the Adaboostmodel but doesnt train it, so train has to be used first before classify can be used. %% Initiates the Adaboostmodel but doesnt train it, so train has to be used first before classify can be used.
%% %%
foreign(initModelNoTraining, c, initModelNoTraining(+float32, +string)). initModelNoTraining(Tolerance, Learner) :-
Tolerance > 0,
initModelNoTrainingI(Tolerance, Learner).
foreign(initModelNoTraining, c, initModelNoTrainingI(+float32, +string)).
%% --Input-- %% --Input--
...@@ -75,16 +81,18 @@ foreign(initModelNoTraining, c, initModelNoTraining(+float32, +string)). ...@@ -75,16 +81,18 @@ foreign(initModelNoTraining, c, initModelNoTraining(+float32, +string)).
%% --Description-- %% --Description--
%% Classifies the given data into the number of classes the model was trained for. %% Classifies the given data into the number of classes the model was trained for.
%% %%
foreign(classify, c, classify( +pointer(float_array), +integer, +integer,
-pointer(float_array), -integer,
-pointer(float_array), -integer, -integer)).
classify(TestList, TestRows, PredicList, ProbsList, ZRows) :- classify(TestList, TestRows, PredicList, ProbsList, ZRows) :-
convert_list_to_float_array(TestList, TestRows, array(Xsize, Xrownum, X)), convert_list_to_float_array(TestList, TestRows, array(Xsize, Xrownum, X)),
classify(X, Xsize, Xrownum, Y, Ysize, Z, ZCols, ZRows), classifyI(X, Xsize, Xrownum, Y, Ysize, Z, ZCols, ZRows),
convert_float_array_to_list(Y, Ysize, PredicList), convert_float_array_to_list(Y, Ysize, PredicList),
convert_float_array_to_2d_list(Z, ZCols, ZRows, ProbsList). convert_float_array_to_2d_list(Z, ZCols, ZRows, ProbsList).
foreign(classify, c, classifyI( +pointer(float_array), +integer, +integer,
-pointer(float_array), -integer,
-pointer(float_array), -integer, -integer)).
%% --Input-- %% --Input--
%% %%
...@@ -94,7 +102,10 @@ classify(TestList, TestRows, PredicList, ProbsList, ZRows) :- ...@@ -94,7 +102,10 @@ classify(TestList, TestRows, PredicList, ProbsList, ZRows) :-
%% --Description-- %% --Description--
%% Returns the amount of classes defined in the model for classification. %% Returns the amount of classes defined in the model for classification.
%% %%
foreign(numClasses, c, numClasses([-integer])). numClasses(ClassesNum) :-
numClassesI(ClassesNum).
foreign(numClasses, c, numClassesI([-integer])).
%% --Input-- %% --Input--
...@@ -105,7 +116,10 @@ foreign(numClasses, c, numClasses([-integer])). ...@@ -105,7 +116,10 @@ foreign(numClasses, c, numClasses([-integer])).
%% --Description-- %% --Description--
%% Returns the tolerance of the model. %% Returns the tolerance of the model.
%% %%
foreign(getTolerance, c, getTolerance([-float32])). getTolerance(Tolerance) :-
getToleranceI(Tolerance).
foreign(getTolerance, c, getToleranceI([-float32])).
%% --Input-- %% --Input--
...@@ -116,7 +130,11 @@ foreign(getTolerance, c, getTolerance([-float32])). ...@@ -116,7 +130,11 @@ foreign(getTolerance, c, getTolerance([-float32])).
%% --Description-- %% --Description--
%% Modifies the tolerance of the model. %% Modifies the tolerance of the model.
%% %%
foreign(modifyTolerance, c, modifyTolerance(+float32)). modifyTolerance(NewTolerance) :-
NewTolerance > 0,
modifyToleranceI(NewTolerance).
foreign(modifyTolerance, c, modifyToleranceI(+float32)).
%% --Input-- %% --Input--
...@@ -131,20 +149,22 @@ foreign(modifyTolerance, c, modifyTolerance(+float32)). ...@@ -131,20 +149,22 @@ foreign(modifyTolerance, c, modifyTolerance(+float32)).
%% float double upper bound training error %% float double upper bound training error
%% %%
%% --Description-- %% --Description--
foreign(train, c, train( +pointer(float_array), +integer, +integer,
+pointer(float_array), +integer,
+integer,
+string,
+integer , +float32,
[-float32])).
train(MatList, MatRows, VecList, NumClasses, Learner, Iterations, Tolerance, Error) :- train(MatList, MatRows, VecList, NumClasses, Learner, Iterations, Tolerance, Error) :-
NumClasses >= 0, NumClasses >= 0,
Iterations >= 0, Iterations >= 0,
Tolerance >= 0, Tolerance >= 0,
convert_list_to_float_array(MatList, MatRows, array(Xsize, Xrownum, X)), convert_list_to_float_array(MatList, MatRows, array(Xsize, Xrownum, X)),
convert_list_to_float_array(VecList, array(Ysize, Y)), convert_list_to_float_array(VecList, array(Ysize, Y)),
train(X, Xsize, Xrownum, Y, Ysize, NumClasses, Learner, Iterations, Tolerance, Error). trainI(X, Xsize, Xrownum, Y, Ysize, NumClasses, Learner, Iterations, Tolerance, Error).
foreign(train, c, trainI( +pointer(float_array), +integer, +integer,
+pointer(float_array), +integer,
+integer,
+string,
+integer , +float32,
[-float32])).
%% Defines the functions that get connected from main.cpp %% Defines the functions that get connected from main.cpp
......
...@@ -62,13 +62,10 @@ test(initModelWithTraining_DecisionStump) :- ...@@ -62,13 +62,10 @@ test(initModelWithTraining_DecisionStump) :-
%% Failure Tests %% Failure Tests
test(initModelNoTraining_WrongInputTypes, [error(type_error(number ,wrong), _)]) :-
initModelNoTraining(wrong, 1).
test(initModelNoTraining_WrongLearner, [error(domain_error('perceptron or decision_stump' ,wrongLearner), _)]) :- test(initModelNoTraining_WrongLearner, [error(domain_error('perceptron or decision_stump' ,wrongLearner), _)]) :-
initModelNoTraining(0.0001, wrongLearner). initModelNoTraining(0.0001, wrongLearner).
test(initModelNoTraining_WrongTol, [error(domain_error('>0' ,-1.0), _)]) :- test(initModelNoTraining_WrongTol, fail) :-
initModelNoTraining(-1.0, perceptron). initModelNoTraining(-1.0, perceptron).
%% Successful Tests %% Successful Tests
...@@ -197,7 +194,7 @@ test(getTolerance_afterTrain, [true(Amount =:= 0.0005)]) :- ...@@ -197,7 +194,7 @@ test(getTolerance_afterTrain, [true(Amount =:= 0.0005)]) :-
:- begin_tests(modifyTolerance). :- begin_tests(modifyTolerance).
%% Failure Tests %% Failure Tests
test(modifyTolerance_With_Negative_Input, [error(domain_error('>0' , -0.02), _)]) :- test(modifyTolerance_With_Negative_Input, fail) :-
reset_Model_No_Train(perceptron), reset_Model_No_Train(perceptron),
modifyTolerance(-0.02). modifyTolerance(-0.02).
...@@ -319,3 +316,4 @@ test(train_After_InitTrain_Decision_Stump, [true(Error =:= 1)]) :- ...@@ -319,3 +316,4 @@ test(train_After_InitTrain_Decision_Stump, [true(Error =:= 1)]) :-
run_adaboost_tests :- run_adaboost_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