Skip to content
Snippets Groups Projects
Commit 52368209 authored by Dean Samuel Schmitz's avatar Dean Samuel Schmitz
Browse files

Update documentation

parent d79fa368
Branches
No related tags found
No related merge requests found
......@@ -26,14 +26,14 @@ void initModel(SP_integer centerData, SP_integer scaleData, SP_integer nIterMax,
// input:
// output: double
SP_integer alpha()
double alpha()
{
return regressor.Alpha();
}
// input:
// output: double
SP_integer beta()
double beta()
{
return regressor.Beta();
}
......
:- 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, predict/2, train/0]).
:- 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),
[when(compile_time), if(changed)]).
......@@ -12,117 +23,163 @@
float32 = float_32,
float_array = array(float32).
%% TODO: update Comment docs
%% definitions for the connected function and what there inputs and output arguments are
%% TODO:
%% --Input--
%% bool centerData => (1)true / (0)false => true,
%% bool scaleData => (1)true / (0)false => false,
%% int nIterMax => 50,
%% float32 tol => 1e-4
%%
%% --Output--
%%
%% --Description--
foreign(initModel, c, initModel(+integer, +integer, +integer, +float32)).
%% Should be called before all other predicates!
%% Initiates the Model so now train/5 can be called.
%% Before predict/5 or predictWitStd/7 can be used train/5 has to be called before
%%
foreign(initModel, c, initModel( +integer,
+integer,
+integer, +float32)).
%% TODO:
%% --Input--
%%
%% --Output--
%% float32 alpha
%%
%% --Description--
foreign(alpha, c, alpha([-integer])).
%% Get the precision (or inverse variance) of the gaussian prior.
%% train/5 should be called before.
%%
foreign(alpha, c, alpha([-float32])).
%% TODO:
%% --Input--
%% float32 beta
%%
%% --Output--
%%
%% --Description--
foreign(beta, c, beta([-integer])).
%% Get the precision (or inverse variance) beta of the model.
%% train/5 should be called before.
%%
foreign(beta, c, beta([-float32])).
%% TODO:
%% --Input--
%%
%% --Output--
%% vec responsesOffset
%%
%% --Description--
%% Get the mean vector computed on the features over the training points.
%%
foreign(dataOffset, c, dataOffset(-integer, [-pointer(float_array)])).
%% TODO:
%% --Input--
%%
%% --Output--
%% vec dataOffset
%%
%% --Description--
%% Get the vector of standard deviations computed on the features over the training points.
%%
foreign(dataScale, c, dataScale(-integer, [-pointer(float_array)])).
%% TODO:
%% --Input--
%%
%% --Output--
%% vec omega
%%
%% --Description--
%% Get the solution vector.
%%
foreign(omega, c, omega(-integer, [-pointer(float_array)])).
%% TODO:
%% --Input--
%% mat points
%%
%% --Output--
%% vec predictions
%%
%% --Description--
foreign(predict, c, predict(+pointer(float_array), +integer, +integer, -pointer(float_array), -integer)).
%% Predict yi for each data point in the given data matrix using the currently-trained Bayesian Ridge model.
%%
foreign(predict, c, predict( +pointer(float_array), +integer, +integer,
-pointer(float_array), -integer)).
%% TODO:
%% --Input--
%% mat points
%%
%% --Output--
%% vec predictions,
%% vec std
%%
%% --Description--
foreign(predictWithStd, c, predictWithStd(+pointer(float_array), +integer, +integer, -pointer(float_array), -integer, -pointer(float_array), -integer)).
%% Predict yi and the standard deviation of the predictive posterior distribution for each data point in the given data matrix, using the currently-trained Bayesian Ridge estimator.
%%
foreign(predictWithStd, c, predictWithStd( +pointer(float_array), +integer, +integer,
-pointer(float_array), -integer,
-pointer(float_array), -integer)).
%% TODO:
%% --Input--
%% mat data,
%% vec responses
%%
%% --Output--
%% float32 rmse
%%
%% --Description--
foreign(rmse, c, rmse(+pointer(float_array), +integer, +integer, +pointer(float_array), +integer, [-integer])).
%% Compute the Root Mean Square Error between the predictions returned by the model and the true responses.
%%
foreign(rmse, c, rmse( +pointer(float_array), +integer, +integer,
+pointer(float_array), +integer,
[-integer])).
%% TODO:
%% --Input--
%% mat data,
%% vec responses
%%
%% --Output--
%%
%% --Description--
foreign(train, c, train(+pointer(float_array), +integer, +integer, +pointer(float_array), +integer)).
%% Run BayesianLinearRegression.
%% The input matrix (like all mlpack matrices) should be column-major – each column is an observation and each row is a dimension.
%%
foreign(train, c, train( +pointer(float_array), +integer, +integer,
+pointer(float_array), +integer)).
%% TODO:
%% --Input--
%%
%% --Output--
%% float32 variance
%%
%% --Description--
%% Get the estimate variance.
%% train/5 should be called before.
%%
foreign(variance, c, variance([-integer])).
%% Defines what functions should be connected from main.cpp
foreign_resource(bayesian_linear_regression, [initModel, alpha, beta, dataOffset, dataScale, omega, predict, predictWithStd, rmse, train, variance]).
foreign_resource(bayesian_linear_regression, [ initModel,
alpha,
beta,
dataOffset,
dataScale,
omega,
predict,
predictWithStd,
rmse,
train,
variance]).
:- load_foreign_resource(bayesian_linear_regression).
%% 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) :-
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)),
predictWithStd(X, Xsize,Xrownum, Predic, PredicSize, Std, StdSize),
convert_float_array_to_list(Predic, PredicSize, PredictList),
convert_float_array_to_list(Std, StdSize, StdList).
%% Trains the model with the given data and targets
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([0.2,0.2,0.2,0.2], array(Ysize, Y)),
train(X,Xsize, Xrownum,Y, Ysize).
......@@ -189,20 +189,3 @@ SP_integer train(float *dataArr, SP_integer dataSize, SP_integer dataRowNum, flo
// run the model function
return regressor.Train(data, responses, betaVec, (transposeData == 1));
}
\ No newline at end of file
// input: const arma::mat &data, const arma::rowvec &responses, const bool transposeData
// output: double minimum cost error
SP_integer trainNoBetaReturn(float *dataArr, SP_integer dataSize, SP_integer dataRowNum, float *responsesArr, SP_integer responsesSize, SP_integer transposeData)
{
if(dataSize / dataRowNum != responsesSize)
{
cout << "Target dim doesnt fit to the Data dim" << endl;
return 0;
}
// convert the Prolog arrays to arma::rowvec and arma::mat
rowvec responses = convertArrayToRowvec(responsesArr, responsesSize);
mat data = convertArrayToMat(dataArr, dataSize, dataRowNum);
// run the model function
return regressor.Train(data, responses, (transposeData == 1));
}
:- module(lars, [initModelNoDataNoGram/4, initModelNoDataWithGram/7, initModelWithDataNoGram/10, initModelWithDataWithGram/13, activeSet/2,beta/2, betaPath/3, computeError/7, lambdaPath/2, matUtriCholFactor/3, predict/6, train/9, trainNoBetaReturn/7]).
:- module(lars, [ initModelNoDataNoGram/4,
initModelNoDataWithGram/7,
initModelWithDataNoGram/10,
initModelWithDataWithGram/13,
activeSet/2,
beta/2,
betaPath/3,
computeError/7,
lambdaPath/2,
matUtriCholFactor/3,
predict/6,
train/9]).
:- load_files(library(str_decl),
[when(compile_time), if(changed)]).
......@@ -14,7 +25,7 @@
%% definitions for the connected function and what there inputs and output arguments are
%% TODO:
%% --Input--
%%
%% --Output--
......@@ -110,16 +121,19 @@ foreign(predict, c, predict(+pointer(float_array), +integer, +integer, -pointer(
%% --Description--
foreign(train, c, train(+pointer(float_array), +integer, +integer, +pointer(float_array), +integer, -pointer(float_array), -integer, +integer, [-integer])).
%% TODO:
%% --Input--
%%
%% --Output--
%%
%% --Description--
foreign(trainNoBetaReturn, c, trainNoBetaReturn(+pointer(float_array), +integer, +integer, +pointer(float_array), +integer, +integer, [-integer])).
%% Defines what functions should be connected from main.cpp
foreign_resource(lars, [initModelNoDataNoGram, initModelNoDataWithGram, initModelWithDataNoGram, initModelWithDataWithGram, activeSet, beta, betaPath, computeError, lambdaPath, matUtriCholFactor, predict, train, trainNoBetaReturn]).
foreign_resource(lars, [initModelNoDataNoGram,
initModelNoDataWithGram,
initModelWithDataNoGram,
initModelWithDataWithGram,
activeSet,
beta,
betaPath,
computeError,
lambdaPath,
matUtriCholFactor,
predict,
train]).
:- load_foreign_resource(lars).
:- module(new_method, [function/1]).
%% requirements of library(struct)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment