当前位置: 首页>>代码示例>>Golang>>正文


Golang Rand.NormFloat64方法代码示例

本文整理汇总了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
}
开发者ID:rawlingsj,项目名称:gofabric8,代码行数:8,代码来源:general.go

示例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
}
开发者ID:rawlingsj,项目名称:gofabric8,代码行数:32,代码来源:general.go

示例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)
	}
}
开发者ID:sbinet,项目名称:gonum-optimize,代码行数:35,代码来源:simplex_test.go

示例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
}
开发者ID:rawlingsj,项目名称:gofabric8,代码行数:8,代码来源:main.go

示例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)
	}
}
开发者ID:WIZARD-CXY,项目名称:golang-devops-stuff,代码行数:8,代码来源:director.go

示例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
		}
	}
}
开发者ID:NyorJa,项目名称:gago,代码行数:12,代码来源:mutation.go

示例7: randomFactor

func randomFactor(n int, r *rand.Rand) Factor {

	f := NewFactor(n)
	for i, _ := range f {
		f[i] = r.NormFloat64()
	}
	return f
}
开发者ID:theseusyang,项目名称:occult,代码行数:8,代码来源:cf.go

示例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
		}
	}
}
开发者ID:tomzhang,项目名称:gago,代码行数:10,代码来源:mutation.go

示例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
}
开发者ID:rchunping,项目名称:go-gcstats,代码行数:9,代码来源:normaldist.go

示例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
}
开发者ID:rawlingsj,项目名称:gofabric8,代码行数:11,代码来源:main.go

示例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()}
	}
}
开发者ID:reconditematter,项目名称:stats2,代码行数:10,代码来源:geo.go

示例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
	}
}
开发者ID:NioTeX,项目名称:neat,代码行数:9,代码来源:trait.go

示例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
}
开发者ID:rawlingsj,项目名称:gofabric8,代码行数:11,代码来源:general.go

示例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
		}
	*/
}
开发者ID:NioTeX,项目名称:neat,代码行数:11,代码来源:weight.go

示例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))
}
开发者ID:henrylee2cn,项目名称:gjoa,代码行数:11,代码来源:model_test.go


注:本文中的math/rand.Rand.NormFloat64方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。