Fuzziness

com.phasmidsoftware.number.core.numerical.Fuzziness
See theFuzziness companion trait
object Fuzziness

A companion object to Fuzziness providing methods to manage and manipulate fuzziness in calculations and numeric operations. Fuzziness represents a level of uncertainty or imprecision associated with a value.

Attributes

Companion
trait
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
Fuzziness.type

Members list

Value members

Concrete methods

def applyCoefficients[T : HasValue](fuzz: (Option[Fuzziness[T]], Option[Fuzziness[T]]), coefficients: Option[(T, T)]): (Option[Fuzziness[T]], Option[Fuzziness[T]])

Scale the fuzz values by the two given coefficients.

Scale the fuzz values by the two given coefficients.

Value parameters

coefficients

the coefficients (a Tuple): the coefficients of deltaX/X and deltaY/Y respectively.

fuzz

the fuzz values (a Tuple), deltaX/X and deltaY/Y.

Attributes

Returns

the scaled fuzz values (a Tuple).

def combine[T : HasValue](t1: T, t2: T, relative: Boolean, independent: Boolean)(fuzz: (Option[Fuzziness[T]], Option[Fuzziness[T]])): Option[Fuzziness[T]]

Combine the fuzz values using a convolution. The order of fuzz1 and fuzz2 is not significant. Note that we normalize the style of each fuzz according to the value of relative. When both shapes are Box, we convolve them directly to produce a Trapezoid (or Box if one is negligible). When either shape is Trapezoid, we pass directly to * which handles all Trapezoid combinations. For all other shape combinations, we normalise to Gaussian before convolving.

Combine the fuzz values using a convolution. The order of fuzz1 and fuzz2 is not significant. Note that we normalize the style of each fuzz according to the value of relative. When both shapes are Box, we convolve them directly to produce a Trapezoid (or Box if one is negligible). When either shape is Trapezoid, we pass directly to * which handles all Trapezoid combinations. For all other shape combinations, we normalise to Gaussian before convolving.

Type parameters

T

the underlying type of the Fuzziness.

Value parameters

fuzz

a Tuple of the two optional Fuzziness values.

independent

true if the fuzz distributions are independent.

relative

true if we are multiplying, false if we are adding.

t1

the magnitude of the first operand.

t2

the magnitude of the second operand.

Attributes

Returns

an Option of Fuzziness[T].

def createAbsFuzz(magnitude: Double): Option[Fuzziness[Double]]

Creates an absolute fuzziness value with the given magnitude.

Creates an absolute fuzziness value with the given magnitude.

Value parameters

magnitude

The magnitude of the fuzziness to be created. This specifies the degree to which a value's precision is uncertain.

Attributes

Returns

An Option containing the created Fuzziness[Double] with the specified magnitude, or None if the fuzziness could not be created.

def createFuzz(relativePrecision: Option[Int]): Option[Fuzziness[Double]]

This method creates fuzz based on the practical limitations of representations and functions in double-precision arithmetic. See also the method doublePrecision.

This method creates fuzz based on the practical limitations of representations and functions in double-precision arithmetic. See also the method doublePrecision.

Value parameters

relativePrecision

the approximate number of bits of additional imprecision caused by evaluating a function.

Attributes

Returns

the approximate precision for a floating point operation, expressed in terms of RelativeFuzz.

def map[T, U : HasValue, V : HasValue](t: T, u: U, relative: Boolean, g: T => V, fuzz: Option[Fuzziness[T]]): Option[Fuzziness[U]]

Map the fuzz value with a function (typically the derivative of the function being applied to the Fuzzy quantity). Note that we normalize the style of each fuzz according to the value of relative. Note also that we normalize the shape of each fuzz to ensure Gaussian, since we cannot combine Box shapes into Box (we could combine Box shapes into trapezoids but who needs that?).

Map the fuzz value with a function (typically the derivative of the function being applied to the Fuzzy quantity). Note that we normalize the style of each fuzz according to the value of relative. Note also that we normalize the shape of each fuzz to ensure Gaussian, since we cannot combine Box shapes into Box (we could combine Box shapes into trapezoids but who needs that?).

Type parameters

T

the underlying type of the incoming Fuzziness.

U

the underlying type of the resulting Fuzziness.

V

the underlying type of the result divided by the input.

Value parameters

fuzz

one of the (optional) Fuzziness values.

g

the function with which to transform the given Fuzziness value

relative

true if we are multiplying, false if we are adding.

t

the magnitude of the input Number.

u

the magnitude of the output Number.

Attributes

Returns

an Option of Fuzziness[T].

def monadicCombine[T : HasValue](t: T)(fuzz: (Option[Fuzziness[T]], Option[Fuzziness[T]])): Option[Fuzziness[T]]

Combines two potential fuzziness values for a given type T using a monadic approach.

Combines two potential fuzziness values for a given type T using a monadic approach.

Type parameters

T

The type of the input value and fuzziness values, which must have an implicit HasValue type class instance available.

