public class UnsignedLogNumber extends java.lang.Number implements Field<UnsignedLogNumber>, java.lang.Comparable<UnsignedLogNumber>
LogNumber
. However, when you are dealing with unsigned numbers like
probabilities, this class will be more efficient.LogNumber
,
LogMath
,
Serialized FormModifier and Type | Field and Description |
---|---|
protected double |
logValue
The log of the value represented by this object, log(value).
|
Modifier | Constructor and Description |
---|---|
|
UnsignedLogNumber()
Creates the
LogNumber representing zero. |
protected |
UnsignedLogNumber(double logValue)
Creates a new
LogNumber from the given value in log-space. |
|
UnsignedLogNumber(UnsignedLogNumber other)
Copies a given LogNumber.
|
Modifier and Type | Method and Description |
---|---|
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
log-space. |
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)
Element-wise multiplication of
this and other |
void |
dotTimesEquals(UnsignedLogNumber other)
Inline element-wise multiplication of
this and
other |
double |
doubleValue() |
boolean |
equals(java.lang.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 element-wise 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 element-wise negation of
this , such that
this.plus( this.negative() ) has only zero elements. |
void |
negativeEquals()
Inline element-wise 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)
Element-wise scaling of
this by scaleFactor |
UnsignedLogNumber |
scaledMinus(double scaleFactor,
UnsignedLogNumber other)
Arithmetic subtraction
other after element-wise scaling of
other by scaleFactor from this . |
void |
scaledMinusEquals(double scaleFactor,
UnsignedLogNumber other)
Inline arithmetic subtraction of
other after element-wise
scaling of other by scaleFactor from this . |
UnsignedLogNumber |
scaledPlus(double scaleFactor,
UnsignedLogNumber other)
Arithmetic addition of
this and other after
element-wise scaling of other by scaleFactor . |
void |
scaledPlusEquals(double scaleFactor,
UnsignedLogNumber other)
Inline arithmetic addition of
this and other after
element-wise scaling of other by scaleFactor . |
void |
scaleEquals(double scaleFactor)
Inline element-wise 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.
|
java.lang.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 ); |
protected double logValue
public UnsignedLogNumber()
LogNumber
representing zero.protected UnsignedLogNumber(double logValue)
LogNumber
from the given value in log-space. 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.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
log-space. Equivalent to calling createFromValue(exp(logValue)).logValue
- The value that is already in log-space.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 java.lang.Object
this
public boolean equals(java.lang.Object other)
Ring
equals
in interface Ring<UnsignedLogNumber>
equals
in class java.lang.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 element-wise equalitypublic int compareTo(UnsignedLogNumber other)
compareTo
in interface java.lang.Comparable<UnsignedLogNumber>
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.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
element-wise 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
element-wise 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 element-wise 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 element-wise
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 element-wise equalitypublic 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 java.lang.Number
public long longValue()
longValue
in class java.lang.Number
public float floatValue()
floatValue
in class java.lang.Number
public double doubleValue()
doubleValue
in class java.lang.Number