Documentation ¶
Overview ¶
Package erand provides randomization functionality built on top of standard math/rand random number generation functions. Includes:
- RndParams: specifies parameters for random number generation according to various distributions used e.g., for initializing random weights and generating random noise in neurons
- Permute*: basic convenience methods calling rand.Shuffle on e.g., []int slice
Index ¶
- Variables
- func Bet(a, b float64, thr int) float64
- func Binom(n, p float64, thr int) float64
- func BoolP(p float32) bool
- func BoolProb(p float64, thr int) bool
- func Discrete(dist []float64, thr int) int
- func Gam(v, k float64, thr int) float64
- func Gauss(stdev float64, thr int) float64
- func IntMeanRange(mean, rnge int64, thr int) int64
- func IntMinMax(min, max int64, thr int) int64
- func IntZeroN(n int64, thr int) int64
- func PChoose32(ps []float32) int
- func PChoose64(ps []float64) int
- func PermuteInts(ins []int)
- func PermuteStrings(ins []string)
- func Permutefloat32s(ins []float32)
- func Permutefloat64s(ins []float64)
- func Poiss(lmb float64, thr int) float64
- func UniformMeanRange(mean, rnge float64, thr int) float64
- func UniformMinMax(min, max float64, thr int) float64
- func ZeroOne(thr int) float64
- type RndDists
- type RndParams
Constants ¶
This section is empty.
Variables ¶
var KiT_RndDists = kit.Enums.AddEnum(RndDistsN, kit.NotBitFlag, nil)
Functions ¶
func BoolP ¶ added in v0.5.3
BoolP is a simple method to generate a true value with given probability (else false). is just rand.Float32() < p but this is more readable and explicit
func Discrete ¶
Discrete samples from a discrete distribution with probabilities given (automatically renormalizes the values). Returns the index of the element of dist.
func Gam ¶
Gam represents maximum entropy distribution with two parameters: scaling parameter (Var, Beta) and shape parameter k (Par, Alpha)
func IntMeanRange ¶
IntMeanRange returns uniform random integer with given range on either side of the mean: [mean - range, mean + range]
func IntMinMax ¶
IntMinMax returns uniform random integer in range between min and max, exclusive of max: [min,max).
func IntZeroN ¶
IntZeroN returns uniform random integer in the range between 0 and n, exclusive of n: [0,n).
func PChoose32 ¶ added in v0.5.3
PChoose32 chooses an index in given slice of float32's at random according to the probilities of each item (must be normalized to sum to 1)
func PChoose64 ¶ added in v0.5.3
PChoose64 chooses an index in given slice of float64's at random according to the probilities of each item (must be normalized to sum to 1)
func PermuteInts ¶
func PermuteInts(ins []int)
PermuteInts permutes (shuffles) the order of elements in the given int slice using the standard Fisher-Yates shuffle https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle So you don't have to remember how to call rand.Shuffle
func PermuteStrings ¶
func PermuteStrings(ins []string)
PermuteStrings permutes (shuffles) the order of elements in the given string slice using the standard Fisher-Yates shuffle https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle So you don't have to remember how to call rand.Shuffle
func Permutefloat32s ¶
func Permutefloat32s(ins []float32)
PermuteFloat32s permutes (shuffles) the order of elements in the given float32 slice using the standard Fisher-Yates shuffle https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle So you don't have to remember how to call rand.Shuffle
func Permutefloat64s ¶
func Permutefloat64s(ins []float64)
PermuteFloat64s permutes (shuffles) the order of elements in the given float64 slice using the standard Fisher-Yates shuffle https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle So you don't have to remember how to call rand.Shuffle
func Poiss ¶
Poiss returns poisson variable, as number of events in interval, with event rate (lmb = Var) plus mean
func UniformMeanRange ¶
UniformMeanRange returns uniform random number with given range on either size of the mean: [mean - range, mean + range]
func UniformMinMax ¶
UniformMinMax returns uniform random number between min and max values inclusive (Do not use for generating integers - will not include max!)
Types ¶
type RndDists ¶
type RndDists int
RndDists are different random number distributions
const ( // Uniform has a uniform probability distribution over var = range on either side of the mean Uniform RndDists = iota // Binomial represents number of 1's in n (Par) random (Bernouli) trials of probability p (Var) Binomial // Poisson represents number of events in interval, with event rate (lambda = Var) plus mean Poisson // Gamma represents maximum entropy distribution with two parameters: scaling parameter (Var) // and shape parameter k (Par) plus mean Gamma // Gaussian normal with Var = stddev plus mean Gaussian // Beta with var = a and par = b shape parameters Beta // Mean is just the constant mean, no randomness Mean RndDistsN )
The random number distributions
func (*RndDists) FromString ¶
func (RndDists) MarshalJSON ¶
func (*RndDists) UnmarshalJSON ¶
type RndParams ¶
type RndParams struct { Dist RndDists `desc:"distribution to generate random numbers from"` Mean float64 `desc:"mean of random distribution -- typically added to generated random variants"` Var float64 `` /* 145-byte string literal not displayed */ Par float64 `view:"if Dist=Gamma,Binomial,Beta" desc:"extra parameter for distribution (depends on each one)"` }
RndParams provides parameterized random number generation according to different distributions and variance, mean params