Scaling

trait Scaling

Scaling utilities.

Often, in order to avoid underflow, we can offload some of the exponent of a double into an int. To make things more efficient, we can actually share that exponent between doubles.

The scales used in this trait are in log space: they can be safely added and subtracted.

Companion
object
class Object
trait Matchable
class Any
object Scaling

Value members

Concrete methods

def computeScaleDelta(scores: Array[Double]): Int

Computes the log power of two we'd need to scale by so that the max double is between (2 ** scaleConstant, 2 ** -scaleConstant).

Computes the log power of two we'd need to scale by so that the max double is between (2 ** scaleConstant, 2 ** -scaleConstant).

def determineScale(score: Double, oldScale: Int): Int
def scaleArray(scores: Array[Double], currentScale: Int): Int

Ensures that the max double is between (2scaleConstant,2-scaleConstant), scaling the array as necessary.

Ensures that the max double is between (2scaleConstant,2-scaleConstant), scaling the array as necessary.

Returns

newScale

def scaleArrayToScale(scores: Array[Double], currentScale: Int, targetScale: Int): Unit
def scaleValue(score: Double, currentScale: Int, targetScale: Int): Double

Converts the scaled value into "normal" space

Converts the scaled value into "normal" space

def sumArrays(src: Array[Double], srcScale: Int, dest: Array[Double], destScale: Int): Int

Sums src into dest assuming they're at different scales. src may be longer than dest, which is useful for allocating a large work buffer.

Sums src into dest assuming they're at different scales. src may be longer than dest, which is useful for allocating a large work buffer.

Returns

the new scale

def toLogSpace(score: Double, currentScale: Int): Double
def unscaleValue(score: Double, currentScale: Int): Double

Converts the scaled value into "normal" space

Converts the scaled value into "normal" space

Abstract fields

val scaleConstant: Int

the largest (log) power of two we want to deal with

the largest (log) power of two we want to deal with