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


Golang rand.NormFloat64函数代码示例

本文整理汇总了Golang中math/rand.NormFloat64函数的典型用法代码示例。如果您正苦于以下问题:Golang NormFloat64函数的具体用法?Golang NormFloat64怎么用?Golang NormFloat64使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NormFloat64函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: main

func main() {
	rand.Seed(time.Now().Unix())
	flag.Parse()
	data := LoadData(*idstr)
	avail := 0
	sample := len(data.Points) / 10
	for j := 0; j < sample; j++ {
		//sample a few routes, prefere close routes
		idx1 := rand.Intn(len(data.Points))
		target_x := data.Points[idx1].X + rand.NormFloat64()*150
		target_y := data.Points[idx1].Y + rand.NormFloat64()*150
		idx2 := 0
		mindist := 999999.0
		for id, val := range data.Points {
			if id == idx1 {
				continue
			}
			dist := Distance(&plotter.Point{target_x, target_y}, val)
			if dist < mindist {
				mindist = dist
				idx2 = id
			}
		}

		pathes := calcPathesFromTo(idx1, idx2, data.Matrix, 6)
		indep := IndependentPathes(pathes)
		fmt.Println(j, "/", sample)
		avail += len(indep)
	}
	a := float64(avail) / float64(sample)
	f, _ := os.Create(*idstr + ".indepPathes.txt")
	f.Write([]byte(fmt.Sprintf("%v\n", a)))
	fmt.Println(a)
}
开发者ID:spartacus23,项目名称:cobweb,代码行数:34,代码来源:computeRedundancy.go

示例2: TestConvLayerBatchR

func TestConvLayerBatchR(t *testing.T) {
	layer := &ConvLayer{
		FilterCount:  3,
		FilterWidth:  2,
		FilterHeight: 4,
		Stride:       2,
		InputHeight:  17,
		InputWidth:   19,
		InputDepth:   5,
	}
	layer.Randomize()

	n := 3
	batchInput := make(linalg.Vector, n*layer.InputWidth*layer.InputHeight*layer.InputDepth)
	for i := range batchInput {
		batchInput[i] = rand.NormFloat64()
	}
	batchRes := &autofunc.Variable{Vector: batchInput}

	params := []*autofunc.Variable{batchRes, layer.Biases, layer.FilterVar}

	rVec := autofunc.RVector{}
	for _, param := range params {
		vec := make(linalg.Vector, len(param.Vector))
		for i := range vec {
			vec[i] = rand.NormFloat64()
		}
		rVec[param] = vec
	}

	testRBatcher(t, rVec, layer, autofunc.NewRVariable(batchRes, rVec), n, params)
}
开发者ID:unixpickle,项目名称:weakai,代码行数:32,代码来源:conv_layer_test.go

示例3: benchmarkConvLayer

func benchmarkConvLayer(b *testing.B, layer *ConvLayer) {
	b.Run("Forward", func(b *testing.B) {
		benchmarkConvLayerForward(b, layer)
	})
	b.Run("Backward", func(b *testing.B) {
		benchmarkConvLayerBackward(b, layer)
	})
	b.Run("Parallel", func(b *testing.B) {
		parallelism := runtime.GOMAXPROCS(0)
		inputs := make(chan *autofunc.Variable, parallelism)
		upstreams := make(chan linalg.Vector, parallelism)
		grads := make(chan autofunc.Gradient, parallelism)
		for i := 0; i < parallelism; i++ {
			testInput := NewTensor3(layer.InputWidth, layer.InputHeight, layer.InputDepth)
			for i := range testInput.Data {
				testInput.Data[i] = rand.NormFloat64()
			}
			inputVar := &autofunc.Variable{Vector: testInput.Data}
			inputs <- inputVar
			upstream := make(linalg.Vector, len(layer.Apply(inputVar).Output()))
			for i := range upstream {
				upstream[i] = rand.NormFloat64()
			}
			upstreams <- upstream
			grad := autofunc.NewGradient(layer.Parameters())
			grads <- grad
		}
		b.ResetTimer()
		b.RunParallel(func(pb *testing.PB) {
			benchmarkConvLayerParallel(pb, layer, <-inputs, <-upstreams, <-grads)
		})
	})
}
开发者ID:unixpickle,项目名称:weakai,代码行数:33,代码来源:conv_layer_test.go

