|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.sun.labs.minion.util.LogMath
public final class LogMath
Provides a set of methods for performing simple math in the log domain. The
logarithmic base can be set by the SphinxProperty:
edu.cmu.sphinx.util.LogMath.logBase
Field Summary | |
---|---|
static java.lang.String |
PROP_LOG_BASE
Sphinx property to get the Log base |
static java.lang.String |
PROP_USE_ADD_TABLE
Sphinx property that controls whether we use the old, slow (but correct) method of performing the LogMath.add by doing the actual computation. |
Constructor Summary | |
---|---|
LogMath()
|
|
LogMath(float logBase,
boolean useAddTable)
|
Method Summary | |
---|---|
float |
addAsLinear(float logVal1,
float logVal2)
Returns the summation of two numbers when the arguments and the result are in log. |
float |
divideAsLinear(float lv1,
float lv2)
|
float |
getLogBase()
Returns the actual log base. |
static float |
getLogOne()
Returns the one value in the log domain |
static float |
getLogZero()
Returns the zero value in the log domain |
java.lang.String |
getName()
|
float |
linearToLog(double linearValue)
Converts the value from linear scale to log scale. |
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. |
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. |
float |
multiplyAsLinear(float lv1,
float lv2)
|
void |
newProperties(com.sun.labs.util.props.PropertySheet ps)
|
float |
powerAsLinear(float lv,
int x)
|
float |
subtractAsLinear(float logMinuend,
float logSubtrahend)
Returns the difference between two numbers when the arguments and the result are in log. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
@ConfigDouble(defaultValue=2.718281828459045) public static final java.lang.String PROP_LOG_BASE
@ConfigBoolean(defaultValue=true) public static final java.lang.String PROP_USE_ADD_TABLE
Constructor Detail |
---|
public LogMath()
public LogMath(float logBase, boolean useAddTable)
Method Detail |
---|
public void newProperties(com.sun.labs.util.props.PropertySheet ps) throws com.sun.labs.util.props.PropertyException
newProperties
in interface com.sun.labs.util.props.Configurable
com.sun.labs.util.props.PropertyException
public java.lang.String getName()
public 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 add
public 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
subtracted
java.lang.IllegalArgumentException
- This is a very slow way to do this, but this method should rarely be used.
public float multiplyAsLinear(float lv1, float lv2)
public float divideAsLinear(float lv1, float lv2)
public float powerAsLinear(float lv, int x)
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 to
java.lang.IllegalArgumentException
public 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 scale
java.lang.IllegalArgumentException
public final double logToLinear(float logValue)
logValue
- the value to be converted to the linear scale
public static final float getLogZero()
public static final float getLogOne()
public final float getLogBase()
public static float log10(float value)
value
- the value to take the log of
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |