Documentation
¶
Overview ¶
Package stats provides small, dependency-free numerical helpers — the descriptive statistics, histogram, mode, argmax, normalized cross-correlation and peak-finding that the signal-analysis paths reach for. They are the native Go equivalents of the handful of numpy/scipy routines the demod and sync-landscape analyses lean on (numpy.mean/std/histogram, numpy.argmax, scipy.signal.find_peaks, scipy.signal.correlate), so those operations live in one tested place instead of being re-derived inline.
Everything is float64/int and stdlib-only, matching the sibling leaf packages (window, fft) — no gonum, no CGO.
Index ¶
- func ArgMax(x []float64) int
- func ArgMaxInt(x []int) int
- func ArgMin(x []float64) int
- func Correlate(a, b []float64) (corr []float64, peakLag int)
- func FindPeaks(y []float64, opts PeakOpts) []int
- func Histogram(x []float64, nbins int) (counts []int, edges []float64)
- func Max(x []float64) (val float64, idx int)
- func Mean(x []float64) float64
- func Min(x []float64) (val float64, idx int)
- func ModeInt(x []int) int
- func StdDev(x []float64, sample bool) float64
- func Variance(x []float64, sample bool) float64
- type PeakOpts
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ArgMax ¶
ArgMax returns the index of the largest value in x (numpy.argmax), or -1 for empty input. Ties resolve to the first (lowest) index.
func ArgMaxInt ¶
ArgMaxInt returns the index of the largest value in an integer slice, or -1 for empty input. Ties resolve to the first (lowest) index. It generalises the "pick the winner by hit count" selection in the sync-landscape analysis.
func ArgMin ¶
ArgMin returns the index of the smallest value in x (numpy.argmin), or -1 for empty input. Ties resolve to the first (lowest) index.
func Correlate ¶
Correlate returns the full normalized cross-correlation of a and b (numpy.correlate / scipy.signal.correlate, mode="full"), together with the lag of its peak. Each output sample is divided by sqrt(Σa²·Σb²), so a sequence correlated against itself peaks at exactly 1.0.
The output has length len(a)+len(b)-1. Index k corresponds to lag s = k-(len(b)-1): the value is Σ a[i]·b[i-s] over the overlapping region. peakLag is the lag s maximizing the correlation — equivalently, the offset into a at which b best aligns (so a pattern b embedded in a at index p peaks at peakLag == p). Returns (nil, 0) when either input is empty.
func FindPeaks ¶
FindPeaks returns the indices of the local maxima in y that satisfy opts, sorted by descending height (strongest first). A sample is a local maximum when it is strictly greater than its left neighbour and greater than or equal to its right neighbour (the ">=" right rule keeps the left-most index of a flat top, matching the carrier-search convention this generalises). Returns nil for empty input or when no peak clears the thresholds.
func Histogram ¶
Histogram bins x into nbins equal-width bins spanning [min(x), max(x)] (numpy.histogram). It returns the per-bin counts (length nbins) and the nbins+1 bin edges. Values equal to the right-most edge fall in the last bin, matching numpy. Returns (nil, nil) when nbins < 1 or x is empty.
func ModeInt ¶
ModeInt returns the most frequent value in x. Ties resolve toward the smaller value, matching the sync-landscape modal-spacing convention it generalises. Returns 0 for empty input.
func StdDev ¶
StdDev returns the standard deviation of x (sqrt of Variance), honouring the same sample/population choice as Variance.
Types ¶
type PeakOpts ¶
type PeakOpts struct {
// Height is an absolute minimum: peaks with y < Height are dropped. 0
// disables the absolute floor.
Height float64
// RelHeight keeps only peaks at least RelHeight·max(peak) tall (a relative
// floor, e.g. 0.01 ≈ 20 dB down). 0 disables it. When both Height and
// RelHeight are set the stricter threshold wins.
RelHeight float64
// MinDistance is the minimum index spacing between kept peaks. When peaks
// are closer, the taller one wins (greedy, strongest first). 0 disables
// spacing suppression.
MinDistance int
// IncludeEnds treats the first and last samples as candidate maxima (a peak
// at a band edge still qualifies). When false they are never peaks, matching
// scipy's default.
IncludeEnds bool
}
PeakOpts constrains FindPeaks, mirroring a minimal subset of scipy.signal.find_peaks. A zero value finds every interior local maximum.