algorithm

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2023 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultDistributionName = "linear"
)

Functions

This section is empty.

Types

type Algorithm

type Algorithm interface {
	Score(record map[string]float64) float64
}

type Bounds

type Bounds struct {
	Lower           float64 `yaml:"lower"`
	Upper           float64 `yaml:"upper"`
	SmallerIsBetter bool    `yaml:"smaller_is_better"`
}

func (Bounds) Apply

func (b Bounds) Apply(v float64) float64

func (Bounds) Threshold

func (b Bounds) Threshold() float64

type Condition

type Condition func(fields map[string]float64) bool

func ExistsCondition

func ExistsCondition(f Field) Condition

func NotCondition

func NotCondition(c Condition) Condition

type ConditionalValue

type ConditionalValue struct {
	Condition Condition
	Inner     Value
}

ConditionalValue wraps an Inner value that will only be returned if the Condition returns true.

func (*ConditionalValue) Value

func (cv *ConditionalValue) Value(fields map[string]float64) (float64, bool)

Value implements the Value interface.

type Distribution

type Distribution struct {
	// contains filtered or unexported fields
}

func LookupDistribution

func LookupDistribution(name string) *Distribution

func (*Distribution) Normalize

func (d *Distribution) Normalize(v float64) float64

func (*Distribution) String

func (d *Distribution) String() string

type Factory

type Factory func(inputs []*Input) (Algorithm, error)

type Field

type Field string

Field implements the Value interface, but simply returns the raw value of the named field.

func (Field) String

func (f Field) String() string

func (Field) Value

func (f Field) Value(fields map[string]float64) (float64, bool)

Value implements the Value interface.

type Input

type Input struct {
	Source       Value
	Bounds       *Bounds
	Distribution *Distribution
	Tags         []string
	Weight       float64
}

func (*Input) Value

func (i *Input) Value(fields map[string]float64) (float64, bool)

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry is used to map a name to a Factory that creates Algorithm instances for the given name.

func NewRegistry

func NewRegistry() *Registry

NewRegistry returns a new Registry instance.

func (*Registry) NewAlgorithm

func (r *Registry) NewAlgorithm(name string, inputs []*Input) (Algorithm, error)

NewAlgorithm generates a new instance of Algorithm for the supplied name and fields.

If the registry does not have a Factory for the supplied name an error will be returned.

If the Algorithm fails to be created by the Factory, an error will also be returned and the Algorithm will be nil.

func (*Registry) Register

func (r *Registry) Register(name string, f Factory)

Register adds the Factory for the corresponding Key to the registry.

If another Factory has been registered with the same Key it will be replaced.

type Value

type Value interface {
	// Value takes in a set of fields does some work and returns either the
	// result and true to indicate success, or 0 and false to indicate
	// the result could not be generated.
	Value(fields map[string]float64) (float64, bool)
}

Directories

Path Synopsis
Package wam implements the Weighted Arithmetic Mean, which forms the basis of Rob Pike's criticality score algorithm as documented in Quantifying_criticality_algorithm.pdf.
Package wam implements the Weighted Arithmetic Mean, which forms the basis of Rob Pike's criticality score algorithm as documented in Quantifying_criticality_algorithm.pdf.

Jump to

Keyboard shortcuts

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