4.1. Training Module
Figure 2 presents the Training Module (TM) used to obtain the probabilities
and
, according to Expression (
1). Therefore, at each
n-th time sample,
, the TM receives as input the vector of attributes
, described in (
2), and the
k-th class,
, for the respective vector of attributes.
Figure 3 details the TM modules. As can be seen, it is constituted by two: the Class Probability Module (CPM) and the Attribute Probability Module (APM). Note that the APM is replicated
N times for parallel processing. Hence, at each
n-th time sample, the CPM receives one
value, which is used for calculating the probabilities,
, and the occurrence number of each
k-th class,
. Meanwhile, each
i-th
receives as input the
i-th attribute,
, the
k-th class,
, and its occurrence number,
, to obtain the probabilities
. Besides, it is important to mention that each
i-th attribute is represented by a
j-th possible value, in which
is the maximum number of distinct values assumed by its attribute.
Figure 4 shows the internal structure of the CPM. Firstly, at each
n-th time sample, the
k-th class,
, is compared with the remaining classes of the dataset (
), through comparator circuits. Besides, note that the classes are represented in the architecture as constant values. Secondly, the comparators output the bit 1 if the classes are equal; otherwise, they output the bit 0. Thirdly, the counter increments its value by 1 every time sample the comparator outputs the bit 1. Thereby, the counter defines the occurrence of each class,
, and propagates these values to every
. Lastly, each
k-th
is multiplied by
for obtaining the probability of occurrence of each
k-th class,
, according to Expression (
3). The calculated probabilities are stored in Registers (R) and provided as output from the CPM.
Meanwhile, each
i-th
is performed in parallel, and its internal structure is shown in
Figure 5. As can be observed, each
i-th
receives as input the
i-th attribute,
, the
k-th class,
, and its occurrence,
. Initially,
is concatenated to
by the
block, generating a
value. This value represents the occurrence of a
k-th class for an
i-th attribute with a
j-th value.
Secondly, for each possible
value, there is a comparator block. Similar to the submodules in the CPM, the comparator outputs the bit 1 according to
Subsequently, the counter submodule (
) increases its value by 1 every
n-th time sample the comparator output is equal to 1. Hence, the counter defines the total occurrence of each
, which is stored in a Register (R).
Thirdly, the output of each counter has to be divided by the k-th related to . Due to the hardware complexity of performing division circuits that provide the decimal values of the result, a multiplier was added before and after the division block. Therefore, the counter output is multiplied by 1000, divided by , and finally, multiplied by .
Lastly, to avoid the Naive Bayes zero-frequency problem, when , logic OR gates were added after the last multiplier blocks. The OR gates receive as input the multiplier value and a constant , which in turn has the smallest possible value that can be represented for the data precision defined, e.g., . Thus, the probabilities of having a value equal to zero are replaced by the value of . The outputs of the logic gates, i.e., the probabilities , are stored in Registers (R) and provided as the outputs of the module. At the end of this procedure, the NB training step is complete, and all the values of and are available.
4.2. Inference Module
The NB inference process consists of classifying a sample
according to (
4). For this purpose, it is necessary to calculate the probability
, defined on Expression (
3).
Figure 6 shows the Inference Module (IM) developed to perform this process. As can be seen, there is one submodule for each
k-th
, and it receives as inputs the probabilities
from the TM and the
N samples,
.
Figure 7 shows the internal structure of each
k-th
submodule. As illustrated, there are
N 15 bit-wide LUTs, of depth
, where each stores all
values. The sample input value,
, is used as the LUT address to select its corresponding probability,
. Subsequently, the probabilities
addressed in each
i-th LUT are multiplied through a tree of multipliers, and in the last multiplier of the tree, the result is multiplied by the
k-th probability
, thus obtaining the value of
, according to (
3).
According to (
4), the decision process of the class corresponding to the sample under evaluation consists of selecting the highest probability
. This process is performed by a relational circuit that compares the
values from all
K submodules of the IM and outputs the class
related to the highest probability value calculated, therefore completing the inference process.