Vector.NormalizeLogWeights<T> Method

Converts log weights to probability weights and returns their log normalizer.

Definition

Namespace: Numerics.NET
Assembly: Numerics.NET (in Numerics.NET.dll) Version: 10.10.0
C#
public static Vector<T> NormalizeLogWeights<T>(
	Vector<T> logWeights,
	out T logNormalizer
)

Parameters

logWeights  Vector<T>
The unnormalized log weights in logical order.
logNormalizer  T
The logarithm of the sum of the exponentials of logWeights. A finite value indicates valid normalized weights.

Type Parameters

T
A supported real floating-point element type.

Return Value

Vector<T>
A new vector of ordinary probability weights, with the same length and logical order as logWeights.

Remarks

When logNormalizer is finite, the returned weights are finite, nonnegative, and sum to one within floating-point roundoff. Negative-infinite scores receive zero weight. The calculation shares a shifted exponential sum between both outputs, avoiding direct exponentiation of large positive or negative scores.

Any NaN score gives a NaN normalizer and all-NaN weights. Otherwise, positive infinities give a positive-infinite normalizer and share the probability mass equally; other entries receive zero. All-negative-infinite scores give a negative-infinite normalizer and all-NaN weights. Empty input gives an empty vector and a negative-infinite normalizer. These cases can be detected afterwards by testing the normalizer for finiteness.

Every logical score is inspected, even when the input is missing-aware. NaNs are never skipped. Input storage is neither modified nor retained. In the Pro edition, the result retains the input's row index and name, using ordinary numeric missing-value semantics rather than inheriting the input's missing-value settings.

Exceptions

ArgumentNullExceptionlogWeights is null.
NotSupportedExceptionThe element type does not support the required floating-point operations.

See Also