// SkewMeanSd calculates the skewness of a dataset
193448
func SkewMeanSd(data Interface, mean, sd float64) (skew float64) {
	Len := data.Len()

	for i := 0; i < Len; i++ {
		x := (data.Get(i) - mean) / sd
		skew += (x*x*x - skew) / float64(i+1)
	}
	return
}
1254560
func newMyRnd(seed1, seed2 uint32) *myRnd {
	return &myRnd{
		seed1: seed1 % myRndMaxVal,
		seed2: seed2 % myRndMaxVal,
	}
}
479614
func (s Sample) GeoMean() float64 {
	if len(s.Xs) == 0 || s.Weights == nil {
		return GeoMean(s.Xs)
	}

	m, wsum := 0.0, 0.0
	for i, x := range s.Xs {
		w := s.Weights[i]
		wsum += w
		lx := math.Log(x)
		m += (lx - m) * w / wsum
	}
	return math.Exp(m)
}
183197
func (r reedSolomon) checkSomeShards(matrixRows, inputs, toCheck [][]byte, outputCount, byteCount int) bool {
	if r.o.maxGoroutines > 1 && byteCount > r.o.minSplitSize {
		return r.checkSomeShardsP(matrixRows, inputs, toCheck, outputCount, byteCount)
	}
	outputs := make([][]byte, len(toCheck))
	for i := range outputs {
		outputs[i] = make([]byte, byteCount)
	}
	for c := 0; c < r.DataShards; c++ {
		in := inputs[c]
		for iRow := 0; iRow < outputCount; iRow++ {
			galMulSliceXor(matrixRows[iRow][c], in, outputs[iRow], &r.o)
		}
	}

	for i, calc := range outputs {
		if !bytes.Equal(calc, toCheck[i]) {
			return false
		}
	}
	return true
}
263398
func (b *BitSet) SymmetricDifferenceCardinality(compare *BitSet) uint {
	panicIfNull(b)
	panicIfNull(compare)
	b, compare = sortByLength(b, compare)
	cnt := popcntXorSlice(b.set, compare.set)
	if len(compare.set) > len(b.set) {
		cnt += popcntSlice(compare.set[len(b.set):])
	}
	return uint(cnt)
}
787265
func (s *SkewedInfo) SetSkewedColumnValues(v []*string) *SkewedInfo {
	s.SkewedColumnValues = v
	return s
}
180466
func (h *Histogram) ApproxMean() float64 {
	if h.useLocks {
		h.mutex.RLock()
		defer h.mutex.RUnlock()
	}
	divisor := 0.0
	sum := 0.0
	for i := uint16(0); i < h.used; i++ {
		midpoint := h.bvs[i].midpoint()
		cardinality := float64(h.bvs[i].count)
		divisor += cardinality
		sum += midpoint * cardinality
	}
	if divisor == 0.0 {
		return math.NaN()
	}
	return sum / divisor
}
821927
func (d *Dataset) AppendColumnValues(header string, cols ...interface{}) error {
	return d.AppendColumn(header, cols[:])
}
1078597
func (m *StandardMeter) RateMean() float64 {
	m.lock.RLock()
	rateMean := m.snapshot.rateMean
	m.lock.RUnlock()
	return rateMean
}
1173338
func (me *Dataset) Offset(offset uint) *Dataset {
	ret := me.copy()
	ret.clauses.Offset = offset
	return ret
}
258492
func At4d(x, y, z, w float64) float64 {
	// Noise contributions from the five corners
	var n0, n1, n2, n3, n4 float64

	// Skew the (x,y,z,w) space to determine which cell of 24 simplices we're in
	var s float64 = (x + y + z + w) * F4 // Factor for 4D skewing
	var i int = fastfloor(x + s)
	var j int = fastfloor(y + s)
	var k int = fastfloor(z + s)
	var l int = fastfloor(w + s)

	var t = float64(i+j+k+l) * G4 // Factor for 4D unskewing

	// Unskew the cell origin back to (x,y,z,w) space
	var ox0 = float64(i) - t
	var oy0 = float64(j) - t
	var oz0 = float64(k) - t
	var ow0 = float64(l) - t

	// The x,y,z,w distances from the cell origin
	var x0 float64 = x - ox0
	var y0 float64 = y - oy0
	var z0 float64 = z - oz0
	var w0 float64 = w - ow0

	// For the 4D case, the simplex is a 4D shape I won't even try to describe.
	// To find out which of the 24 possible simplices we're in, we need to
	// determine the magnitude ordering of x0, y0, z0 and w0.
	var rankx, ranky, rankz, rankw int

	// Six pair-wise comparisons are performed between each possible pair
	// of the four coordinates, and the results are used to rank the numbers.
	if x0 > y0 {
		rankx++
	} else {
		ranky++
	}
	if x0 > z0 {
		rankx++
	} else {
		rankz++
	}
	if x0 > w0 {
		rankx++
	} else {
		rankw++
	}
	if y0 > z0 {
		ranky++
	} else {
		rankz++
	}
	if y0 > w0 {
		ranky++
	} else {
		rankw++
	}
	if z0 > w0 {
		rankz++
	} else {
		rankw++
	}

	// The integer offsets for the second, third and fourth simplex corner
	var i1, j1, k1, l1 int
	var i2, j2, k2, l2 int
	var i3, j3, k3, l3 int

	// simplex[c] is a 4-vector with the numbers 0, 1, 2 and 3 in some order.
	// Many values of c will never occur, since e.g. x>y>z>w makes x<z, y<w and x<w
	// impossible. Only the 24 indices which have non-zero entries make any sense.
	// We use a thresholding to set the coordinates in turn from the largest magnitude.

	// Rank 3 denotes the largest coordinate.
	if rankx >= 3 {
		i1 = 1
	} else {
		i1 = 0
	}
	if ranky >= 3 {
		j1 = 1
	} else {
		j1 = 0
	}
	if rankz >= 3 {
		k1 = 1
	} else {
		k1 = 0
	}
	if rankw >= 3 {
		l1 = 1
	} else {
		l1 = 0
	}

	// Rank 2 denotes the second largest coordinate.
	if rankx >= 2 {
		i2 = 1
	} else {
		i2 = 0
	}
	if ranky >= 2 {
		j2 = 1
	} else {
		j2 = 0
	}
	if rankz >= 2 {
		k2 = 1
	} else {
		k2 = 0
	}
	if rankw >= 2 {
		l2 = 1
	} else {
		l2 = 0
	}

	// Rank 1 denotes the second smallest coordinate.
	if rankx >= 1 {
		i3 = 1
	} else {
		i3 = 0
	}
	if ranky >= 1 {
		j3 = 1
	} else {
		j3 = 0
	}
	if rankz >= 1 {
		k3 = 1
	} else {
		k3 = 0
	}
	if rankw >= 1 {
		l3 = 1
	} else {
		l3 = 0
	}

	// The fifth corner has all coordinate offsets = 1, so no need to compute that.

	// Offsets for second corner in (x,y,z,w) coords
	var x1 = x0 - float64(i1) + G4
	var y1 = y0 - float64(j1) + G4
	var z1 = z0 - float64(k1) + G4
	var w1 = w0 - float64(l1) + G4

	// Offsets for third corner in (x,y,z,w) coords
	var x2 = x0 - float64(i2) + 2.0*G4
	var y2 = y0 - float64(j2) + 2.0*G4
	var z2 = z0 - float64(k2) + 2.0*G4
	var w2 = w0 - float64(l2) + 2.0*G4

	// Offsets for fourth corner in (x,y,z,w) coords
	var x3 = x0 - float64(i3) + 3.0*G4
	var y3 = y0 - float64(j3) + 3.0*G4
	var z3 = z0 - float64(k3) + 3.0*G4
	var w3 = w0 - float64(l3) + 3.0*G4

	// Offsets for last corner in (x,y,z,w) coords
	var x4 = x0 - 1.0 + 4.0*G4
	var y4 = y0 - 1.0 + 4.0*G4
	var z4 = z0 - 1.0 + 4.0*G4
	var w4 = w0 - 1.0 + 4.0*G4

	// Work out the hashed gradient indices of the five simplex corners
	var ii int = i & 0xff
	var jj int = j & 0xff
	var kk int = k & 0xff
	var ll int = l & 0xff
	var gi0 int = perm[ii+perm[jj+perm[kk+perm[ll]]]] % 32
	var gi1 int = perm[ii+i1+perm[jj+j1+perm[kk+k1+perm[ll+l1]]]] % 32
	var gi2 int = perm[ii+i2+perm[jj+j2+perm[kk+k2+perm[ll+l2]]]] % 32
	var gi3 int = perm[ii+i3+perm[jj+j3+perm[kk+k3+perm[ll+l3]]]] % 32
	var gi4 int = perm[ii+1+perm[jj+1+perm[kk+1+perm[ll+1]]]] % 32

	// Calculate the contribution from the five corners
	var t0 float64 = 0.5 - x0*x0 - y0*y0 - z0*z0 - w0*w0
	if t0 < 0 {
		n0 = 0.0
	} else {
		t0 *= t0
		n0 = t0 * t0 * dot4(grad4[gi0], x0, y0, z0, w0)
	}

	var t1 float64 = 0.5 - x1*x1 - y1*y1 - z1*z1 - w1*w1
	if t1 < 0 {
		n1 = 0.0
	} else {
		t1 *= t1
		n1 = t1 * t1 * dot4(grad4[gi1], x1, y1, z1, w1)
	}

	var t2 float64 = 0.5 - x2*x2 - y2*y2 - z2*z2 - w2*w2
	if t2 < 0 {
		n2 = 0.0
	} else {
		t2 *= t2
		n2 = t2 * t2 * dot4(grad4[gi2], x2, y2, z2, w2)
	}

	var t3 float64 = 0.5 - x3*x3 - y3*y3 - z3*z3 - w3*w3
	if t3 < 0 {
		n3 = 0.0
	} else {
		t3 *= t3
		n3 = t3 * t3 * dot4(grad4[gi3], x3, y3, z3, w3)
	}

	var t4 float64 = 0.5 - x4*x4 - y4*y4 - z4*z4 - w4*w4
	if t4 < 0 {
		n4 = 0.0
	} else {
		t4 *= t4
		n4 = t4 * t4 * dot4(grad4[gi4], x4, y4, z4, w4)
	}

	// Sum and scale to [-1,1]
	return 27.0 * (n0 + n1 + n2 + n3 + n4)
}
243733
func SampleInts(n int, k int) (res []int, err error) {
	if k < 0 {
		err = errors.Newf("invalid sample size k")
		return
	}

	if n < k {
		err = errors.Newf("sample size k larger than n")
		return
	}

	picked := set.NewSet()
	for picked.Len() < k {
		i := Intn(n)
		picked.Add(i)
	}

	res = make([]int, k)
	e := 0
	for i := range picked.Iter() {
		res[e] = i.(int)
		e++
	}

	return
}
109344
func (db *DB) SKeyExists(key []byte) (int64, error) {
	if err := checkKeySize(key); err != nil {
		return 0, err
	}
	sk := db.sEncodeSizeKey(key)
	v, err := db.bucket.Get(sk)
	if v != nil && err == nil {
		return 1, nil
	}
	return 0, err
}
60628
func (db *RedisDB) ssetAdd(key string, score float64, member string) bool {
	ss, ok := db.sortedsetKeys[key]
	if !ok {
		ss = newSortedSet()
		db.keys[key] = "zset"
	}
	_, ok = ss[member]
	ss[member] = score
	db.sortedsetKeys[key] = ss
	db.keyVersion[key]++
	return !ok
}
431538
func initCovariance(n_comps, n_feats int) []mat.Symmetric {
	var result []mat.Symmetric
	floats := identity(n_feats)
	for k := 0; k < n_comps; k++ {
		matrix := mat.NewSymDense(n_feats, floats)
		result = append(result, matrix)
	}
	return result
}
971284
func (set IdentifierSet) SymmetricDifference(other IdentifierSet) IdentifierSet {
	aDiff := set.Difference(other)
	bDiff := other.Difference(set)
	return aDiff.Union(bDiff)
}
993276
func (s *MultiTermvectorService) Offsets(offsets bool) *MultiTermvectorService {
	s.offsets = &offsets
	return s
}