

PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: NESTED  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 
java.lang.Object java.lang.Number gov.sandia.cognition.math.LogNumber
public class LogNumber
Represents a number in logspace, storing the log of the absolute value
log(value) and the sign of the value sign(value). It is used to operate
on a number as if it were not being represented in log space.
Thus if you have two log numbers, a and b such that
a = log(x) and b = log(y), doing c = a * b will be result in c = log(x * y),
not c = log(x) * log(y). This means that when you do a.getValue() you will
get x and if you do a.getLogValue() you will get log(x).
This class is useful if you need to do a lot of operations on data with very
large or very small exponents to avoid numerical overflow and underflow.
This can be useful, for example, for probabilities that involve many
products.
All of the logarithms done by the class are done using the natural base (e),
which is often denoted as ln(x) instead of log(x).
If you know that all of your numbers are positive, such as if they are all
probabilities, then you may want to use an UnsignedLogNumber
instead,
since it does not have to maintain the sign information, so it will consume
less memory and will be faster.
UnsignedLogNumber
,
LogMath
,
Serialized FormField Summary  

protected double 
logValue
The log of the absolute value represented by this object, log(value). 
protected boolean 
negative
The sign of the value, sign(value). 
Constructor Summary  


LogNumber()
Creates the LogNumber representing zero. 
protected 
LogNumber(boolean negative,
double logValue)
Creates a new LogNumber from the given value in logspace. 

LogNumber(LogNumber other)
Copies a given LogNumber. 
Method Summary  

LogNumber 
absoluteValue()
Returns a new LogNumber that represents the absolute value
of this LogNumber . 
void 
absoluteValueEquals()
Transforms this value to be its absolute value. 
LogNumber 
clone()
Returns a smart copy of this , such that changing the values
of the return class will not effect this 
int 
compareTo(LogNumber other)

static LogNumber 
createFromLogValue(boolean negative,
double logValue)
Creates a new LogNumber from the given value that is
already in logspace. 
static LogNumber 
createFromLogValue(double logValue)
Creates a new LogNumber from the given value that is
already in logspace. 
static LogNumber 
createFromValue(double value)
Creates a new LogNumber from the given value. 
LogNumber 
divide(LogNumber other)
Divides this value by another value and returns the result. 
void 
divideEquals(LogNumber other)
Divides this value by another value and stores the result in this value. 
LogNumber 
dotTimes(LogNumber other)
Elementwise multiplication of this and other 
void 
dotTimesEquals(LogNumber other)
Inline elementwise multiplication of this and
other 
double 
doubleValue()

boolean 
equals(LogNumber other,
double effectiveZero)
Determines if two RingType objects are effectively equal 
boolean 
equals(Object other)
Determines if two RingType objects are equal 
float 
floatValue()

double 
getLogValue()
Gets the log of the value represented by this object, which is what is stored in the object. 
double 
getValue()
Gets the value represented by the log number. 
int 
hashCode()

int 
intValue()

LogNumber 
inverse()
Returns the inverse of this . 
void 
inverseEquals()
Changes this value to be its inverse. 
boolean 
isNegative()
Gets whether or not this value has a negative sign. 
boolean 
isZero()
Determines if this ring is equal to zero. 
boolean 
isZero(double effectiveZero)
Determines if this ring is equal to zero using the elementwise effective zero value. 
long 
longValue()

LogNumber 
max(LogNumber other)
A new LogNumber that is the maximum of this and another. 
void 
maxEquals(LogNumber other)
Changes this value to be the maximum of this value or the given value. 
LogNumber 
min(LogNumber other)
A new LogNumber that is the minimum of this and another. 
void 
minEquals(LogNumber other)
Changes this value to be the minimum of this value or the given value. 
LogNumber 
minus(LogNumber other)
Arithmetic subtraction of other from this 
void 
minusEquals(LogNumber other)
Inline arithmetic subtraction of other from
this 
LogNumber 
negative()
Returns the elementwise negation of this , such that
this.plus( this.negative() ) has only zero elements. 
void 
negativeEquals()
Inline elementwise negation of this 
LogNumber 
plus(LogNumber other)
Arithmetic addition of this and other 
void 
plusEquals(LogNumber other)
Inline arithmetic addition of this and other 
LogNumber 
power(double power)
Returns a new LogNumber representing this log number taken
to the given power. 
void 
powerEquals(double power)
Transforms this log number by taking it to the given power. 
LogNumber 
scale(double scaleFactor)
Elementwise scaling of this by scaleFactor 
LogNumber 
scaledMinus(double scaleFactor,
LogNumber other)
Arithmetic subtraction other after elementwise scaling of
other by scaleFactor from this . 
void 
scaledMinusEquals(double scaleFactor,
LogNumber other)
Inline arithmetic subtraction of other after elementwise
scaling of other by scaleFactor from this . 
LogNumber 
scaledPlus(double scaleFactor,
LogNumber other)
Arithmetic addition of this and other after
elementwise scaling of other by scaleFactor . 
void 
scaledPlusEquals(double scaleFactor,
LogNumber other)
Inline arithmetic addition of this and other after
elementwise scaling of other by scaleFactor . 
void 
scaleEquals(double scaleFactor)
Inline elementwise scaling of this by
scaleFactor 
void 
setLogValue(double logValue)
Sets the log of the value represented by this object, which is what is stored in the object. 
void 
setNegative(boolean negative)
Sets whether or not this value has a negative sign. 
void 
setValue(double value)
Sets the value represented by the log number. 
LogNumber 
times(LogNumber other)
Multiples this value times another value and returns the result. 
void 
timesEquals(LogNumber other)
Multiplies this value times another value and stores the result in this value. 
String 
toString()

