

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.UnsignedLogNumber
public class UnsignedLogNumber
Represents an unsigned number in log space, storing log(value) and operating
directly on it. It is used to operate on the 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,
which is often represented as ln(x) instead of log(x).
Note that this can only represent nonnegative numbers (x >= 0). Any
operations that will create negative numbers result in a NaN being stored
as the value. If you are looking for signed log numbers, see
LogNumber
. However, when you are dealing with unsigned numbers like
probabilities, this class will be more efficient.
LogNumber
,
LogMath
,
Serialized FormField Summary  

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


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

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

UnsignedLogNumber 
clone()
Returns a smart copy of this , such that changing the values
of the return class will not effect this 
int 
compareTo(UnsignedLogNumber other)

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

boolean 
equals(Object other)
Determines if two RingType objects are equal 
boolean 
equals(UnsignedLogNumber other,
double effectiveZero)
Determines if two RingType objects are effectively 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()

UnsignedLogNumber 
inverse()
Returns the inverse of this . 
void 
inverseEquals()
Changes this value to be its inverse. 
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()

UnsignedLogNumber 
max(UnsignedLogNumber other)
A new LogNumber that is the maximum of this and another. 
void 
maxEquals(UnsignedLogNumber other)
Changes this value to be the maximum of this value or the given value. 
UnsignedLogNumber 
min(UnsignedLogNumber other)
A new LogNumber that is the minimum of this and another. 
void 
minEquals(UnsignedLogNumber other)
Changes this value to be the minimum of this value or the given value. 
UnsignedLogNumber 
minus(UnsignedLogNumber other)
Arithmetic subtraction of other from this 
void 
minusEquals(UnsignedLogNumber other)
Inline arithmetic subtraction of other from
this 
UnsignedLogNumber 
negative()
Returns the elementwise negation of this , such that
this.plus( this.negative() ) has only zero elements. 
void 
negativeEquals()
Inline elementwise negation of this 
UnsignedLogNumber 
plus(UnsignedLogNumber other)
Arithmetic addition of this and other 
void 
plusEquals(UnsignedLogNumber other)
Inline arithmetic addition of this and other 
UnsignedLogNumber 
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. 
UnsignedLogNumber 
scale(double scaleFactor)
Elementwise scaling of this by scaleFactor 
UnsignedLogNumber 
scaledMinus(double scaleFactor,
UnsignedLogNumber other)
Arithmetic subtraction other after elementwise scaling of
other by scaleFactor from this . 
void 
scaledMinusEquals(double scaleFactor,
UnsignedLogNumber other)
Inline arithmetic subtraction of other after elementwise
scaling of other by scaleFactor from this . 
UnsignedLogNumber 
scaledPlus(double scaleFactor,
UnsignedLogNumber other)
Arithmetic addition of this and other after
elementwise scaling of other by scaleFactor . 
void 
scaledPlusEquals(double scaleFactor,
UnsignedLogNumber 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 
setValue(double value)
Sets the value represented by the log number. 
UnsignedLogNumber 
times(UnsignedLogNumber other)
Multiples this value times another value and returns the result. 
void 
timesEquals(UnsignedLogNumber 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 double logValue
Constructor Detail 

public UnsignedLogNumber()
LogNumber
representing zero.
protected UnsignedLogNumber(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.
logValue
 The log(value) for the value to be represented by this LogNumber.public UnsignedLogNumber(UnsignedLogNumber other)
other
 The LogNumber to copy.Method Detail 

public static UnsignedLogNumber createFromValue(double value)
LogNumber
from the given value.
value
 A normal value.
public static UnsignedLogNumber createFromLogValue(double logValue)
LogNumber
from the given value that is already in
logspace. Equivalent to calling createFromValue(exp(logValue)).
logValue
 The value that is already in logspace.
public UnsignedLogNumber clone()
Ring
this
, such that changing the values
of the return class will not effect this
clone
in interface Ring<UnsignedLogNumber>
clone
in interface CloneableSerializable
clone
in class Object
this
public boolean equals(Object other)
Ring
equals
in interface Ring<UnsignedLogNumber>
equals
in class Object
other
 RingType to compare against this
public boolean equals(UnsignedLogNumber other, double effectiveZero)
Ring
equals
in interface Ring<UnsignedLogNumber>
other
 RingType to compare against this
effectiveZero
 tolerance threshold for elementwise equality
public int compareTo(UnsignedLogNumber other)
compareTo
in interface Comparable<UnsignedLogNumber>
public int hashCode()
hashCode
in class Object
public String toString()
toString
in class Object
public UnsignedLogNumber plus(UnsignedLogNumber other)
Ring
this
and other
plus
in interface Ring<UnsignedLogNumber>
other
 object to add to this
this
and other
public void plusEquals(UnsignedLogNumber other)
Ring
this
and other
plusEquals
in interface Ring<UnsignedLogNumber>
other
 object to add to this
public UnsignedLogNumber minus(UnsignedLogNumber other)
Ring
other
from this
minus
in interface Ring<UnsignedLogNumber>
other
 object to subtract from this
this
and other
public void minusEquals(UnsignedLogNumber other)
Ring
other
from
this
minusEquals
in interface Ring<UnsignedLogNumber>
other
 object to subtract from this
public UnsignedLogNumber times(UnsignedLogNumber other)
times
in interface EuclideanRing<UnsignedLogNumber>
other
 The other value.
public void timesEquals(UnsignedLogNumber other)
timesEquals
in interface EuclideanRing<UnsignedLogNumber>
other
 The other value.public UnsignedLogNumber divide(UnsignedLogNumber other)
divide
in interface EuclideanRing<UnsignedLogNumber>
other
 The other value.
public void divideEquals(UnsignedLogNumber other)
divideEquals
in interface EuclideanRing<UnsignedLogNumber>
other
 The other value.public UnsignedLogNumber dotTimes(UnsignedLogNumber other)
Ring
this
and other
dotTimes
in interface Ring<UnsignedLogNumber>
other
 elements of other will be multiplied to the corresponding
elements of this
this
and
other
public void dotTimesEquals(UnsignedLogNumber other)
Ring
this
and
other
dotTimesEquals
in interface Ring<UnsignedLogNumber>
other
 elements of other will be multiplied to the corresponding
elements of this
public UnsignedLogNumber scale(double scaleFactor)
Ring
this
by scaleFactor
scale
in interface Ring<UnsignedLogNumber>
scaleFactor
 amount to scale the elements of this
this
public void scaleEquals(double scaleFactor)
Ring
this
by
scaleFactor
scaleEquals
in interface Ring<UnsignedLogNumber>
scaleFactor
 amount to scale the elements of this
public UnsignedLogNumber scaledPlus(double scaleFactor, UnsignedLogNumber 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<UnsignedLogNumber>
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, UnsignedLogNumber 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<UnsignedLogNumber>
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 UnsignedLogNumber scaledMinus(double scaleFactor, UnsignedLogNumber 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<UnsignedLogNumber>
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, UnsignedLogNumber 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<UnsignedLogNumber>
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 UnsignedLogNumber negative()
Ring
this
, such that
this.plus( this.negative() )
has only zero elements.
negative
in interface Ring<UnsignedLogNumber>
this
public void negativeEquals()
Ring
this
negativeEquals
in interface Ring<UnsignedLogNumber>
public UnsignedLogNumber inverse()
Field
this
.
inverse
in interface Field<UnsignedLogNumber>
public void inverseEquals()
Field
inverseEquals
in interface Field<UnsignedLogNumber>
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<UnsignedLogNumber>
public boolean isZero()
Ring
isZero
in interface Ring<UnsignedLogNumber>
public boolean isZero(double effectiveZero)
Ring
isZero
in interface Ring<UnsignedLogNumber>
effectiveZero
 Tolerance threshold for elementwise equality
public UnsignedLogNumber 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 UnsignedLogNumber min(UnsignedLogNumber other)
LogNumber
that is the minimum of this and another.
other
 Another value.
public void minEquals(UnsignedLogNumber other)
other
 Another value.public UnsignedLogNumber max(UnsignedLogNumber other)
LogNumber
that is the maximum of this and another.
other
 Another value.
public void maxEquals(UnsignedLogNumber other)
other
 Another value.public double getValue()
public void setValue(double value)
value
 The value for this object to represent.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 