prob

package
v0.0.0-...-75eaa32 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

package prob defines various types and functions for manipulating discrete probability distributions

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Comparator

type Comparator[T any] = func(a, b T) int

type Dist

type Dist[T any] struct {
	// contains filtered or unexported fields
}

a discrete probability distribution

func FlatMap

func FlatMap[T any, U any](
	dist Dist[T],
	mapper func(T) Dist[U],
) (Dist[U], error)

FlatMap maps each outcome of a probability distribution of outcome T to a new probability distribution with outcome U and flattens the results into a single distribution of outcome U

func FromConst

func FromConst[T any](v T) (Dist[T], error)

FromConst returns a distribution whose sole outcome is v

func FromEntries

func FromEntries[T any](m []EntryT[T]) (Dist[T], error)

func FromMap

func FromMap[T comparable](m MapT[T]) (Dist[T], error)

func Map

func Map[T any, U any](
	dist Dist[T],
	mapper func(T) U,
) (Dist[U], error)

Map maps a probability distribution from outcome type T to U

func Reduce

func Reduce[T any, U any](
	dists []Dist[T],
	collector func(U, T) U,
	initialValue U,
) (Dist[U], error)

reduces probability distributions of multiple independent events into an aggregate probability distribution

func (Dist[T]) Distribution

func (d Dist[T]) Distribution() Dist[T]

func (Dist[T]) Format

func (d Dist[T]) Format(w fmt.State, v rune)

func (Dist[T]) Iter

func (d Dist[T]) Iter() iter.Seq2[T, *big.Rat]

func (Dist[T]) Keys

func (d Dist[T]) Keys() []Key

func (Dist[T]) Lookup

func (d Dist[T]) Lookup(k Key) (EntryT[T], bool)

func (Dist[T]) Median

func (d Dist[T]) Median(cmp func(T, T) int) T

func (Dist[T]) Percentile

func (d Dist[T]) Percentile(p float64, cmp func(T, T) int) T

func (Dist[T]) StringKey

func (d Dist[T]) StringKey() string

type EntryT

type EntryT[T any] = util.Entry[T, *big.Rat]

type Key

type Key string

type MapT

type MapT[T comparable] = map[T]*big.Rat

type StringKeyer

type StringKeyer interface {
	StringKey() string
}

Jump to

Keyboard shortcuts

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