Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Prolog mlpack Library
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
general
stups
Prolog mlpack Library
Commits
1cb6520a
Commit
1cb6520a
authored
2 years ago
by
Jakhes
Browse files
Options
Downloads
Patches
Plain Diff
Adding linear_SVM tests
parent
d523323a
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/methods/linear_SVM/linear_SVM.pl
+15
-8
15 additions, 8 deletions
src/methods/linear_SVM/linear_SVM.pl
src/methods/linear_SVM/linear_SVM_test.pl
+259
-24
259 additions, 24 deletions
src/methods/linear_SVM/linear_SVM_test.pl
with
274 additions
and
32 deletions
src/methods/linear_SVM/linear_SVM.pl
+
15
−
8
View file @
1cb6520a
...
@@ -37,6 +37,9 @@
...
@@ -37,6 +37,9 @@
%% Initializes the linear_svm model with the given data and trains it.
%% Initializes the linear_svm model with the given data and trains it.
%%
%%
initModelWithTrain
(
DataList
,
DataRows
,
LabelsList
,
NumClasses
,
Lambda
,
Delta
,
FitIntercept
,
Optimizer
)
:-
initModelWithTrain
(
DataList
,
DataRows
,
LabelsList
,
NumClasses
,
Lambda
,
Delta
,
FitIntercept
,
Optimizer
)
:-
NumClasses
>=
0
,
Lambda
>=
0.0
,
Delta
>=
0.0
,
convert_list_to_float_array
(
DataList
,
DataRows
,
array
(
Xsize
,
Xrownum
,
X
)),
convert_list_to_float_array
(
DataList
,
DataRows
,
array
(
Xsize
,
Xrownum
,
X
)),
convert_list_to_float_array
(
LabelsList
,
array
(
Ysize
,
Y
)),
convert_list_to_float_array
(
LabelsList
,
array
(
Ysize
,
Y
)),
initModelWithTrainI
(
X
,
Xsize
,
Xrownum
,
Y
,
Ysize
,
NumClasses
,
Lambda
,
Delta
,
FitIntercept
,
Optimizer
).
initModelWithTrainI
(
X
,
Xsize
,
Xrownum
,
Y
,
Ysize
,
NumClasses
,
Lambda
,
Delta
,
FitIntercept
,
Optimizer
).
...
@@ -60,6 +63,9 @@ foreign(initModelWithTrain, c, initModelWithTrainI( +pointer(float_array), +
...
@@ -60,6 +63,9 @@ foreign(initModelWithTrain, c, initModelWithTrainI( +pointer(float_array), +
%% Initializes the linear_svm model with the given data but doesnt train it.
%% Initializes the linear_svm model with the given data but doesnt train it.
%%
%%
initModelNoTrain
(
NumClasses
,
Lambda
,
Delta
,
FitIntercept
)
:-
initModelNoTrain
(
NumClasses
,
Lambda
,
Delta
,
FitIntercept
)
:-
NumClasses
>=
0
,
Lambda
>=
0.0
,
Delta
>=
0.0
,
initModelNoTrainI
(
NumClasses
,
Lambda
,
Delta
,
FitIntercept
).
initModelNoTrainI
(
NumClasses
,
Lambda
,
Delta
,
FitIntercept
).
foreign
(
initModelNoTrain
,
c
,
initModelNoTrainI
(
+
integer
,
+
float32
,
+
float32
,
foreign
(
initModelNoTrain
,
c
,
initModelNoTrainI
(
+
integer
,
+
float32
,
+
float32
,
...
@@ -138,6 +144,7 @@ foreign(computeAccuracy, c, computeAccuracyI( +pointer(float_array), +integer
...
@@ -138,6 +144,7 @@ foreign(computeAccuracy, c, computeAccuracyI( +pointer(float_array), +integer
%% Train the Linear_svm model with the given training data.
%% Train the Linear_svm model with the given training data.
%%
%%
train
(
DataList
,
DataRows
,
LabelsList
,
NumClasses
,
Optimizer
,
ObjValue
)
:-
train
(
DataList
,
DataRows
,
LabelsList
,
NumClasses
,
Optimizer
,
ObjValue
)
:-
NumClasses
>=
0
,
convert_list_to_float_array
(
DataList
,
DataRows
,
array
(
Xsize
,
Xrownum
,
X
)),
convert_list_to_float_array
(
DataList
,
DataRows
,
array
(
Xsize
,
Xrownum
,
X
)),
convert_list_to_float_array
(
LabelsList
,
array
(
Ysize
,
Y
)),
convert_list_to_float_array
(
LabelsList
,
array
(
Ysize
,
Y
)),
trainI
(
X
,
Xsize
,
Xrownum
,
Y
,
Ysize
,
NumClasses
,
Optimizer
,
ObjValue
).
trainI
(
X
,
Xsize
,
Xrownum
,
Y
,
Ysize
,
NumClasses
,
Optimizer
,
ObjValue
).
...
...
This diff is collapsed.
Click to expand it.
src/methods/linear_SVM/linear_SVM_test.pl
+
259
−
24
View file @
1cb6520a
...
@@ -6,50 +6,285 @@
...
@@ -6,50 +6,285 @@
:-
use_module
(
linear_SVM
).
:-
use_module
(
linear_SVM
).
:-
use_module
(
'../../helper_files/helper.pl'
).
:-
use_module
(
'../../helper_files/helper.pl'
).
reset_Model
:-
reset_Model
_NoTrain
:-
initModelNoTrain
(
2
,
0.0001
,
1.0
,
0
).
initModelNoTrain
(
2
,
0.0001
,
1.0
,
0
).
reset_Model_WithTrain
:-
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
,
lbfgs
).
:-
begin_tests
(
lists
).
:-
begin_tests
(
lists
).
%% train tests
%%
test
(
correct_train
)
:-
%% TESTING predicate initModelWithTrain/8
reset_Model
,
%%
convert_list_to_float_array
([
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
,
array
(
Xsize
,
Xrownum
,
X
)),
:-
begin_tests
(
initModelWithTrain
).
convert_list_to_float_array
([
1
,
1
,
0
,
0
],
array
(
Ysize
,
Y
)),
train
(
X
,
Xsize
,
Xrownum
,
Y
,
Ysize
,
2
,
lbfgs
,
Result
),
%% Failure Tests
print
(
Result
).
:-
end_tests
(
lists
).
test
(
linear_SVM_InitModelWithTrain_Negative_NumClasses
,
fail
)
:-
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
,
lbfgs
).
test
(
linear_SVM_InitModelWithTrain_Negative_Lambda
,
fail
)
:-
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
,
lbfgs
).
test
(
linear_SVM_InitModelWithTrain_Negative_Delta
,
fail
)
:-
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
,
lbfgs
).
test
(
linear_SVM_InitModelWithTrain_Wrong_Optimizer_Input
,
[
error
(
domain_error
(
'The given Optimizer is unkown!'
,
wrongInput
),
_
)])
:-
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'
))])
:-
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'
))])
:-
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'
))])
:-
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
).
%% Successful Tests
test
(
linear_SVM_InitModelWithTrain_Normal_Use_LBFGS
)
:-
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
,
lbfgs
).
test
(
linear_SVM_InitModelWithTrain_Normal_Use_PSGD
)
:-
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
,
psgd
).
test
(
linear_SVM_InitModelWithTrain_CSV_Inpupt_LBFGS
)
:-
open
(
'src/data_csv/iris2.csv'
,
read
,
File
),
take_csv_row
(
File
,
skipFirstRow
,
10
,
Data
),
initModelWithTrain
(
Data
,
4
,
[
0
,
1
,
0
,
1
,
1
,
0
,
1
,
1
,
1
,
0
],
2
,
0.000021
,
2.0
,
1
,
lbfgs
).
:-
end_tests
(
initModelWithTrain
).
%%
%% TESTING predicate initModelNoTrain/4
%%
:-
begin_tests
(
initModelNoTrain
).
%% Failure Tests
test
(
linear_SVM_InitModelNoTrain_Negative_NumClasses
,
fail
)
:-
initModelNoTrain
(
-
2
,
0.0001
,
1.0
,
0
).
test
(
linear_SVM_InitModelNoTrain_Negative_Lambda
,
fail
)
:-
initModelNoTrain
(
2
,
-
0.0001
,
1.0
,
0
).
test
(
linear_SVM_InitModelNoTrain_Negative_Delta
,
fail
)
:-
initModelNoTrain
(
2
,
0.0001
,
-
1.0
,
0
).
%% Successful Tests
test
(
linear_SVM_InitModelNoTrain_Normal_Use
)
:-
initModelNoTrain
(
2
,
0.0001
,
1.0
,
0
).
test
(
linear_SVM_InitModelNoTrain_Alternative
)
:-
initModelNoTrain
(
2
,
0.042
,
0.5
,
1
).
:-
end_tests
(
initModelNoTrain
).
%%
%%
%% TESTING predicate
predicate/10
%% TESTING predicate
classify/5
%%
%%
:-
begin_tests
(
predicate
).
:-
begin_tests
(
classify
).
%% Failure Tests
%% Failure Tests
test
(
testDescription
,
[
error
(
domain_error
(
'expectation'
,
culprit
),
_
)])
:-
test
(
linear_SVM_Classify_Before_Train
,
[
error
(
_
,
system_error
(
'Error'
)
)])
:-
reset_Model_No
_
Train
(
perceptron
)
,
reset_Model_NoTrain
,
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
,
_
).
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
(
testDescription2
,
[
error
(
_
,
system_error
(
'The values of the Label have to start at 0 and be >= 0 and < the given numClass!
'
))])
:-
test
(
linear_SVM_Classify_Diffrent_Dims_Than_Train
,
[
error
(
_
,
system_error
(
'Error
'
))])
:-
reset_Model_
No_
Train
(
perceptron
)
,
reset_Model_
With
Train
,
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
,
_
).
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
,
_
,
_
,
_
).
%% Successful Tests
%% Successful Tests
test
(
testDescription3
,
[
true
(
Error
=:=
1
)])
:-
test
(
linear_SVM_Classify_Normal_Use_LBFGS
)
:-
reset_Model_No_Train
(
perceptron
),
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
,
lbfgs
),
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
).
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
,
LabelsList
,
ScoresList
,
_
),
print
(
'\nLabels: '
),
print
(
LabelsList
),
print
(
'\nScores: '
),
print
(
ScoresList
).
test
(
linear_SVM_Classify_Normal_Use_PSGD
)
:-
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
,
psgd
),
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
,
LabelsList
,
ScoresList
,
_
),
print
(
'\nLabels: '
),
print
(
LabelsList
),
print
(
'\nScores: '
),
print
(
ScoresList
).
test
(
linear_SVM_Classify_CSV_Input
)
:-
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
),
take_csv_row
(
File
,
skipFirstRow
,
10
,
Data
),
classify
(
Data
,
4
,
LabelsList
,
ScoresList
,
_
),
print
(
'\nLabels: '
),
print
(
LabelsList
),
print
(
'\nScores: '
),
print
(
ScoresList
).
:-
end_tests
(
classify
).
%%
%% TESTING predicate classifyPoint/2
%%
:-
begin_tests
(
classifyPoint
).
%% Failure Tests
test
(
linear_SVM_ClassifyPoint_Before_Train
,
[
error
(
_
,
system_error
(
'Error'
))])
:-
reset_Model_NoTrain
,
classifyPoint
([
5.1
,
3.5
,
1.4
],
_
).
test
(
linear_SVM_ClassifyPoint_Diffrent_Dims_Than_Train
,
[
error
(
_
,
system_error
(
'Error'
))])
:-
reset_Model_WithTrain
,
classifyPoint
([
5.1
,
3.5
,
1.4
,
4.9
],
_
).
%% Successful Tests
test
(
linear_SVM_ClassifyPoint_Normal_Use_LBFGS
)
:-
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
,
lbfgs
),
classifyPoint
([
5.1
,
3.5
,
1.4
],
Label
),
print
(
'\nLabel: '
),
print
(
Label
).
test
(
linear_SVM_ClassifyPoint_Normal_Use_PSGD
)
:-
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
,
psgd
),
classifyPoint
([
5.1
,
3.5
,
1.4
],
Label
),
print
(
'\nLabel: '
),
print
(
Label
).
test
(
linear_SVM_ClassifyPoint_CSV_Input
)
:-
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
),
take_csv_row
(
File
,
skipFirstRow
,
1
,
Data
),
classifyPoint
(
Data
,
Label
),
print
(
'\nLabel: '
),
print
(
Label
).
:-
end_tests
(
classifyPoint
).
%%
%% TESTING predicate computeAccuracy/4
%%
:-
begin_tests
(
computeAccuracy
).
%% Failure Tests
test
(
linear_SVM_ComputeAccuracy_Before_Train
,
[
error
(
_
,
system_error
(
'Error'
))])
:-
reset_Model_NoTrain
,
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'
))])
:-
reset_Model_WithTrain
,
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'
))])
:-
reset_Model_WithTrain
,
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'
))])
:-
reset_Model_WithTrain
,
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'
))])
:-
reset_Model_WithTrain
,
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
],
_
).
%% Successful Tests
test
(
linear_SVM_ComputeAccuracy_Normal_Use_LBFGS
)
:-
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
,
lbfgs
),
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
],
Accuracy
),
print
(
'\nAccuracy: '
),
print
(
Accuracy
).
test
(
linear_SVM_ComputeAccuracy_Normal_Use_PSGD
)
:-
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
,
psgd
),
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
],
Accuracy
),
print
(
'\nAccuracy: '
),
print
(
Accuracy
).
test
(
linear_SVM_ComputeAccuracy_CSV_Input
)
:-
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
),
take_csv_row
(
File
,
skipFirstRow
,
1
,
Data
),
computeAccuracy
(
Data
,
4
,
[
0
,
1
,
0
,
1
,
1
,
0
,
1
,
1
,
1
,
0
],
Accuracy
),
print
(
'\nAccuracy: '
),
print
(
Accuracy
).
:-
end_tests
(
computeAccuracy
).
%%
%% TESTING predicate train/6
%%
:-
begin_tests
(
train
).
%% Failure Tests
test
(
linear_SVM_Train_Negative_NumClasses
,
fail
)
:-
reset_Model_NoTrain
,
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
,
lbfgs
,
_
).
test
(
linear_SVM_Train_Wrong_Optimizer_Input
,
[
error
(
domain_error
(
'The given Optimizer is unkown!'
,
wrongInput
),
_
)])
:-
reset_Model_NoTrain
,
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'
))])
:-
reset_Model_NoTrain
,
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'
))])
:-
reset_Model_NoTrain
,
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'
))])
:-
reset_Model_NoTrain
,
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
,
_
).
%% Successful Tests
test
(
linear_SVM_Train_Normal_Use_LBFGS
)
:-
reset_Model_NoTrain
,
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
,
lbfgs
,
ObjectiveValue
),
print
(
'\nObjectiveValue: '
),
print
(
ObjectiveValue
).
test
(
linear_SVM_Train_Normal_Use_PSGD
)
:-
reset_Model_NoTrain
,
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
,
psgd
,
ObjectiveValue
),
print
(
'\nObjectiveValue: '
),
print
(
ObjectiveValue
).
test
(
testDescription4
,
[
true
(
Error
=:=
0.9797958971132711
)]
)
:-
test
(
linear_SVM_Train_CSV_Inpupt_LBFGS
)
:-
reset_Model_No
_
Train
(
perceptron
)
,
reset_Model_NoTrain
,
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
).
train
(
Data
,
4
,
[
0
,
1
,
0
,
1
,
1
,
0
,
1
,
1
,
1
,
0
],
2
,
lbfgs
,
ObjectiveValue
),
print
(
'\nObjectiveValue: '
),
print
(
ObjectiveValue
).
:-
end_tests
(
predicate
).
:-
end_tests
(
train
).
run_linear_SVM_tests
:-
run_linear_SVM_tests
:-
run_tests
.
run_tests
.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment