namespace classification

// namespaces

namespace xf::data_analytics::classification::internal

// classes

template <
    typename MType,
    int D,
    int DDepth,
    int K,
    int KDepth,
    RAMType RAMWeight,
    RAMType RAMIntercept
    >
class logisticRegressionPredict

decisionTreePredict

#include "xf_data_analytics/classification/decision_tree_predict.hpp"
template <
    typename MType,
    unsigned int WD,
    unsigned int MAX_FEA_NUM,
    unsigned int MAX_TREE_DEPTH = 20,
    unsigned MAX_CAT_BITS = 8
    >
void decisionTreePredict (
    hls::stream <ap_uint <WD>> dstrm_batch [MAX_FEA_NUM],
    hls::stream <bool>& estrm_batch,
    hls::stream <ap_uint <512>>& treeStrm,
    hls::stream <bool>& treeTag,
    hls::stream <ap_uint <MAX_CAT_BITS>>& predictionsStrm,
    hls::stream <bool>& predictionsTag
    )

decisionTreePredict, Top function of Decision Tree Predict.

This function first loads decision tree (the corresponding function : getTree) from treeStrm Then, read sample one by one from dstrm_batch, and output its category id into predictionsStrm streams

Note that the treeStrm is a 512-bit stream, and each 512 bits include two nodes. In each 512-bit confirm the range(0,71) is node[i].nodeInfo and range(256,327) is node[i+1].nodeInfo the range(192,255) is node[i].threshold and range(448,511) is node[i+1].threshold For detailed info of Node struct, can refer “decision_tree.hpp” Samples in input sample stream should be converted into ap_uint<WD> from MType

Parameters:

MType The data type of sample
WD The width of data type MType, can get by sizeof(MType)
MAX_FEA_NUM The max feature num function can support
MAX_TREE_DEPTH The max tree depth function can support
MAX_CAT_BITS The category max bit number
dstrm_batch Input data streams of ap_uint<WD>
estrm_batch End flag stream for input data
treeStrm Decision tree streams
treeTag End flag stream for decision tree nodes
predictionsStrm Output data streams
predictionsTagStrm End flag stream for output

axiVarColToStreams

#include "xf_data_analytics/classification/decision_tree_train.hpp"
template <
    int _BurstLen = 32,
    int _WAxi = 512,
    int _WData = 64
    >
void axiVarColToStreams (
    ap_uint <_WAxi>* ddr,
    const ap_uint <32> offset,
    const ap_uint <32> rows,
    ap_uint <32> cols,
    hls::stream <ap_uint <_WData>> dataStrm [_WAxi/_WData],
    hls::stream <bool>& eDataStrm
    )

Loading table from AXI master to stream. Table should be row based storage of identical datawidth.

Parameters:

_BurstLen burst length of AXI buffer, default is 32.
_WAxi width of AXI port, must be multiple of datawidth, default is 512.
_WData datawith, default is 64.
ddr input AXI port
offset offset(in _WAxi bits) to load table.
rows Row number of table
cols Column number of table Output streams of _WAxi/_WData channels end flag of output stream.

naiveBayesTrain

#include "xf_data_analytics/classification/naive_bayes.hpp"
template <
    int DT_WIDTH = 32,
    int WL = 3,
    typename DT = unsigned int
    >
void naiveBayesTrain (
    const int num_of_class,
    const int num_of_term,
    hls::stream <ap_uint <64>> i_data_strm [1<< WL],
    hls::stream <bool> i_e_strm [1<< WL],
    hls::stream <int>& o_terms_strm,
    hls::stream <ap_uint <64>> o_data0_strm [1<< WL],
    hls::stream <ap_uint <64>> o_data1_strm [1<< WL]
    )

naiveBayesTrain, top function of multinomial Naive Bayes Training.

This function will firstly load train dataset from the i_data_strm, then counte the frequency for each hit term. After scaning all sample, the likehood probability matrix and prior probability will be output from two independent stream

Parameters:

DT_WIDTH the width of type DT, in bits
WL the width of bit to enable dispatcher, only 3 is supported so far
DT the data type of internal counter for terms, can be 32/64-bit integer, float or double
num_of_class the number of class in sample dataset, should be exactly same with real dataset
num_of_term the number of terms, must be larger than the number of feature, and num_of_class * num_of_term <= (1 << (20-WL)) must be satisfied.
i_data_strm input data stream of ap_uint<64> in multiple channel
i_e_strm end flag stream for each input data channel
o_terms_strm the output number of statistic feature
o_data0_strm the output likehood matrix
o_data1_strm the output prior probablity vector

naiveBayesPredict

#include "xf_data_analytics/classification/naive_bayes.hpp"
template <
    int CH_NM,
    int GRP_NM
    >
void naiveBayesPredict (
    const int num_of_class,
    const int num_of_term,
    hls::stream <ap_uint <64>>& i_theta_strm,
    hls::stream <ap_uint <64>>& i_prior_strm,
    hls::stream <ap_uint <32>> i_data_strm [CH_NM],
    hls::stream <bool>& i_e_strm,
    hls::stream <ap_uint <10>>& o_class_strm,
    hls::stream <bool>& o_e_strm
    )

naiveBayesPredict, top function of multinomial Naive Bayes Prediction

The function will firstly load the train model into on-chip memory, and calculate the classfication results for each sample using argmax function.

Parameters:

CH_NM the number of channel for input sample data, should be power of 2
GRP_NM the unroll factor for handling the classes simultaneously, must be power of 2 in 1~256
num_of_term the number of class, should be exactly same with the input dataset
num_of_term the number of feature, should be exactly same with the input dataset
i_theta_strm the input likehood probability stream, [num_of_class][num_of_term]
i_prior_strm the input prior probability stream, [num_of_class]
i_data_strm the input of test data stream
i_e_strm end flag stream for i_data_strm
o_class_strm the prediction result for each input sample
o_e_strm end flag stream for o_class_strm

svmPredict

#include "xf_data_analytics/classification/svm_predict.hpp"
template <
    typename MType,
    unsigned WD,
    unsigned StreamN,
    unsigned SampleDepth
    >
void svmPredict (
    const int cols,
    hls::stream <MType> sample_strm [StreamN],
    hls::stream <bool>& e_sample_strm,
    hls::stream <ap_uint <512>>& weight_strm,
    hls::stream <bool>& eTag,
    hls::stream <ap_uint <1>>& predictionsStrm,
    hls::stream <bool>& predictionsTag
    )

svmPredict, Top function of svm Predict.

This function first loads weight (the corresponding function : getWeight) from weight_strm Then, read sample from sample_strm, and output its classification id into predictionsStrm streams

Parameters:

MType The data type of sample
WD The width of data type MType, can get by sizeof(MType)
StreamN The stream number of input sample stream vector
SampleDepth stream depth number of one input sample
cols colum number of input data sample
sample_strm Input data streams of MType
e_sample_strm End flag stream for input data
weight_strm weight streams
eTag End flag stream for weight streams
predictionsStrm Output data streams
predictionsTagStrm End flag stream for output