示例4: TestMatMul

func TestMatMul(t *testing.T) {
	const (
		m = 3
		k = 4
		n = 5
	)

	alpha := rand.NormFloat64()
	a, b := randMat(m, k), randMat(k, n)
	got := blas.MatMul(alpha, a, b)
	want := mat.Scale(alpha, mat.Mul(a, b))
	checkEqualMat(t, want, got, 1e-9)

	// Try with non-copying transposes.
	alpha = rand.NormFloat64()
	a, b = randMat(k, m).T(), randMat(k, n)
	got = blas.MatMul(alpha, a, b)
	want = mat.Scale(alpha, mat.Mul(a, b))
	checkEqualMat(t, want, got, 1e-9)

	alpha = rand.NormFloat64()
	a, b = randMat(m, k), randMat(n, k).T()
	got = blas.MatMul(alpha, a, b)
	want = mat.Scale(alpha, mat.Mul(a, b))
	checkEqualMat(t, want, got, 1e-9)

	alpha = rand.NormFloat64()
	a, b = randMat(k, m).T(), randMat(n, k).T()
	got = blas.MatMul(alpha, a, b)
	want = mat.Scale(alpha, mat.Mul(a, b))
	checkEqualMat(t, want, got, 1e-9)
}
开发者ID:jvlmdr,项目名称:lin-go,代码行数:32,代码来源:dgemm_test.go

示例5: TestMaxPoolingBatchR

func TestMaxPoolingBatchR(t *testing.T) {
	layer := &MaxPoolingLayer{
		XSpan:       5,
		YSpan:       4,
		InputWidth:  17,
		InputHeight: 19,
		InputDepth:  3,
	}

	n := 3
	batchInput := make(linalg.Vector, n*layer.InputWidth*layer.InputHeight*layer.InputDepth)
	for i := range batchInput {
		batchInput[i] = rand.NormFloat64()
	}
	batchRes := &autofunc.Variable{Vector: batchInput}

	rVec := autofunc.RVector{
		batchRes: make(linalg.Vector, len(batchInput)),
	}
	for i := range rVec[batchRes] {
		rVec[batchRes][i] = rand.NormFloat64()
	}

	testRBatcher(t, rVec, layer, autofunc.NewRVariable(batchRes, rVec),
		n, []*autofunc.Variable{batchRes})
}
开发者ID:unixpickle,项目名称:weakai,代码行数:26,代码来源:max_pooling_layer_test.go

示例6: TestSolveLUVec

func (s *S) TestSolveLUVec(c *check.C) {
	for _, n := range []int{5, 10} {
		a := NewDense(n, n, nil)
		for i := 0; i < n; i++ {
			for j := 0; j < n; j++ {
				a.Set(i, j, rand.NormFloat64())
			}
		}
		b := NewVector(n, nil)
		for i := 0; i < n; i++ {
			b.SetVec(i, rand.NormFloat64())
		}
		var lu LU
		lu.Factorize(a)
		var x Vector
		if err := x.SolveLUVec(&lu, false, b); err != nil {
			continue
		}
		var got Vector
		got.MulVec(a, &x)
		if !got.EqualsApproxVec(b, 1e-12) {
			c.Error("Solve mismatch n = %v.\nWant: %v\nGot: %v", n, b, got)
		}
	}
	// TODO(btracey): Add testOneInput test when such a function exists.
}
开发者ID:jmptrader,项目名称:matrix,代码行数:26,代码来源:lu_test.go

示例7: Point3dNormal

// Return a random point from the Normal distribution.
//
func Point3dNormal() Point3d {
	return Point3d{
		rand.NormFloat64(),
		rand.NormFloat64(),
		rand.NormFloat64(),
	}
}
开发者ID:glenn-brown,项目名称:vu,代码行数:9,代码来源:point3d.go

示例8: addNode

