public final class LogMath
extends java.lang.Object
edu.cmu.sphinx.util.LogMath.logBase
Modifier and Type | Field and Description |
---|---|
static float |
LOG_ONE |
static float |
LOG_ZERO |
Modifier and Type | Method and Description |
---|---|
float |
addAsLinear(float logVal1,
float logVal2)
Returns the summation of two numbers when the arguments and the result are in log.
|
float |
getLogBase() |
static LogMath |
getLogMath() |
boolean |
isUseTable() |
float |
linearToLog(double linearValue)
Converts the value from linear scale to log scale.
|
void |
linearToLog(float[] vector)
Converts a vector from linear domain to log domain using a given
LogMath -instance for conversion. |
float |
lnToLog(float logSource)
Converts the source, which is a number in base Math.E, to a log value which base is the LogBase of this LogMath.
|
static float |
log10(float value)
Returns the log (base 10) of value
|
float |
log10ToLog(float logSource)
Converts the source, which is a number in base 10, to a log value which base is the LogBase of this LogMath.
|
double |
logToLinear(float logValue)
Converts the value from log scale to linear scale.
|
void |
logToLinear(float[] vector,
float[] out)
Converts a vector from log to linear domain using a given
LogMath -instance for conversion. |
float |
logToLn(float logSource)
Converts the source, whose base is the LogBase of this LogMath, to a log value which is a number in base Math.E.
|
static float |
logToLog(float logSource,
float sourceBase,
float resultBase)
Converts the source, which is assumed to be a log value whose base is sourceBase, to a log value whose base is
resultBase.
|
static void |
setLogBase(float logBase)
Sets log base.
|
static void |
setUseTable(boolean useTable)
The property that controls whether we use the old, slow (but correct)
method of performing the LogMath.add by doing the actual computation.
|
float |
subtractAsLinear(float logMinuend,
float logSubtrahend)
Returns the difference between two numbers when the arguments and the result are in log.
|
public static final float LOG_ZERO
public static final float LOG_ONE
public static LogMath getLogMath()
public static void setLogBase(float logBase)
According to forum discussions a value between 1.00001 and 1.0004 should be used for speech recognition. Going above 1.0005 will probably hurt.
logBase
- Log basepublic static void setUseTable(boolean useTable)
useTable
- to configure table lookupspublic final float addAsLinear(float logVal1, float logVal2)
That is, it returns log(a + b) given log(a) and log(b)
This method makes use of the equality:
log(a + b) = log(a) + log (1 + exp(log(b) - log(a)))
which is derived from:
a + b = a * (1 + (b / a))
which in turns makes use of:
b / a = exp (log(b) - log(a))
Important to notice that subtractAsLinear(a, b)
is *not* the same as
addAsLinear(a, -b)
, since we're in the log domain, and -b is in fact the inverse.
No underflow/overflow check is performed.
logVal1
- value in log domain (i.e. log(val1)) to addlogVal2
- value in log domain (i.e. log(val2)) to addpublic final float subtractAsLinear(float logMinuend, float logSubtrahend) throws java.lang.IllegalArgumentException
That is, it returns log(a - b) given log(a) and log(b)
Implementation is less efficient than add(), since we're less likely to use this function, provided for completeness. Notice however that the result only makes sense if the minuend is higher than the subtrahend. Otherwise, we should return the log of a negative number.
It implements the subtraction as:
log(a - b) = log(a) + log(1 - exp(log(b) - log(a)))
No need to check for underflow/overflow.
logMinuend
- value in log domain (i.e. log(minuend)) to be subtracted fromlogSubtrahend
- value in log domain (i.e. log(subtrahend)) that is being subtractedjava.lang.IllegalArgumentException
- This is a very slow way to do this, but this method should rarely be used.
public static float logToLog(float logSource, float sourceBase, float resultBase) throws java.lang.IllegalArgumentException
It takes advantage of the relation:
log_a(b) = log_c(b) / lob_c(a)
or:
log_a(b) = log_c(b) * lob_a(c)
where log_a(b) is logarithm of b base a etc.
logSource
- log value whose base is sourceBasesourceBase
- the base of the log the sourceresultBase
- the base to convert the source log tojava.lang.IllegalArgumentException
- if arguments out of boundspublic final float lnToLog(float logSource)
logSource
- the number in base Math.E to convertpublic final float log10ToLog(float logSource)
logSource
- the number in base Math.E to convertpublic final float logToLn(float logSource)
logSource
- the number to convert to base Math.Epublic final float linearToLog(double linearValue) throws java.lang.IllegalArgumentException
linearValue
- the value to be converted to log scalejava.lang.IllegalArgumentException
- if value out of rangepublic final double logToLinear(float logValue)
logValue
- the value to be converted to the linear scalepublic final float getLogBase()
public boolean isUseTable()
public static float log10(float value)
value
- the value to take the log ofpublic void linearToLog(float[] vector)
LogMath
-instance for conversion.vector
- to convert in-placepublic void logToLinear(float[] vector, float[] out)
LogMath
-instance for conversion.vector
- to convertout
- result