void 
zero()
Zeros out all elements of this , so that the following are
equivalent
r1.scaleEquals( 0.0 );
and
r1.zero();
Furthermore,
r1.zero(); anything.dotTimes( r1 ).equals( r1 ); 
Methods inherited from class java.lang.Number 

byteValue, shortValue 
Methods inherited from class java.lang.Object 

finalize, getClass, notify, notifyAll, wait, wait, wait 
Field Detail 

protected boolean negative
protected double logValue
Constructor Detail 

public LogNumber()
LogNumber
representing zero.
protected LogNumber(boolean negative, double logValue)
LogNumber
from the given value in logspace.
This method is protected to avoid people calling it with being unsure if
value or log(value) should be given. Thus, two separate static utility
functions createFromValue and createFromLogValue are to be used instead.
negative
 The flag indicating if the value is positive (false) or negative
(true).logValue
 The log(value) for the value to be represented by this
LogNumber.public LogNumber(LogNumber other)
other
 The LogNumber to copy.Method Detail 

public static LogNumber createFromValue(double value)
LogNumber
from the given value.
value
 A normal value.
public static LogNumber createFromLogValue(double logValue)
LogNumber
from the given value that is
already in logspace. Equivalent to calling createFromValue(
exp(logValue)) or createFromLogValue(false, logValue).
logValue
 The value that is already in logspace.
public static LogNumber createFromLogValue(boolean negative, double logValue)
LogNumber
from the given value that is
already in logspace. Equivalent to calling createFromValue(
(negative ? +1.0 : 1.0) * exp(logValue)).
negative
 True if the value is negative.logValue
 The value that is already in logspace.
public LogNumber clone()
Ring
this
, such that changing the values
of the return class will not effect this
clone
in interface Ring<LogNumber>
clone
in interface CloneableSerializable
clone
in class Object
this
public boolean equals(Object other)
Ring
equals
in interface Ring<LogNumber>
equals
in class Object
other
 RingType to compare against this
public boolean equals(LogNumber other, double effectiveZero)
Ring
equals
in interface Ring<LogNumber>
other
 RingType to compare against this
effectiveZero
 tolerance threshold for elementwise equality
public int compareTo(LogNumber other)
compareTo
in interface Comparable<LogNumber>
public int hashCode()
hashCode
in class Object
public String toString()
toString
in class Object
public LogNumber plus(LogNumber other)
Ring
this
and other
plus
in interface Ring<LogNumber>
other
 object to add to this
this
and other
public void plusEquals(LogNumber other)
Ring
this
and other
plusEquals
in interface Ring<LogNumber>
other
 object to add to this
public LogNumber minus(LogNumber other)
Ring
other
from this
minus
in interface Ring<LogNumber>
other
 object to subtract from this
this
and other
public void minusEquals(LogNumber other)
Ring
other
from
this
minusEquals
in interface Ring<LogNumber>
other
 object to subtract from this
public LogNumber times(LogNumber other)
times
in interface EuclideanRing<LogNumber>
other
 The other value.
public void timesEquals(LogNumber other)
timesEquals
in interface EuclideanRing<LogNumber>
other
 The other value.public LogNumber divide(LogNumber other)
divide
in interface EuclideanRing<LogNumber>
other
 The other value.
public void divideEquals(LogNumber other)
divideEquals
in interface EuclideanRing<LogNumber>
other
 The other value.public LogNumber dotTimes(LogNumber other)
Ring
this
and other
dotTimes
in interface Ring<LogNumber>
other
 elements of other will be multiplied to the corresponding
