score

package
v4.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 7, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateTimeDecayFunctionUpdate

func CalculateTimeDecayFunctionUpdate(oldScore, newScore ScoreStore, halfLife time.Duration, updateWeight float64, sampleTime time.Time) (normalizedScoreStore ScoreStore, rawScoreStore ScoreStore)

CalculateTimeDecayFunctionUpdate calculates the time decayed score update between two ScoreStore entries. It uses a decay function with a half life of halfLife to factor in the time elapsed since the oldScore was recorded. Both the numerator and the denominator of the newScore are decayed by this function. Additionally, the newScore is factored by a weight of updateWeight. The function returns a new ScoreStore entry with the updated numerator, denominator, and current time.

The mathematical equation used to calculate the update is:

updatedNum = oldScore.Num*exp(-(now-oldScore.Time)/halfLife) + newScore.Num*exp(-(now-newScore.Time)/halfLife)*updateWeight
updatedDenom = oldScore.Denom*exp(-(now-oldScore.Time)/halfLife) + newScore.Denom*exp(-(now-newScore.Time)/halfLife)*updateWeight

where now is the current time.

Note that the returned ScoreStore has a new Time field set to the current time.

Types

type ScoreStore

type ScoreStore struct {
	Num   float64 // for performance i didn't use math/big rationale arithmetic
	Denom float64
	Time  time.Time
}

func NewScoreStore

func NewScoreStore(num, denom float64, inpTime time.Time) ScoreStore

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL