PocketSphinx  5.0.0 A small speech recognizer
logmath.h File Reference

Fast integer logarithmic addition operations. More...

#include <pocketsphinx/export.h>
#include <pocketsphinx/prim_type.h>

Go to the source code of this file.

## Typedefs

typedef struct logmath_s logmath_t

## Detailed Description

Because doxygen is Bad Software, the actual documentation can only exist in logmath_t. Sorry about that.

In evaluating HMM models, probability values are often kept in log domain, to avoid overflow. To enable these logprob values to be held in int32 variables without significant loss of precision, a logbase of (1+epsilon) (where epsilon < 0.01 or so) is used. This module maintains this logbase (B).

However, maintaining probabilities in log domain creates a problem when adding two probability values. This problem can be solved by table lookup. Note that:

• $$b^z = b^x + b^y$$
• $$b^z = b^x(1 + b^{y-x}) = b^y(1 + e^{x-y})$$
• $$z = x + log_b(1 + b^{y-x}) = y + log_b(1 + b^{x-y})$$

So:

• when $$y > x, z = y + logadd\_table[-(x-y)]$$
• when $$x > y, z = x + logadd\_table[-(y-x)]$$
• where $$logadd\_table[n] = log_b(1 + b^{-n})$$

The first entry in logadd_table is simply $$log_b(2.0)$$, for the case where $$y = x$$ and thus $$z = log_b(2x) = log_b(2) + x$$. The last entry is zero, where $$log_b(x+y) = x = y$$ due to loss of precision.

Since this table can be quite large particularly for small logbases, an option is provided to compress it by dropping the least significant bits of the table.

## ◆ LOGMATH_TABLE

 #define LOGMATH_TABLE ( lm ) ((logadd_t *)lm)

Obtain the log-add table from a logmath_t *