LibCapy - predictor

Parent class and structures for the predictor classes.

Macros:

PredictorEvaluation, class to memorise the result of evaluation of a predictor

Overall accuracy For categorical predictor it is the percentage of correct answers (in [0.0, 1.0]). For numerical predictor it is the MAE (mean absolute error) double accuracy;

Confusion matrix, such as confusionMatrix[i * n + j] is the number of times the i-th category has been predicted as the j-th category, where n is the number of possible categories size_t* confusionMatrix;

Return the evaluated accuracy of the predictor

Output and side effect(s):

Return the accuracy (in [0, 1]). double (*getAccuracy)(void);

Return the evaluated fitness of the predictor

Output and side effect(s):

Return the fitness (in [0, 1]). double (*getFitness)(void);

Predictor, parent class for all predictors

Index of the predicted output in the dataset (default: 0) size_t iOutput;

Type of predictor (default: categorical) CapyPredictorType type;

Type of feature scaling (default: normalise) CapyPredictorFeatureScaling featureScaling

Number of inputs size_t nbInput;

Train the predictor on a dataset

Input argument(s):

dataset: the dataset

Output and side effect(s):

The predictor is trained.

Exception(s):

May raise CapyExc_UnsupportedFormat void (*train)(CapyDataset const* const dataset);

Predict an input

Input argument(s):

inp: the input

Output and side effect(s):

Return the prediction CapyPredictorPrediction (*predict)(CapyVec const* const inp);

Evaluate the predictor on a dataset

Input argument(s):

dataset: the dataset

Output and side effect(s):

Return the evaluation of the predictor. CapyPredictorEvaluation* (*evaluate)(CapyDataset const* const dataset);

Convert a CapyDataset into a CapyMat usable by the predictor

Input argument(s):

dataset: the dataset to be converted

Output and side effect(s):

Return a matrix formatted as necessary CapyMat (*cvtDatasetToMat)( CapyDataset const* const dataset);

Clone a predictor

Output and side effect(s):

Return a clone of the predictor. void* (*clone)(void);

Export the predictor as a C function

Input argument(s):

stream: the stream where to export
name: the name of the function
dataset: the training dataset

Output and side effect(s):

A ready to use C function implementing the predictor is written on the stream. See the comment exported with the function to know how to use the exported function. void (*exportToCFun)( FILE* const stream, char const* const name, CapyDataset const* const dataset);

Export the predictor as a HTML web app

Input argument(s):

stream: the stream where to export
title: the title of the web app
dataset: the training dataset
expectedAccuracy: the expected accuracy of the predictor (in [0,1])

Output and side effect(s):

A ready to use web app implementing the predictor is written on the stream. void (*exportToHtml)( FILE* const stream, char const* const title, CapyDataset const* const dataset, double const expectedAccuracy);

Preprocess the input features in the training data

Input argument(s):

mat: the training data
dataset: the training dataset

Output and side effect(s):

'mat' is updated void (*scaleTrainingInputFeatures)( CapyMat* const mat, CapyDataset const* const dataset);

Preprocess the input features in the input vector

Input argument(s):

inp: the input vector

Output and side effect(s):

'inp' is updated void (*scaleInputFeatures)(CapyVec* const inp);

Export the input feature scaling as C code Input: stream: the stream on which the code is exported Output: The scaling code is written to the stream (to be used by the exportToCFun method. void (*exportScaleInputToCFun)(FILE* const stream);

Save the predictor to a stream Input: stream: the stream on which to save Output: The predictor data are saved on the stream void (*save)(FILE* const stream);

Enumerations:

Type of predictor

Types of input features scaling minMaxNormalization: [min,max]->[0,1] minMaxNormalizationSym: [min,max]->[-1,1] meanNormalization: (x - avg) / (max - min) standardization: (x - avg) / sigma

Typedefs:

CapyPredictorEvaluation declaration

Predictor structure

Struct CapyPredictorPrediction :

Struct CapyPredictorPrediction's properties:

Predicted category/value

Confidence of the prediction (in [0,+inf[, the higher the more confident)

Struct CapyPredictorPrediction's methods:

None.

Functions:

Create a CapyPredictorEvaluation

Output and side effect(s):

Return a CapyPredictorEvaluation

Allocate memory for a new CapyPredictorEvaluation and create it

Output and side effect(s):

Return a CapyPredictorEvaluation

Exception(s):

May raise CapyExc_MallocFailed.

Free the memory used by a CapyPredictorEvaluation* and reset '*that' to NULL

Input argument(s):

that: a pointer to the CapyPredictorEvaluation to free

Create a CapyPredictor

Input argument(s):

type: type of predictor

Output and side effect(s):

Return a CapyPredictor

Allocate memory for a new CapyPredictor and create it

Input argument(s):

type: type of predictor

Output and side effect(s):

Return a CapyPredictor

Exception(s):

May raise CapyExc_MallocFailed.

Free the memory used by a CapyPredictor* and reset '*that' to NULL

Input argument(s):

that: a pointer to the CapyPredictor to free

2024-03-20
in LibCapy,
0 views
Copyright 2021-2024 Baillehache Pascal