func (b *block) addNode(n node) {
	if !b.nodes[n] {
		b.Add(n)
		n.Move(Pt(rand.NormFloat64(), rand.NormFloat64()))
		b.nodes[n] = true
		n.setBlock(b)
		switch n := n.(type) {
		case *callNode:
			if n.obj != nil && !isMethod(n.obj) {
				b.func_().addPkgRef(n.obj)
			}
		case *compositeLiteralNode:
			// handled in compositeLiteralNode.setType
		case *valueNode:
			switch obj := n.obj.(type) {
			case *types.Const, *types.Var:
				b.func_().addPkgRef(obj)
			case *types.Func:
				if !isMethod(obj) {
					b.func_().addPkgRef(obj)
				}
			}
		}
		rearrange(b)
	}
}
开发者ID:gordonklaus,项目名称:flux,代码行数:26,代码来源:block.go

示例9: Noise

func Noise(l int) *ComplexV {
	r := Zeros(l)
	for k, _ := range *r {
		(*r)[k] = complex(rand.NormFloat64(), rand.NormFloat64())
	}
	return r
}
开发者ID:a4a881d4,项目名称:gosse,代码行数:7,代码来源:cmplxv.go

示例10: generateMoveTrack

func generateMoveTrack(xPosAnswer int) [][]int {
	totalFrames := int(xPosAnswer/2) + rand.Intn(5)

	moveTrack := make([][]int, totalFrames)
	moveTrack[0] = []int{int(-rand.NormFloat64()*8.0 - 20.0), int(-rand.NormFloat64()*8.0 - 20.0), 0}
	moveTrack[1] = []int{0, 0, 0}

	periodParam := rand.Float64()
	for i := 2; i < totalFrames; i++ {
		moveTrack[i] = []int{0, int(math.Sin(float64(i)*periodParam*0.08) * 4.0), i*8 + rand.Intn(5)}
	}

	xPosBitmap := make([]bool, xPosAnswer)
	for i := 0; i < totalFrames-4; {
		t := &xPosBitmap[rand.Intn(xPosAnswer-1)]
		if !*t {
			*t = true
			i++
		}
	}
	xPosBitmap[xPosAnswer-1] = true

	k := 2
	for i, v := range xPosBitmap {
		if v {
			moveTrack[k][0] = i + 1
			k++
		}
	}

	copy(moveTrack[totalFrames-1], moveTrack[totalFrames-2])
	moveTrack[totalFrames-1][2] += 100 + rand.Intn(300)

	return moveTrack
}
开发者ID:AvAudioPlayer,项目名称:scripts,代码行数:35,代码来源:geetest-bypass.go

示例11: tree0

func tree0(f croot.File) {
	// create a tree
	tree := croot.NewTree("tree", "tree", 32)
	e := &Event{}
	const bufsiz = 32000

	tree.Branch("evt", e, bufsiz, 0)

	// fill some events with random numbers
	nevents := *evtmax
	for iev := 0; iev != nevents; iev++ {
		if iev%1000 == 0 {
			fmt.Printf(":: processing event %d...\n", iev)
		}

		// the two energies follow a gaussian distribution
		e.A.E = rand.NormFloat64() //ea
		e.B.E = rand.NormFloat64() //eb

		e.A.T = croot.GRandom.Rndm(1)
		e.B.T = e.A.T * croot.GRandom.Gaus(0., 1.)
		if iev%1000 == 0 {
			fmt.Printf("ievt: %d\n", iev)
			fmt.Printf("evt.a.e= %8.3f\n", e.A.E)
			fmt.Printf("evt.a.t= %8.3f\n", e.A.T)
			fmt.Printf("evt.b.e= %8.3f\n", e.B.E)
			fmt.Printf("evt.b.t= %8.3f\n", e.B.T)
		}
		tree.Fill()
	}
	f.Write("", 0, 0)
}
开发者ID:sbinet,项目名称:go-io-benchs,代码行数:32,代码来源:main.go

示例12: testBatchRGradienter

