當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。