Value parameters

fuzz

A tuple containing two optional fuzziness values of type T to be combined.

t

The input value of type T that will be used during the combination.

Attributes

Returns

An optional fuzziness of type T resulting from the monadic combination of the provided fuzziness values.

def monadicFuzziness(op: MonadicOperation, t: Double, x: Double, fuzz: Option[Fuzziness[Double]]): Option[Fuzziness[Double]]

Calculate the fuzziness for the result of a MonadicOperation.

Calculate the fuzziness for the result of a MonadicOperation.

We work entirely in relative space. The functionFuzz is the input fuzz propagated through the derivative of the operation; the opFuzz is the machine's implementation error for computing the function. These two sources are independent, so they are combined via RSS convolution. The output x is not needed here because we return relative fuzz, leaving any conversion to absolute to the caller.

Value parameters

fuzz

the (optional) fuzziness of input to the monadic operation.

op

the monadic operation.

t

the magnitude of the input to the monadic operation.

x

the magnitude of the result of the monadic operation (not used directly).

Attributes

Returns

the optional fuzziness for the result of the monadic operation.

def scaleTransform[T : HasValue](k: Double): Fuzziness[T] => Fuzziness[T]

Method to yield a transformation (i.e. a Fuzziness[T] => Fuzziness[T]) based on a scale constant k.

Method to yield a transformation (i.e. a Fuzziness[T] => Fuzziness[T]) based on a scale constant k.

Type parameters

T

the underlying type.

Value parameters

k

the scale constant.

Attributes

Returns

a function which will transform a Fuzziness[T] into a Fuzziness[T].

def showPercentage(fo: Option[Fuzziness[Double]]): String

Method to represent an optional Fuzziness as a String.

Method to represent an optional Fuzziness as a String.

Value parameters

fo

the fuzziness.

Attributes

Returns

a String which either shows a percentage (ending in '%') or "".

def toDecimalPower(x: Double, n: Int): Double

Apply a decimal exponent of n to x and return the new value. CONSIDER using BigDecimal for more precision (see AbsoluteFuzz.round)

Apply a decimal exponent of n to x and return the new value. CONSIDER using BigDecimal for more precision (see AbsoluteFuzz.round)

Value parameters

n

the size of the exponent.

x

a Double.

Attributes

Returns

the result.

def zipStrings(v: String, t: String): String

Combines two strings by replacing characters from the first string with corresponding characters from the second string whenever they are non-zero ('0').

Combines two strings by replacing characters from the first string with corresponding characters from the second string whenever they are non-zero ('0').

NOTE used by AbsoluteFuzz.toString

Value parameters

t

the second string providing replacement characters.

v

the first string to process, with characters to be potentially replaced.

Attributes

Returns

a new string where characters from the first string are replaced by non-zero characters from the second string at the same positions.

Concrete fields

lazy val doublePrecision: Fuzziness[Double]

This is the (approximate) fuzziness caused in general by trying to represent numbers in double precision. Of course, many numbers can be represented exactly by double-precision. But not all.

This is the (approximate) fuzziness caused in general by trying to represent numbers in double precision. Of course, many numbers can be represented exactly by double-precision. But not all.

Attributes

Returns

a Fuzziness[Double].

val doublePrecisionFloor: Double

The floor below which a fuzz magnitude is considered pure double-precision noise. Two fuzz values both below this threshold are combined by scaling the larger by sqrt(2), rather than by full convolution, to avoid spurious shape promotion.

The floor below which a fuzz magnitude is considered pure double-precision noise. Two fuzz values both below this threshold are combined by scaling the larger by sqrt(2), rather than by full convolution, to avoid spurious shape promotion.

Attributes

val negligibleRatio: Double

A constant value representing the threshold ratio between large and small values, above which the smaller fuzz contribution is considered negligible in the combined quadrature result. Specifically, if large/small > this ratio, the smaller fuzz contributes less than 0.5% and is treated as insignificant. If large/small > 10, the smaller fuzz contributes < 0.5% to the combined quadrature result and is treated as negligible.

A constant value representing the threshold ratio between large and small values, above which the smaller fuzz contribution is considered negligible in the combined quadrature result. Specifically, if large/small > this ratio, the smaller fuzz contributes less than 0.5% and is treated as insignificant. If large/small > 10, the smaller fuzz contributes < 0.5% to the combined quadrature result and is treated as negligible.

Attributes

val oneSigma: Double

Represents a predefined constant, oneSigma, used to define a confidence interval or tolerance level in mathematical or statistical computations. The value of this constant is 0.317, which may be interpreted as within one standard deviation..

Represents a predefined constant, oneSigma, used to define a confidence interval or tolerance level in mathematical or statistical computations. The value of this constant is 0.317, which may be interpreted as within one standard deviation..

Attributes

A constant value representing the square root of 2. This is used when combining two equal fuzz values without changing the underlying shape.

A constant value representing the square root of 2. This is used when combining two equal fuzz values without changing the underlying shape.

Attributes