func testBatchRGradienter(t *testing.T, batchSize int, b *BatchRGradienter) {
	rand.Seed(batchRGradienterSeed)

	net := Network{
		&DenseLayer{
			InputCount:  10,
			OutputCount: 30,
		},
		&Sigmoid{},
		&DenseLayer{
			InputCount:  30,
			OutputCount: 3,
		},
		&Sigmoid{},
	}
	net.Randomize()
	b.Learner = net.BatchLearner()

	inputs := make([]linalg.Vector, batchSize)
	outputs := make([]linalg.Vector, batchSize)
	for i := range inputs {
		inputVec := make(linalg.Vector, 10)
		outputVec := make(linalg.Vector, 3)
		for j := range inputVec {
			inputVec[j] = rand.NormFloat64()
		}
		for j := range outputVec {
			outputVec[j] = rand.Float64()
		}
		inputs[i] = inputVec
		outputs[i] = outputVec
	}
	samples := VectorSampleSet(inputs, outputs)

	rVector := autofunc.RVector(autofunc.NewGradient(net.Parameters()))
	for _, vec := range rVector {
		for i := range vec {
			vec[i] = rand.NormFloat64()
		}
	}

	single := SingleRGradienter{Learner: net, CostFunc: b.CostFunc}
	expectedGrad := single.Gradient(samples)
	actualGrad := b.Gradient(samples)

	if !vecMapsEqual(expectedGrad, actualGrad) {
		t.Error("bad gradient from Gradient()")
	}

	expectedGrad, expectedRGrad := single.RGradient(rVector, samples)
	actualGrad, actualRGrad := b.RGradient(rVector, samples)

	if !vecMapsEqual(expectedGrad, actualGrad) {
		t.Error("bad gradient from RGradient()")
	}
	if !vecMapsEqual(expectedRGrad, actualRGrad) {
		t.Error("bad r-gradient from RGradient()")
	}
}
开发者ID:unixpickle,项目名称:weakai,代码行数:59,代码来源:batch_rgradienter_test.go

示例13: Run

func (*Tool) Run(args []string) {
	fmt.Println("running logistic regression")

	n := 1000
	p := 10

	beta := make([]float64, p)
	beta[0] = rand.NormFloat64()
	beta[1] = rand.NormFloat64()

	x := la.NewMatrix(n, p)
	y := la.NewVector(n)

	for i := 0; i < n; i++ {

		v := randVec(p)

		var z float64

		for j := 0; j < p; j++ {
			x.Set(i, j, v[j])
			z += beta[j]
		}

		if z > 0 {
			y.Set(i, +1)
		} else {
			y.Set(i, -1)
		}
	}

	rp := &model.RegressionProblem{
		N:            n,
		P:            p,
		Data:         x,
		Response:     y,
		ColumnNames:  names("p", p),
		RowNames:     names("x", n),
		ResponseName: "y",
	}

	rc := &model.LogisticRegressionRisk{}
	pc := model.NewLassoPenalty(p)

	dv := 0.001
	vmax := 0.07

	mon := &FixedVMonitor{vmax}

	oa := &model.RandomAssigner{rp.Data.Rows, 2.0 / 3.0}

	tt := oa.Assign()

	results := model.RunGpsFull(rp, tt, dv, rc, pc, mon.Continue)

	fmt.Println(results)

}
开发者ID:rygomez,项目名称:goutil,代码行数:58,代码来源:logistic.go

示例14: ComplexNormal

// Create random matrix with element's real and imaginary parts
// from [0.0, 1.0).
func ComplexNormal(rows, cols int) *ComplexMatrix {
	A := ComplexZeros(rows, cols)
	for i, _ := range A.elements {
		re := rand.NormFloat64()
		im := rand.NormFloat64()
		A.elements[i] = complex(re, im)
	}
	return A
}
开发者ID:sguzwf,项目名称:algorithm,代码行数:11,代码来源:cdense.go

示例15: CreateIndis

func CreateIndis(anzindis int64, stddev, center_x, center_y float64) []*plotter.Point {
	list := make([]*plotter.Point, 0, anzindis)
	for i := 0; i < int(anzindis); i++ {
		indi := new(plotter.Point)
		indi.X = (rand.NormFloat64() * stddev) + center_x
		indi.Y = (rand.NormFloat64() * stddev) + center_y
		list = append(list, indi)
	}
	return list
}
开发者ID:spartacus23,项目名称:cobweb,代码行数:10,代码来源:generateGraph.go


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