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

Adding emst

parent 466fadee
No related branches found
No related tags found
No related merge requests found
...@@ -5,6 +5,7 @@ all: ...@@ -5,6 +5,7 @@ all:
make -C src/methods/ada_boost splfr=$(SPLFR_PATH) make -C src/methods/ada_boost splfr=$(SPLFR_PATH)
make -C src/methods/bayesian_linear_regression splfr=$(SPLFR_PATH) make -C src/methods/bayesian_linear_regression splfr=$(SPLFR_PATH)
make -C src/methods/dbscan splfr=$(SPLFR_PATH) make -C src/methods/dbscan splfr=$(SPLFR_PATH)
make -C src/methods/emst splfr=$(SPLFR_PATH)
make -C src/methods/kmeans splfr=$(SPLFR_PATH) make -C src/methods/kmeans splfr=$(SPLFR_PATH)
make -C src/methods/lars splfr=$(SPLFR_PATH) make -C src/methods/lars splfr=$(SPLFR_PATH)
make -C src/methods/linear_regression splfr=$(SPLFR_PATH) make -C src/methods/linear_regression splfr=$(SPLFR_PATH)
...@@ -20,6 +21,7 @@ clean: ...@@ -20,6 +21,7 @@ clean:
make -C src/methods/ada_boost clean make -C src/methods/ada_boost clean
make -C src/methods/bayesian_linear_regression clean make -C src/methods/bayesian_linear_regression clean
make -C src/methods/dbscan clean make -C src/methods/dbscan clean
make -C src/methods/emst clean
make -C src/methods/kmeans clean make -C src/methods/kmeans clean
make -C src/methods/lars clean make -C src/methods/lars clean
make -C src/methods/linear_regression clean make -C src/methods/linear_regression clean
......
splfr=/usr/local/sicstus4.7.1/bin/splfr
METHOD_NAME=emst
$(METHOD_NAME).so: $(METHOD_NAME).pl $(METHOD_NAME).cpp
$(splfr) -larmadillo -fopenmp -lmlpack -lstdc++ -cxx --struct $(METHOD_NAME).pl $(METHOD_NAME).cpp ../../helper_files/helper.cpp
clean:
rm $(METHOD_NAME).so
#include <sicstus/sicstus.h>
/* ex_glue.h is generated by splfr from the foreign/[2,3] facts.
Always include the glue header in your foreign resource code.
*/
#include "emst_glue.h"
#include <mlpack/methods/emst/dtb.hpp>
#include <mlpack/core.hpp>
// including helper functions for converting between arma structures and arrays
#include "../../helper_files/helper.hpp"
// 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:
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;
DualTreeBoruvka(data, (naive == 1)).ComputeMST(resultsReturnMat);
// return the Matrix dimensions
*resultsMatColNum = resultsReturnMat.n_cols;
*resultsMatRowNum = resultsReturnMat.n_rows;
// return the Matrix as one long Array
*resultsMatArr = convertToArray(resultsReturnMat);
}
\ No newline at end of file
:- module(emst, [emst/7]).
%% requirements of library(struct)
:- load_files(library(str_decl),
[when(compile_time), if(changed)]).
%% needed for using the array type
:- use_module(library(structs)).
:- use_module('../../helper_files/helper.pl').
%% type definitions for the float array
:- foreign_type
float32 = float_32,
float_array = array(float32).
%% definitions for the connected function
%% TODO:
%% --Input--
%%
%% --Output--
%%
%% --Description--
foreign(emst, c, emst(+pointer(float_array), +integer, +integer, +integer, -pointer(float_array), -integer, -integer)).
%% +integer , +float32, +string
%% [-integer] , [-float32], [-string]
%% matrix input
%% +pointer(float_array), +integer, +integer
%% array input
%% +pointer(float_array), +integer
%% matrix return
%% -pointer(float_array), -integer, -integer
%% array return
%% -pointer(float_array), -integer
%% Defines the functions that get connected from main.cpp
foreign_resource(emst, [emst]).
:- load_foreign_resource(emst).
\ No newline at end of file
:- 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment