Documentation
¶
Overview ¶
Package rand provides a random number source abstraction for UMAP.
In production, Source wraps math/rand/v2. In tests, a Recorded source plays back prerecorded sequences from the Python reference implementation, enabling byte-for-byte reproducibility verification.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Production ¶
type Production struct {
// contains filtered or unexported fields
}
Production wraps math/rand/v2.Rand as a Source.
func NewProduction ¶
func NewProduction(seed *uint64) *Production
NewProduction creates a new production random source from a seed. If seed is nil, uses an auto-seeded source.
func (*Production) Float64 ¶
func (p *Production) Float64() float64
func (*Production) Intn ¶
func (p *Production) Intn(n int) int
func (*Production) NormFloat64 ¶
func (p *Production) NormFloat64() float64
func (*Production) Perm ¶
func (p *Production) Perm(n int) []int
func (*Production) UniformFloat64 ¶
func (p *Production) UniformFloat64(low, high float64) float64
type Recorded ¶
type Recorded struct {
// contains filtered or unexported fields
}
Recorded plays back prerecorded random sequences. It panics if more values are consumed than were recorded, indicating a divergence between Go and Python call order.
func NewRecorded ¶
func NewRecorded(data RecordedData) *Recorded
NewRecorded creates a Recorded source from a RecordedData struct.
func NewRecordedFromFile ¶
NewRecordedFromFile loads a Recorded source from a JSON file.
func (*Recorded) NormFloat64 ¶
func (*Recorded) UniformFloat64 ¶
type RecordedData ¶
type RecordedData struct {
Ints []int `json:"ints"`
Floats []float64 `json:"floats"`
Norms []float64 `json:"norms"`
Perms [][]int `json:"perms"`
}
RecordedData holds prerecorded random sequences from the Python reference implementation. Each field is a sequence of values consumed in order.
type Source ¶
type Source interface {
// Intn returns a random int in [0, n).
Intn(n int) int
// Float64 returns a random float64 in [0.0, 1.0).
Float64() float64
// NormFloat64 returns a normally distributed float64 (mean=0, stddev=1).
NormFloat64() float64
// Perm returns a random permutation of [0, n).
Perm(n int) []int
// UniformFloat64 returns a random float64 in [low, high).
UniformFloat64(low, high float64) float64
}
Source provides all random operations UMAP needs.