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
049c620f
Commit
049c620f
authored
Oct 14, 2022
by
Jakhes
Browse files
Options
Downloads
Patches
Plain Diff
Adding emst tests
parent
703fe7b4
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/methods/emst/emst.cpp
+16
-11
16 additions, 11 deletions
src/methods/emst/emst.cpp
src/methods/emst/emst.pl
+9
-5
9 additions, 5 deletions
src/methods/emst/emst.pl
src/methods/emst/emst_test.pl
+48
-51
48 additions, 51 deletions
src/methods/emst/emst_test.pl
with
73 additions
and
67 deletions
src/methods/emst/emst.cpp
+
16
−
11
View file @
049c620f
...
...
@@ -12,31 +12,36 @@
// some of the most used namespaces
using
namespace
arma
;
using
namespace
mlpack
;
using
namespace
std
;
using
namespace
mlpack
::
emst
;
// TODO:
// input: const MatType & dataset,
// const bool naive = false,
// const MetricType metric = MetricType(),
// arma::mat & results <-
// output:
// description:
// Performs the MST calculation using the Dual-Tree Boruvka algorithm.
//
void
emst
(
float
*
dataMatArr
,
SP_integer
dataMatSize
,
SP_integer
dataMatRowNum
,
SP_integer
naive
,
float
**
resultsMatArr
,
SP_integer
*
resultsMatColNum
,
SP_integer
*
resultsMatRowNum
)
{
// convert the Prolog arrays to arma::mat
mat
data
=
convertArrayToMat
(
dataMatArr
,
dataMatSize
,
dataMatRowNum
);
// create the ReturnMat
mat
resultsReturnMat
;
try
{
DualTreeBoruvka
(
data
,
(
naive
==
1
)).
ComputeMST
(
resultsReturnMat
);
}
catch
(
const
std
::
exception
&
e
)
{
raisePrologSystemExeption
(
e
.
what
());
}
// return the Matrix dimensions
*
resultsMatColNum
=
resultsReturnMat
.
n_cols
;
*
resultsMatRowNum
=
resultsReturnMat
.
n_rows
;
// return the Matrix
as one long Array
*
resultsMatArr
=
convertToArray
(
resultsReturnMat
);
// return the Matrix
returnMatrixInformation
(
resultsReturnMat
,
resultsMatArr
,
resultsMatColNum
,
resultsMatRowNum
);
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/methods/emst/emst.pl
+
9
−
5
View file @
049c620f
:-
module
(
emst
,
[
emst
/
7
]).
:-
module
(
emst
,
[
emst
/
5
]).
%% requirements of library(struct)
:-
load_files
(
library
(
str_decl
),
...
...
@@ -16,7 +16,10 @@
%% definitions for the connected function
%% TODO:
foreign
(
emst
,
c
,
emstI
(
+
pointer
(
float_array
),
+
integer
,
+
integer
,
+
integer
,
-
pointer
(
float_array
),
-
integer
,
-
integer
)).
%% --Input--
%% mat dataset,
%% bool naive => (1)true / (0)false
...
...
@@ -27,9 +30,10 @@
%% --Description--
%% Performs the MST calculation using the Dual-Tree Boruvka algorithm.
%%
foreign
(
emst
,
c
,
emst
(
+
pointer
(
float_array
),
+
integer
,
+
integer
,
+
integer
,
-
pointer
(
float_array
),
-
integer
,
-
integer
)).
emst
(
DataList
,
DataRows
,
Naive
,
ResultsList
,
YCols
)
:-
convert_list_to_float_array
(
DataList
,
DataRows
,
array
(
Xsize
,
Xrows
,
X
)),
emstI
(
X
,
Xsize
,
Xrows
,
Naive
,
Y
,
YCols
,
YRows
),
convert_float_array_to_2d_list
(
Y
,
YCols
,
YRows
,
ResultsList
).
%% Defines the functions that get connected from main.cpp
...
...
This diff is collapsed.
Click to expand it.
src/methods/emst/emst_test.pl
+
48
−
51
View file @
049c620f
:-
module
(
emst_tests
,
[
run_emst_tests
/
0
]).
:-
use_module
(
library
(
plunit
)).
:-
use_module
(
emst
).
:-
use_module
(
'../../helper_files/helper.pl'
).
reset_Model
:-
initModel
(
1
,
0
,
50
,
0.0001
).
:-
begin_tests
(
lists
).
%% alpha tests
test
(
alpha_std_init
)
:-
reset_Model
,
alpha
(
0
).
test
(
alpha_wrong_input
,
fail
)
:-
reset_Model
,
alpha
(
1
).
test
(
alpha_after_train
,
A
=:=
9223372036854775808
)
:-
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
],
3
,
array
(
Xsize
,
Xrownum
,
X
)),
convert_list_to_float_array
([
0.2
,
0.2
,
0.2
,
0.2
],
array
(
Ysize
,
Y
)),
train
(
X
,
Xsize
,
Xrownum
,
Y
,
Ysize
),
alpha
(
A
).
%% train tests
test
(
correct_train
)
:-
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
],
3
,
array
(
Xsize
,
Xrownum
,
X
)),
convert_list_to_float_array
([
0.2
,
0.2
,
0.2
,
0.2
],
array
(
Ysize
,
Y
)),
train
(
X
,
Xsize
,
Xrownum
,
Y
,
Ysize
).
test
(
false_train
,
fail
)
:-
reset_Model
,
convert_list_to_float_array
([],
3
,
array
(
Xsize
,
Xrownum
,
X
)),
convert_list_to_float_array
([
0.2
,
0.2
,
0.2
,
0.2
],
array
(
Ysize
,
Y
)),
train
(
X
,
Xsize
,
Xrownum
,
Y
,
Ysize
).
test
(
false_train2
,
fail
)
:-
reset_Model
,
convert_list_to_float_array
([],
0
,
array
(
Xsize
,
Xrownum
,
X
)),
convert_list_to_float_array
([
0.2
,
0.2
,
0.2
,
0.2
],
array
(
Ysize
,
Y
)),
train
(
X
,
Xsize
,
Xrownum
,
Y
,
Ysize
).
test
(
false_train3
,
fail
)
:-
reset_Model
,
convert_list_to_float_array
([
1
,
2
],
0
,
array
(
Xsize
,
Xrownum
,
X
)),
convert_list_to_float_array
([
0.2
,
0.2
,
0.2
,
0.2
],
array
(
Ysize
,
Y
)),
train
(
X
,
Xsize
,
Xrownum
,
Y
,
Ysize
).
test
(
false_train3
,
fail
)
:-
reset_Model
,
convert_list_to_float_array
([
1
,
2
,
44
,
3
],
3
,
array
(
Xsize
,
Xrownum
,
X
)),
convert_list_to_float_array
([
0.2
,
0.2
,
0.2
,
0.2
],
array
(
Ysize
,
Y
)),
train
(
X
,
Xsize
,
Xrownum
,
Y
,
Ysize
).
test
(
false_train4
)
:-
reset_Model
,
convert_list_to_float_array
([
1
,
2
,
44
,
3
],
2
,
array
(
Xsize
,
Xrownum
,
X
)),
convert_list_to_float_array
([
0.2
,
0.2
,
0.2
,
0.2
],
array
(
Ysize
,
Y
)),
train
(
X
,
Xsize
,
Xrownum
,
Y
,
Ysize
).
:-
end_tests
(
lists
).
\ No newline at end of file
%%
%% TESTING predicate emst/5
%%
:-
begin_tests
(
emst
).
%% Failure Tests
%% Successful Tests
test
(
emst_Direkt_Input_Use
)
:-
emst
([
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
,
ResultsList
,
_
),
print
(
ResultsList
),
emst
([
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
,
[[
2.0
,
3.0
,
0.24494902789592743
],
[
1.0
,
2.0
,
0.30000022053718567
],
[
0.0
,
2.0
,
0.5099020004272461
]],
_
).
test
(
emst_Direkt_Input_Use_Naive
)
:-
emst
([
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
,
ResultsList
,
_
),
print
(
ResultsList
),
emst
([
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
,
[[
2.0
,
3.0
,
0.24494902789592743
],
[
1.0
,
2.0
,
0.30000022053718567
],
[
0.0
,
2.0
,
0.5099020004272461
]],
_
).
test
(
emst_CSV_Input_Use
)
:-
open
(
'/home/afkjakhes/eclipse-workspace/prolog-mlpack-libary/src/data_csv/iris2.csv'
,
read
,
File
),
take_csv_row
(
File
,
skipFirstRow
,
10
,
Data
),
emst
(
Data
,
4
,
0
,
ResultsList
,
_
),
print
(
ResultsList
),
emst
(
Data
,
4
,
0
,
[[
0.0
,
4.0
,
0.14142122864723206
],
[
0.0
,
7.0
,
0.17320498824119568
],
[
1.0
,
9.0
,
0.17320503294467926
],
[
2.0
,
3.0
,
0.24494902789592743
],
[
2.0
,
6.0
,
0.26457515358924866
],
[
3.0
,
8.0
,
0.29999974370002747
],
[
1.0
,
2.0
,
0.30000022053718567
],
[
7.0
,
9.0
,
0.3316626250743866
],
[
0.0
,
5.0
,
0.6164416074752808
]],
_
).
:-
end_tests
(
emst
).
run_emst_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