Struct Weight
Represent an element of the automata weight semiring.
Inherited Members
Namespace: Microsoft.ML.Probabilistic.Distributions.Automata
Assembly: Microsoft.ML.Probabilistic.dll
Syntax
[Serializable]
[DataContract]
public readonly struct Weight : IComparable<Weight>, IFormattable
Remarks
Weights are stored in log-domain so that weights of tiny magnitude can be handled without the loss of precision.
Properties
Infinity
Gets the infinite weight.
Declaration
public static readonly Weight Infinity { get; }
Property Value
| Type | Description |
|---|---|
| Weight |
IsInfinity
Gets value indicating whether weight is infinite.
Declaration
public readonly bool IsInfinity { get; }
Property Value
| Type | Description |
|---|---|
| Boolean |
IsZero
Gets a value indicating whether the weight is zero.
Declaration
public readonly bool IsZero { get; }
Property Value
| Type | Description |
|---|---|
| Boolean |
LogValue
Gets the logarithm of the weight value.
Declaration
public readonly double LogValue { get; }
Property Value
| Type | Description |
|---|---|
| Double |
One
Gets the unit weight.
Declaration
public static readonly Weight One { get; }
Property Value
| Type | Description |
|---|---|
| Weight |
Value
Gets the weight value.
Declaration
public readonly double Value { get; }
Property Value
| Type | Description |
|---|---|
| Double |
Zero
Gets the zero weight.
Declaration
public static readonly Weight Zero { get; }
Property Value
| Type | Description |
|---|---|
| Weight |
Methods
AbsoluteDifference(Weight, Weight)
Compute the difference of given weights.
Declaration
public static Weight AbsoluteDifference(Weight weight1, Weight weight2)
Parameters
| Type | Name | Description |
|---|---|---|
| Weight | weight1 | The first weight. |
| Weight | weight2 | The second weight. |
Returns
| Type | Description |
|---|---|
| Weight | The computed difference. |
ApproximateClosure(Weight)
Computes the sum of a geometric series 1 + w + w^2 + w^3 + ...,
where w is a given weight.
If the sum diverges, replaces the infinite sum by a finite sum with a lot of terms.
Declaration
public static Weight ApproximateClosure(Weight weight)
Parameters
| Type | Name | Description |
|---|---|---|
| Weight | weight | The weight. |
Returns
| Type | Description |
|---|---|
| Weight | The computed sum. |
Closure(Weight)
Computes the sum of a geometric series 1 + w + w^2 + w^3 + ...,
where w is a given weight.
Declaration
public static Weight Closure(Weight weight)
Parameters
| Type | Name | Description |
|---|---|---|
| Weight | weight | The weight. |
Returns
| Type | Description |
|---|---|
| Weight | The computed sum, or Infinity if the sum diverges. |
CompareTo(Weight)
Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.
Declaration
public readonly int CompareTo(Weight that)
Parameters
| Type | Name | Description |
|---|---|---|
| Weight | that | An object to compare with this instance. |
Returns
| Type | Description |
|---|---|
| Int32 | A value that indicates the relative order of the objects being compared. The return value
has these meanings: Value Meaning Less than zero This instance precedes |
Equals(Object)
Checks if this instance is equal to a given object.
Declaration
public override readonly bool Equals(object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| Object | obj | The object. |
Returns
| Type | Description |
|---|---|
| Boolean | true if this instance is equal to |
Overrides
FromLogValue(Double)
Creates a weight from the logarithm of its value.
Declaration
[Construction(new string[]{"LogValue"})]
public static Weight FromLogValue(double logValue)
Parameters
| Type | Name | Description |
|---|---|---|
| Double | logValue | The logarithm of the weight value. |
Returns
| Type | Description |
|---|---|
| Weight | The created weight. |
FromValue(Double)
Creates a weight from its value.
Declaration
public static Weight FromValue(double value)
Parameters
| Type | Name | Description |
|---|---|---|
| Double | value | The weight value. |
Returns
| Type | Description |
|---|---|
| Weight | The created weight. |
GetHashCode()
Gets the hash code of this instance.
Declaration
public override readonly int GetHashCode()
Returns
| Type | Description |
|---|---|
| Int32 | The hash code. |
Overrides
Inverse(Weight)
Computes the inverse of a given weight.
Declaration
public static Weight Inverse(Weight weight)
Parameters
| Type | Name | Description |
|---|---|---|
| Weight | weight | The weight. |
Returns
| Type | Description |
|---|---|
| Weight | The inverse |
Pow(Weight, Double)
Returns a specified weight raised to the specified power.
Declaration
public static Weight Pow(Weight weight, double power)
Parameters
| Type | Name | Description |
|---|---|---|
| Weight | weight | |
| Double | power |
Returns
| Type | Description |
|---|---|
| Weight |
Product(Weight, Weight)
Compute the product of given weights.
Declaration
public static Weight Product(Weight weight1, Weight weight2)
Parameters
| Type | Name | Description |
|---|---|---|
| Weight | weight1 | The first weight. |
| Weight | weight2 | The second weight. |
Returns
| Type | Description |
|---|---|
| Weight | The computed product. |
Product(Weight, Weight, Weight)
Compute the product of given weights.
Declaration
public static Weight Product(Weight weight1, Weight weight2, Weight weight3)
Parameters
| Type | Name | Description |
|---|---|---|
| Weight | weight1 | The first weight. |
| Weight | weight2 | The second weight. |
| Weight | weight3 | The third weight. |
Returns
| Type | Description |
|---|---|
| Weight | The computed product. |
Product(Weight[])
Compute the product of given weights.
Declaration
public static Weight Product(params Weight[] weights)
Parameters
| Type | Name | Description |
|---|---|---|
| Weight[] | weights | The weights. |
Returns
| Type | Description |
|---|---|
| Weight | The computed product. |
Read(Func<Double>)
Reads a weight.
Declaration
public static Weight Read(Func<double> readDouble)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<Double> | readDouble |
Returns
| Type | Description |
|---|---|
| Weight |
Sum(Weight, Weight)
Compute the sum of given weights.
Declaration
public static Weight Sum(Weight weight1, Weight weight2)
Parameters
| Type | Name | Description |
|---|---|---|
| Weight | weight1 | The first weight. |
| Weight | weight2 | The second weight. |
Returns
| Type | Description |
|---|---|
| Weight | The computed sum. |
ToString()
Gets a string representation of this object.
Declaration
public override readonly string ToString()
Returns
| Type | Description |
|---|---|
| String | A string representation of this object. |
Overrides
ToString(IFormatProvider)
Gets a string representation of this object.
Declaration
public readonly string ToString(IFormatProvider provider)
Parameters
| Type | Name | Description |
|---|---|---|
| IFormatProvider | provider | A format provider. |
Returns
| Type | Description |
|---|---|
| String | A string representation of this object. |
ToString(String)
Declaration
public readonly string ToString(string format)
Parameters
| Type | Name | Description |
|---|---|---|
| String | format |
Returns
| Type | Description |
|---|---|
| String |
ToString(String, IFormatProvider)
Declaration
public readonly string ToString(string format, IFormatProvider formatProvider)
Parameters
| Type | Name | Description |
|---|---|---|
| String | format | |
| IFormatProvider | formatProvider |
Returns
| Type | Description |
|---|---|
| String |
Write(Action<Double>)
Writes the weight.
Declaration
public readonly void Write(Action<double> writeDouble)
Parameters
| Type | Name | Description |
|---|---|---|
| Action<Double> | writeDouble |
Operators
Addition(Weight, Weight)
Compute the sum of given weights.
Declaration
public static Weight operator +(Weight weight1, Weight weight2)
Parameters
| Type | Name | Description |
|---|---|---|
| Weight | weight1 | The first weight. |
| Weight | weight2 | The second weight. |
Returns
| Type | Description |
|---|---|
| Weight | The computed sum. |
Division(Weight, Weight)
Compute the ratio of given weights.
Declaration
public static Weight operator /(Weight weight1, Weight weight2)
Parameters
| Type | Name | Description |
|---|---|---|
| Weight | weight1 | The first weight. |
| Weight | weight2 | The second weight. |
Returns
| Type | Description |
|---|---|
| Weight | The computed product. |
Equality(Weight, Weight)
The weight equality operator.
Declaration
public static bool operator ==(Weight weight1, Weight weight2)
Parameters
| Type | Name | Description |
|---|---|---|
| Weight | weight1 | The first weight. |
| Weight | weight2 | The second weight. |
Returns
| Type | Description |
|---|---|
| Boolean | true if the given weights are equal, false otherwise. |
GreaterThan(Weight, Weight)
Weight "greater than" operator.
Declaration
public static bool operator>(Weight weight1, Weight weight2)
Parameters
| Type | Name | Description |
|---|---|---|
| Weight | weight1 | |
| Weight | weight2 |
Returns
| Type | Description |
|---|---|
| Boolean |
GreaterThanOrEqual(Weight, Weight)
Weight "greater than or equal" operator.
Declaration
public static bool operator >=(Weight weight1, Weight weight2)
Parameters
| Type | Name | Description |
|---|---|---|
| Weight | weight1 | |
| Weight | weight2 |
Returns
| Type | Description |
|---|---|
| Boolean |
Inequality(Weight, Weight)
The weight inequality operator.
Declaration
public static bool operator !=(Weight weight1, Weight weight2)
Parameters
| Type | Name | Description |
|---|---|---|
| Weight | weight1 | The first weight. |
| Weight | weight2 | The second weight. |
Returns
| Type | Description |
|---|---|
| Boolean | true if the given weights are not equal, false otherwise. |
LessThan(Weight, Weight)
Weight "less than" operator.
Declaration
public static bool operator <(Weight weight1, Weight weight2)
Parameters
| Type | Name | Description |
|---|---|---|
| Weight | weight1 | |
| Weight | weight2 |
Returns
| Type | Description |
|---|---|
| Boolean |
LessThanOrEqual(Weight, Weight)
Weight "less than or equal" operator.
Declaration
public static bool operator <=(Weight weight1, Weight weight2)
Parameters
| Type | Name | Description |
|---|---|---|
| Weight | weight1 | |
| Weight | weight2 |
Returns
| Type | Description |
|---|---|
| Boolean |
Multiply(Weight, Weight)
Compute the product of given weights.
Declaration
public static Weight operator *(Weight weight1, Weight weight2)
Parameters
| Type | Name | Description |
|---|---|---|
| Weight | weight1 | The first weight. |
| Weight | weight2 | The second weight. |
Returns
| Type | Description |
|---|---|
| Weight | The computed product. |