Documentation
¶
Overview ¶
Package utils provides shared utilities for datascience including parsing, optimization helpers, and compatibility functions.
Index ¶
- func CartesianProduct(sets [][]int) [][]int
- func Combinations(items []string, k int) [][]string
- func GenerateStateNames(cardinality int) []string
- func Permutations(items []string) [][]string
- func SafePath(path string) (string, error)
- func StateIndex(names []string, name string) (int, error)
- func StateNameMap(variables []string, stateNames map[string][]string) map[string]map[string]int
- func ValidateNoInf(name string, values []float64) error
- func ValidateNoNaN(name string, values []float64) error
- func ValidateNonNegativeFloat(name string, value float64) error
- func ValidatePositiveInt(name string, value int) error
- func ValidateProbability(name string, value float64) error
- func ValidateProbabilityDistribution(name string, values []float64, tolerance float64) error
- func ValidateStateNames(names []string, cardinality int) error
- type ConvergenceChecker
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CartesianProduct ¶
CartesianProduct computes the Cartesian product of integer sets. For example, CartesianProduct([][]int{{0,1},{2,3}}) returns [[0,2],[0,3],[1,2],[1,3]].
func Combinations ¶
Combinations generates all k-element combinations of items. The order of elements within each combination matches their order in items.
func GenerateStateNames ¶
GenerateStateNames produces default state names ["s0", "s1", ..., "s{n-1}"].
func Permutations ¶
Permutations generates all permutations of items using Heap's algorithm.
func SafePath ¶ added in v0.1.1
SafePath validates that a file path does not contain directory traversal sequences or other dangerous patterns.
func StateIndex ¶
StateIndex returns the index of name within names, or an error if not found.
func StateNameMap ¶
StateNameMap builds a mapping from variable name to state name to index. variables lists the variable names; stateNames maps each variable to its ordered slice of state names.
func ValidateNoInf ¶
ValidateNoInf returns an error if any value is infinite.
func ValidateNoNaN ¶
ValidateNoNaN returns an error if any value is NaN.
func ValidateNonNegativeFloat ¶
ValidateNonNegativeFloat returns an error if value is negative.
func ValidatePositiveInt ¶
ValidatePositiveInt returns an error if value is not strictly positive.
func ValidateProbability ¶
ValidateProbability returns an error if value is not in [0, 1].
func ValidateProbabilityDistribution ¶
ValidateProbabilityDistribution returns an error if the values do not sum to 1 within the given tolerance.
func ValidateStateNames ¶
ValidateStateNames checks that names has the expected length and contains no duplicates.
Types ¶
type ConvergenceChecker ¶
type ConvergenceChecker struct {
// contains filtered or unexported fields
}
ConvergenceChecker tracks a scalar value across iterations and determines whether it has converged (i.e., the absolute change falls below a tolerance).
func NewConvergenceChecker ¶
func NewConvergenceChecker(tolerance float64, maxIter int) *ConvergenceChecker
NewConvergenceChecker creates a ConvergenceChecker with the given tolerance and maximum iteration count.
func (*ConvergenceChecker) Converged ¶
func (c *ConvergenceChecker) Converged() bool
Converged returns whether convergence has been detected.
func (*ConvergenceChecker) Iterations ¶
func (c *ConvergenceChecker) Iterations() int
Iterations returns the number of Update calls so far.
func (*ConvergenceChecker) Reset ¶
func (c *ConvergenceChecker) Reset()
Reset clears the checker state so it can be reused.
func (*ConvergenceChecker) Update ¶
func (c *ConvergenceChecker) Update(value float64) bool
Update records a new value and returns true if the checker has converged (the absolute change from the previous value is less than tolerance) or the maximum number of iterations has been reached.