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
308d0afc
Commit
308d0afc
authored
2 years ago
by
Jakhes
Browse files
Options
Downloads
Patches
Plain Diff
Moving all extra predicates into a helper file
parent
1fe22107
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/helper_files/helper.pl
+60
-0
60 additions, 0 deletions
src/helper_files/helper.pl
src/methods/bayesian_linear_regression/bayesian_linear_regression.pl
+5
-51
5 additions, 51 deletions
.../bayesian_linear_regression/bayesian_linear_regression.pl
with
65 additions
and
51 deletions
src/helper_files/helper.pl
0 → 100644
+
60
−
0
View file @
308d0afc
:-
module
(
helper
,
[
convert_list_to_float_array
/
3
,
convert_list_to_float_array
/
2
,
fill_float_array
/
3
,
convert_float_array_to_list
/
3
,
convert_float_array_to_list
/
4
,
len
/
2
,
convert_record_to_arr
/
2
,
take_csv_row
/
1
]).
:-
use_module
(
library
(
structs
)).
:-
use_module
(
library
(
csv
)).
%% Functions for editing float arrays
convert_list_to_float_array
(
Arr
,
Row_num
,
array
(
Size
,
Row_num
,
Mem
))
:-
len
(
Arr
,
Size
),
Size
>=
Row_num
,
Row_num
>
0
,
mod
(
Size
,
Row_num
)
=:=
0
,
new
(
float_array
,
Size
,
Mem
),
fill_float_array
(
Arr
,
0
,
Mem
).
convert_list_to_float_array
(
Arr
,
array
(
Size
,
Mem
))
:-
len
(
Arr
,
Size
),
new
(
float_array
,
Size
,
Mem
),
fill_float_array
(
Arr
,
0
,
Mem
).
fill_float_array
([],
_
,
_
):-
!.
fill_float_array
([
H
|
Tail
],
Index
,
Mem
)
:-
put_contents
(
Mem
,
Index
,
H
),
New_index
is
Index
+
1
,
fill_float_array
(
Tail
,
New_index
,
Mem
).
convert_float_array_to_list
(
Mem
,
Count
,
Out
)
:-
convert_float_array_to_list
(
Mem
,
0
,
Count
,
Out
).
convert_float_array_to_list
(
_
,
Count
,
Count
,
[])
:-
!.
convert_float_array_to_list
(
Mem
,
Index
,
Count
,
[
Val
|
Rest
])
:-
NewIndex
is
Index
+
1
,
convert_float_array_to_list
(
Mem
,
NewIndex
,
Count
,
Rest
),
get_contents
(
Mem
,
Index
,
Val
).
%% returns the length of a list
len
([],
0
):-
!.
len
([
_
|
Tail
],
List_L
)
:-
len
(
Tail
,
Tail_L
),
List_L
is
Tail_L
+
1
.
%% Funktions for reading the csv Files
%% take the elements in a csv record and put them in a list
convert_record_to_arr
([],
[]):-
!.
convert_record_to_arr
([
float
(
Num
,
_
)|
Tail
],
[
Num
|
Rest
])
:-
convert_record_to_arr
(
Tail
,
Rest
).
convert_record_to_arr
([
string
(
_
)|
Tail
],
Rest
)
:-
convert_record_to_arr
(
Tail
,
Rest
).
take_csv_row
(
Out
)
:-
open
(
'/home/afkjakhes/eclipse-workspace/Prolog mlpack Libary/iris.csv'
,
read
,
A
),
read_record
(
A
,
_
),
read_record
(
A
,
Rec
),
convert_record_to_arr
(
Rec
,
Out
).
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/methods/bayesian_linear_regression/bayesian_linear_regression.pl
+
5
−
51
View file @
308d0afc
:-
module
(
bayesian_linear_regression
,
[
initModel
/
4
,
alpha
/
1
,
beta
/
1
,
dataOffset
/
2
,
dataScale
/
2
,
omega
/
2
,
predict
/
5
,
predictWithStd
/
7
,
rmse
/
6
,
train
/
5
,
variance
/
1
]).
:-
load_files
(
library
(
str_decl
),
:-
load_files
(
library
(
str_decl
),
[
when
(
compile_time
),
if
(
changed
)]).
[
when
(
compile_time
),
if
(
changed
)]).
%% needed for using the array type and for reading from csv
%% needed for using the array type and for reading from csv
:-
use_module
(
library
(
structs
)).
:-
use_module
(
library
(
structs
)).
:-
use_module
(
library
(
csv
)).
:-
use_module
(
library
(
csv
)).
:-
use_module
(
'/home/afkjakhes/git/prolog-mlpack-libary/src/helper_files/helper'
).
%% type definitions for the float array
%% type definitions for the float array
:-
foreign_type
:-
foreign_type
...
@@ -29,60 +32,10 @@ foreign_resource(bayesian_linear_regression, [initModel, alpha, beta, dataOffset
...
@@ -29,60 +32,10 @@ foreign_resource(bayesian_linear_regression, [initModel, alpha, beta, dataOffset
:-
load_foreign_resource
(
bayesian_linear_regression
).
:-
load_foreign_resource
(
bayesian_linear_regression
).
%% Functions for editing float arrays
convert_list_to_float_array
(
Arr
,
Row_num
,
array
(
Size
,
Row_num
,
Mem
))
:-
len
(
Arr
,
Size
),
new
(
float_array
,
Size
,
Mem
),
fill_float_array
(
Arr
,
0
,
Mem
).
convert_list_to_float_array
(
Arr
,
array
(
Size
,
Mem
))
:-
len
(
Arr
,
Size
),
new
(
float_array
,
Size
,
Mem
),
fill_float_array
(
Arr
,
0
,
Mem
).
fill_float_array
([],
_
,
_
):-
!.
fill_float_array
([
H
|
Tail
],
Index
,
Mem
)
:-
put_contents
(
Mem
,
Index
,
H
),
New_index
is
Index
+
1
,
fill_float_array
(
Tail
,
New_index
,
Mem
).
convert_float_array_to_list
(
Mem
,
Count
,
Out
)
:-
convert_float_array_to_list
(
Mem
,
0
,
Count
,
Out
).
convert_float_array_to_list
(
_
,
Count
,
Count
,
[])
:-
!.
convert_float_array_to_list
(
Mem
,
Index
,
Count
,
[
Val
|
Rest
])
:-
NewIndex
is
Index
+
1
,
convert_float_array_to_list
(
Mem
,
NewIndex
,
Count
,
Rest
),
get_contents
(
Mem
,
Index
,
Val
).
%% Funktions for reading the csv Files
%% returns the length of a list
len
([],
0
):-
!.
len
([
_
|
Tail
],
List_L
)
:-
len
(
Tail
,
Tail_L
),
List_L
is
Tail_L
+
1
.
%% take the elements in a csv record and put them in a list
convert_record_to_arr
([],
[]):-
!.
convert_record_to_arr
([
float
(
Num
,
_
)|
Tail
],
[
Num
|
Rest
])
:-
convert_record_to_arr
(
Tail
,
Rest
).
convert_record_to_arr
([
string
(
_
)|
Tail
],
Rest
)
:-
convert_record_to_arr
(
Tail
,
Rest
).
take_csv_row
(
Out
)
:-
open
(
'/home/afkjakhes/eclipse-workspace/Prolog mlpack Libary/iris.csv'
,
read
,
A
),
read_record
(
A
,
_
),
read_record
(
A
,
Rec
),
convert_record_to_arr
(
Rec
,
Out
).
%% Some funktions that use the BayesianLinearRegression
%% Some funktions that use the BayesianLinearRegression
%% First trains the model and then tries to predict the targets and the std for the given data
predict
(
PredictList
,
StdList
)
:-
predict
(
PredictList
,
StdList
)
:-
train
,
train
,
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
([
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
)),
...
@@ -90,6 +43,7 @@ predict(PredictList, StdList) :-
...
@@ -90,6 +43,7 @@ predict(PredictList, StdList) :-
convert_float_array_to_list
(
Predic
,
PredicSize
,
PredictList
),
convert_float_array_to_list
(
Predic
,
PredicSize
,
PredictList
),
convert_float_array_to_list
(
Std
,
StdSize
,
StdList
).
convert_float_array_to_list
(
Std
,
StdSize
,
StdList
).
%% Trains the model with the given data and targets
train
:-
train
:-
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
([
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
)),
convert_list_to_float_array
([
0.2
,
0.2
,
0.2
,
0.2
],
array
(
Ysize
,
Y
)),
...
...
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