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

Adding MeanShift to project

parent b653d455
No related branches found
No related tags found
No related merge requests found
......@@ -8,6 +8,7 @@ all:
make -C src/methods/ada_boost splfr=$(SPLFR_PATH)
make -C src/methods/kmeans splfr=$(SPLFR_PATH)
make -C src/methods/dbscan splfr=$(SPLFR_PATH)
make -C src/methods/mean_shift splfr=$(SPLFR_PATH)
clean:
make -C src/methods/bayesian_linear_regression clean
......@@ -16,3 +17,4 @@ clean:
make -C src/methods/ada_boost clean
make -C src/methods/kmeans clean
make -C src/methods/dbscan clean
make -C src/methods/mean_shift clean
splfr=/usr/local/sicstus4.7.1/bin/splfr
METHOD_NAME=mean_shift
$(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 "mean_shift_glue.h"
#include <mlpack/methods/mean_shift/mean_shift.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::meanshift;
// TODO: adding support for different Kernels
//
// input: const double radius = 0,
// const size_t maxIterations = 1000,
// const KernelType kernel = KernelType()
//
// const MatType & data,
// arma::Row< size_t > & assignments,
// arma::mat & centroids,
// bool forceConvergence = true,
// bool useSeeds = true
// output:
// description:
void meanShift(double radius, SP_integer maxIterations, float *dataMatArr, SP_integer dataMatSize, SP_integer dataMatRowNum, float **assignmentsArr, SP_integer *assignmentsArrSize,
float **centroidsMatArr, SP_integer *centroidsMatColNum, SP_integer *centroidsMatRowNum, SP_integer forceConvergence, SP_integer useSeeds)
{
// convert the Prolog arrays to arma::mat
mat data = convertArrayToMat(dataMatArr, dataMatSize, dataMatRowNum);
// get the ReturnVector
arma::Row<size_t> toReturnVector;
// get the ReturnMat
mat toReturnMat;
MeanShift<>(radius, maxIterations).Cluster(data, toReturnVector, toReturnMat, (forceConvergence == 1), (useSeeds == 1));
// return the Vector lenght
*assignmentsArrSize = toReturnVector.n_elem;
// return the Vector as Array
*assignmentsArr = convertToArray(toReturnVector);
// return the Matrix dimensions
*centroidsMatColNum = toReturnMat.n_cols;
*centroidsMatRowNum = toReturnMat.n_rows;
// return the Matrix as one long Array
*centroidsMatArr = convertToArray(toReturnMat);
}
:- module(mean_shift, [meanShift/12]).
%% 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: double radius >0
%% int maxIterations
%% mat data data(float_array), dataSize, dataRowNum
%% bool forceConvergence (1)true / (0)false
%% bool useSeeds (1)true / (0)false
%%
%% output: vec assignments assign(float_array), assignSize
%% mat centroids cent(float_array), centColNum, centRowNum
%% description:
foreign(meanShift, c, meanShift(+float32, +integer, +pointer(float_array), +integer, +integer, -pointer(float_array), -integer,
-pointer(float_array), -integer, -integer, +integer, +integer)).
%% Defines the functions that get connected from main.cpp
foreign_resource(mean_shift, [meanShift]).
:- load_foreign_resource(mean_shift).
\ No newline at end of file
:- use_module(library(plunit)).
:- use_module(mean_shift).
:- use_module('../../helper_files/helper.pl').
:- begin_tests(lists).
test(meanShift) :-
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)),
meanShift(1, 1000, X, Xsize, Xrownum, Assign, Assignsize, Centroids, Centroidscolnum, Centroidsrownum, 0, 0),
print(Assignsize),
convert_float_array_to_list(Assign, Assignsize, ResultsAssign),
print(ResultsAssign),
print(Centroidscolnum),
convert_float_array_to_2d_list(Centroids, Centroidscolnum, Centroidsrownum, Results),
print(Results).
:- 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