本文整理汇总了Golang中math/rand.Rand.NormFloat64方法的典型用法代码示例。如果您正苦于以下问题:Golang Rand.NormFloat64方法的具体用法?Golang Rand.NormFloat64怎么用?Golang Rand.NormFloat64使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类math/rand.Rand
的用法示例。
在下文中一共展示了Rand.NormFloat64方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: randomSlice
// randomSlice allocates a new slice of length n filled with random values.
func randomSlice(n int, rnd *rand.Rand) []float64 {
s := make([]float64, n)
for i := range s {
s[i] = rnd.NormFloat64()
}
return s
}
示例2: randomSchurCanonical
// randomSchurCanonical returns a random, general matrix in Schur canonical
// form, that is, block upper triangular with 1×1 and 2×2 diagonal blocks where
// each 2×2 diagonal block has its diagonal elements equal and its off-diagonal
// elements of opposite sign.
func randomSchurCanonical(n, stride int, rnd *rand.Rand) blas64.General {
t := randomGeneral(n, n, stride, rnd)
// Zero out the lower triangle.
for i := 0; i < t.Rows; i++ {
for j := 0; j < i; j++ {
t.Data[i*t.Stride+j] = 0
}
}
// Randomly create 2×2 diagonal blocks.
for i := 0; i < t.Rows; {
if i == t.Rows-1 || rnd.Float64() < 0.5 {
// 1×1 block.
i++
continue
}
// 2×2 block.
// Diagonal elements equal.
t.Data[(i+1)*t.Stride+i+1] = t.Data[i*t.Stride+i]
// Off-diagonal elements of opposite sign.
c := rnd.NormFloat64()
if math.Signbit(c) == math.Signbit(t.Data[i*t.Stride+i+1]) {
c *= -1
}
t.Data[(i+1)*t.Stride+i] = c
i += 2
}
return t
}
示例3: testRandomSimplex
func testRandomSimplex(t *testing.T, nTest int, pZero float64, maxN int, rnd *rand.Rand) {
// Try a bunch of random LPs
for i := 0; i < nTest; i++ {
n := rnd.Intn(maxN) + 2 // n must be at least two.
m := rnd.Intn(n-1) + 1 // m must be between 1 and n
if m == 0 || n == 0 {
continue
}
randValue := func() float64 {
//var pZero float64
v := rnd.Float64()
if v < pZero {
return 0
}
return rnd.NormFloat64()
}
a := mat64.NewDense(m, n, nil)
for i := 0; i < m; i++ {
for j := 0; j < n; j++ {
a.Set(i, j, randValue())
}
}
b := make([]float64, m)
for i := range b {
b[i] = randValue()
}
c := make([]float64, n)
for i := range c {
c[i] = randValue()
}
testSimplex(t, nil, c, a, b, convergenceTol)
}
}
示例4: genrand
// genrand returns a general r×c matrix with random entries.
func genrand(r, c int, rnd *rand.Rand) []float64 {
m := make([]float64, r*c)
for i := range m {
m[i] = rnd.NormFloat64()
}
return m
}
示例5: makeLatency
func (d *Director) makeLatency(rng *rand.Rand, intensity float64) uint {
l := int((20 + rng.NormFloat64()*10) * intensity)
if l < 1 {
return 1
} else {
return uint(l)
}
}
示例6: Normal
// Normal mutation individual modifies an individual's gene if a coin toss is
// under a defined mutation rate. It does so for each gene. The new gene value
// is a random value sampled from a normal distribution centered on the gene's
// current value and with the intensity parameter as it's standard deviation.
func Normal(indi *Individual, mutRate, mutIntensity float64, generator *rand.Rand) {
for i := range indi.Dna {
// Flip a coin and decide to mutate or not
if generator.Float64() <= mutRate {
indi.Dna[i] *= generator.NormFloat64() * mutIntensity
}
}
}
示例7: randomFactor
func randomFactor(n int, r *rand.Rand) Factor {
f := NewFactor(n)
for i, _ := range f {
f[i] = r.NormFloat64()
}
return f
}
示例8: Apply
// Apply normal mutation.
func (mut MutNormalF) Apply(indi *Individual, generator *rand.Rand) {
for i := range indi.Genome {
// Flip a coin and decide to mutate or not
if generator.Float64() < mut.Rate {
// Sample from a normal distribution
indi.Genome[i] = indi.Genome[i].(float64) * generator.NormFloat64() * mut.Std
}
}
}
示例9: Rand
func (n NormalDist) Rand(r *rand.Rand) float64 {
var x float64
if r == nil {
x = rand.NormFloat64()
} else {
x = r.NormFloat64()
}
return x*n.Sigma + n.Mu
}
示例10: hessrand
// hessrand returns a Hessenberg matrix of order n with random non-zero entries
// in column-major format.
func hessrand(n int, rnd *rand.Rand) []float64 {
h := make([]float64, n*n)
for j := 0; j < n; j++ {
for i := 0; i <= min(j+1, n-1); i++ {
h[i+j*n] = rnd.NormFloat64()
}
}
return h
}
示例11: GenU
// GenU generates points p₀,p₁,... spread uniformly on the unit sphere S².
func GenU(r *rand.Rand, p []Geo) {
for i := range p {
x := r.NormFloat64()
y := r.NormFloat64()
z := r.NormFloat64()
v := vec{x, y, z}
p[i] = Geo{v.hat()}
}
}
示例12: mutateTrait
func (m *Trait) mutateTrait(rng *rand.Rand, t neat.Trait, v *float64) {
tv := *v
tv += rng.NormFloat64()
if tv < t.Min {
tv = t.Min
} else if tv > t.Max {
tv = t.Max
}
}
示例13: randomGeneral
// randomGeneral allocates a new r×c general matrix filled with random
// numbers. Out-of-range elements are filled with NaN values.
func randomGeneral(r, c, stride int, rnd *rand.Rand) blas64.General {
ans := nanGeneral(r, c, stride)
for i := 0; i < r; i++ {
for j := 0; j < c; j++ {
ans.Data[i*ans.Stride+j] = rnd.NormFloat64()
}
}
return ans
}
示例14: mutateWeight
// Returns a modified weight
func (m Weight) mutateWeight(rng *rand.Rand, c *neat.Connection) {
c.Weight += rng.NormFloat64()
/*
if w < -m.WeightRange*2 {
w = -m.WeightRange * 2
} else if w > m.WeightRange*2 {
w = m.WeightRange * 2
}
*/
}
示例15: randomGaussian
func randomGaussian(r *rand.Rand, id string, dim int) *gm.Model {
var mean, sd []float64
startSD := 40.0
for i := 0; i < dim; i++ {
mean = append(mean, float64(r.Intn(10)*100.0))
a := r.NormFloat64()*0.2 + 1.0 // pert 0.8 to 1.2
sd = append(sd, startSD*a)
}
return gm.NewModel(dim, gm.Name(id), gm.Mean(mean), gm.StdDev(sd))
}