elements of this
this
and
other
public void dotTimesEquals(LogNumber other)
Ring
this
and
other
dotTimesEquals
in interface Ring<LogNumber>
other
 elements of other will be multiplied to the corresponding
elements of this
public LogNumber scale(double scaleFactor)
Ring
this
by scaleFactor
scale
in interface Ring<LogNumber>
scaleFactor
 amount to scale the elements of this
this
public void scaleEquals(double scaleFactor)
Ring
this
by
scaleFactor
scaleEquals
in interface Ring<LogNumber>
scaleFactor
 amount to scale the elements of this
public LogNumber scaledPlus(double scaleFactor, LogNumber other)
Ring
this
and other
after
elementwise scaling of other
by scaleFactor
.
If this is x, other is y, and scaleFactor is a, then this method is
equivalent to x + a * y. It is typically a more efficient way of doing
this.plus(other.scale(scaleFactor))
since it can avoid
intermediate object creation.
scaledPlus
in interface Ring<LogNumber>
scaleFactor
 The scale factor to multiply by the elements of other before
adding to the elements of this.other
 Object to scale and then add to this.
public void scaledPlusEquals(double scaleFactor, LogNumber other)
Ring
this
and other
after
elementwise scaling of other
by scaleFactor
.
If this is x, other is y, and scaleFactor is a, then this method is
equivalent to x += a * y. It is typically a more efficient way of doing
this.plusEquals(other.scale(scaleFactor))
since it can avoid
intermediate object creation.
scaledPlusEquals
in interface Ring<LogNumber>
scaleFactor
 The scale factor to multiply by the elements of other before
adding to the elements of this.other
 Object to scale and then add to this.public LogNumber scaledMinus(double scaleFactor, LogNumber other)
Ring
other
after elementwise scaling of
other
by scaleFactor
from this
.
If this is x, other is y, and scaleFactor is a, then this method is
equivalent to x  a * y. It is typically a more efficient way of doing
this.minus(other.scale(scaleFactor))
since it can avoid
intermediate object creation.
scaledMinus
in interface Ring<LogNumber>
scaleFactor
 The scale factor to multiply by the elements of other before
subtracting from the elements of this.other
 Object to scale and then subtract from this.
public void scaledMinusEquals(double scaleFactor, LogNumber other)
Ring
other
after elementwise
scaling of other
by scaleFactor
from this
.
If this is x, other is y, and scaleFactor is a, then this method is
equivalent to x = a * y. It is typically a more efficient way of doing
this.minusEquals(other.scale(scaleFactor))
since it can avoid
intermediate object creation.
scaledMinusEquals
in interface Ring<LogNumber>
scaleFactor
 The scale factor to multiply by the elements of other before
adding to the elements of this.other
 Object to scale and then add to this.public LogNumber negative()
Ring
this
, such that
this.plus( this.negative() )
has only zero elements.
negative
in interface Ring<LogNumber>
this
public void negativeEquals()
Ring
this
negativeEquals
in interface Ring<LogNumber>
public void inverseEquals()
Field
inverseEquals
in interface Field<LogNumber>
public LogNumber inverse()
Field
this
.
inverse
in interface Field<LogNumber>
public void zero()
Ring
this
, so that the following are
equivalent
r1.scaleEquals( 0.0 );
and
r1.zero();
Furthermore,
r1.zero(); anything.dotTimes( r1 ).equals( r1 );
zero
in interface Ring<LogNumber>
public boolean isZero()
Ring
isZero
in interface Ring<LogNumber>
public boolean isZero(double effectiveZero)
Ring
isZero
in interface Ring<LogNumber>
effectiveZero
 Tolerance threshold for elementwise equality
public LogNumber absoluteValue()
LogNumber
that represents the absolute value
of this LogNumber
.
public void absoluteValueEquals()
public LogNumber power(double power)
LogNumber
representing this log number taken
to the given power.
power
 The power.
public void powerEquals(double power)
power
 The power.public LogNumber min(LogNumber other)
LogNumber
that is the minimum of this and another.
other
 Another value.
public void minEquals(LogNumber other)
other
 Another value.public LogNumber max(LogNumber other)
LogNumber
that is the maximum of this and another.
other
 Another value.
public void maxEquals(LogNumber other)
other
 Another value.public double getValue()
public void setValue(double value)
value
 The value for this object to represent.public boolean isNegative()
public void setNegative(boolean negative)
negative
 True if this value has a negative sign.public double getLogValue()
public void setLogValue(double logValue)
logValue
 The log of the value for this object to represent.public int intValue()
intValue
in class Number
public long longValue()
longValue
in class Number
public float floatValue()
floatValue
in class Number
public double doubleValue()
doubleValue
in class Number


PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: NESTED  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 