Esempio n. 1
0
func randmatstat(t int) (float64, float64) {
	n := 5
	var v stats.Stats
	var w stats.Stats
	for i := 0; i < t; i++ {
		a := matrix.Zeros(n, n)
		b := matrix.Zeros(n, n)
		c := matrix.Zeros(n, n)
		d := matrix.Zeros(n, n)
		for j := 0; j < n; j++ {
			for k := 0; k < n; k++ {
				a.Set(j, k, rand.NormFloat64())
				b.Set(j, k, rand.NormFloat64())
				c.Set(j, k, rand.NormFloat64())
				d.Set(j, k, rand.NormFloat64())
			}
		}
		P := matrix.Zeros(n, 4*n)
		for j := 0; j < n; j++ {
			for k := 0; k < n; k++ {
				P.Set(j, k, a.Get(j, k))
				P.Set(j, n+k, b.Get(j, k))
				P.Set(j, 2*n+k, c.Get(j, k))
				P.Set(j, 3*n+k, d.Get(j, k))
			}
		}
		Q := matrix.Zeros(2*n, 2*n)
		for j := 0; j < n; j++ {
			for k := 0; k < n; k++ {
				Q.Set(j, k, a.Get(j, k))
				Q.Set(j, n+k, b.Get(j, k))
				Q.Set(n+j, k, c.Get(j, k))
				Q.Set(n+j, n+k, d.Get(j, k))
			}
		}
		P = matrix.Product(matrix.Transpose(P), P)
		P = matrix.Product(P, P)
		P = matrix.Product(P, P)
		Q = matrix.Product(matrix.Transpose(Q), Q)
		Q = matrix.Product(Q, Q)
		Q = matrix.Product(Q, Q)
		v.Update(P.Trace())
		w.Update(Q.Trace())
	}
	return v.PopulationStandardDeviation() / float64(v.Count()) / v.Mean(), w.PopulationStandardDeviation() / float64(w.Count()) / w.Mean()
}
Esempio n. 2
0
func testUnpred(r io.Reader) (float64, float64) {
	dict := make(map[int16]bool)
	buff := make([]byte, 2)
	count := 0
	var prob stats.Stats

	for i := 0; i < TestingRounds; i++ {
		r.Read(buff)
		val := int16(buff[0]) + int16(buff[1])*256

		if _, ok := dict[val]; ok {
			count++
		} else {
			dict[val] = true
		}
		prob.Update(float64(buff[0]))
		prob.Update(float64(buff[1]))
	}

	return float64(count) / float64(TestingRounds),
		prob.PopulationStandardDeviation()
}