// Beta is equivalent to Alpha but controls the smoothing of the trend
// instead of the data.
195302
func (m *HoltLinearMovAvgModel) Beta(beta float64) *HoltLinearMovAvgModel {
	m.beta = &beta
	return m
}
616853
func MedianAbsoluteDeviationPopulation(input Float64Data) (mad float64, err error) {
	if input.Len() == 0 {
		return math.NaN(), EmptyInputErr
	}

	i := copyslice(input)
	m, _ := Median(i)

	for key, value := range i {
		i[key] = math.Abs(value - m)
	}

	return Median(i)
}
390517
func SampleVariance(input Float64Data) (svar float64, err error) {

	v, err := _variance(input, 1)
	if err != nil {
		return math.NaN(), err
	}

	return v, nil
}
1020201
def down_alpha_beta(returns, factor_returns, **kwargs):
    
    return down(returns, factor_returns, function=alpha_beta_aligned, **kwargs)
173494
func (b *bdpEstimator) calculate(d [8]byte) {
	// Check if the ping acked for was the bdp ping.
	if bdpPing.data != d {
		return
	}
	b.mu.Lock()
	rttSample := time.Since(b.sentAt).Seconds()
	if b.sampleCount < 10 {
		// Bootstrap rtt with an average of first 10 rtt samples.
		b.rtt += (rttSample - b.rtt) / float64(b.sampleCount)
	} else {
		// Heed to the recent past more.
		b.rtt += (rttSample - b.rtt) * float64(alpha)
	}
	b.isSent = false
	// The number of bytes accumulated so far in the sample is smaller
	// than or equal to 1.5 times the real BDP on a saturated connection.
	bwCurrent := float64(b.sample) / (b.rtt * float64(1.5))
	if bwCurrent > b.bwMax {
		b.bwMax = bwCurrent
	}
	// If the current sample (which is smaller than or equal to the 1.5 times the real BDP) is
	// greater than or equal to 2/3rd our perceived bdp AND this is the maximum bandwidth seen so far, we
	// should update our perception of the network BDP.
	if float64(b.sample) >= beta*float64(b.bdp) && bwCurrent == b.bwMax && b.bdp != bdpLimit {
		sampleFloat := float64(b.sample)
		b.bdp = uint32(gamma * sampleFloat)
		if b.bdp > bdpLimit {
			b.bdp = bdpLimit
		}
		bdp := b.bdp
		b.mu.Unlock()
		b.updateFlowControl(bdp)
		return
	}
	b.mu.Unlock()
}
731602
func (n *Node) ChangesBetween(from, to api.Version) ([]state.Change, error) {
	n.stopMu.RLock()
	defer n.stopMu.RUnlock()

	if from.Index > to.Index {
		return nil, errors.New("versions are out of order")
	}

	if !n.IsMember() {
		return nil, ErrNoRaftMember
	}

	// never returns error
	last, _ := n.raftStore.LastIndex()

	if to.Index > last {
		return nil, errors.New("last version is out of bounds")
	}

	pbs, err := n.raftStore.Entries(from.Index+1, to.Index+1, math.MaxUint64)
	if err != nil {
		return nil, err
	}

	var changes []state.Change
	for _, pb := range pbs {
		if pb.Type != raftpb.EntryNormal || pb.Data == nil {
			continue
		}
		r := &api.InternalRaftRequest{}
		err := proto.Unmarshal(pb.Data, r)
		if err != nil {
			return nil, errors.Wrap(err, "error umarshalling internal raft request")
		}

		if r.Action != nil {
			changes = append(changes, state.Change{StoreActions: r.Action, Version: api.Version{Index: pb.Index}})
		}
	}

	return changes, nil
}
245042
func BgBlue(arg interface{}) Value {
	if val, ok := arg.(Value); ok {
		return val.BgBlue()
	}
	return value{value: arg, color: BlueBg}
}
1002476
func (s Float32Slice) Less(i, j int) bool {
	return s[i] < s[j]
}
468255
func (vs Values) Normalize() []Value {
	var output []Value
	var total float64

	for _, v := range vs {
		total += v.Value
	}

	for _, v := range vs {
		if v.Value > 0 {
			output = append(output, Value{
				Style: v.Style,
				Label: v.Label,
				Value: util.Math.RoundDown(v.Value/total, 0.0001),
			})
		}
	}
	return output
}
61347
func (it *Regex) Optimize() (graph.Iterator, bool) {
	newSub, changed := it.subIt.Optimize()
	if changed {
		it.subIt.Close()
		it.subIt = newSub
	}
	return it, false
}
1246155
func Covariance(data1, data2 Float64Data) (float64, error) {

	l1 := data1.Len()
	l2 := data2.Len()

	if l1 == 0 || l2 == 0 {
		return math.NaN(), EmptyInputErr
	}

	if l1 != l2 {
		return math.NaN(), SizeErr
	}

	m1, _ := Mean(data1)
	m2, _ := Mean(data2)

	// Calculate sum of squares
	var ss float64
	for i := 0; i < l1; i++ {
		delta1 := (data1.Get(i) - m1)
		delta2 := (data2.Get(i) - m2)
		ss += (delta1*delta2 - ss) / float64(i+1)
	}

	return ss * float64(l1) / float64(l1-1), nil
}
899698
func handleProgress(ch <-chan *migrator.ProgressUpdate, doneCh <-chan struct{}) {
	var lastOp string
	var lastProgress float64
	lastFlush := time.Now()
	for {
		select {
		case update := <-ch:
			switch {
			case lastOp != update.Op:
				lastProgress = update.Progress
				lastOp = update.Op
				fmt.Println(update.Op)
				fmt.Printf("%.2f%%\n", update.Progress)

			case update.Progress-lastProgress >= 5:
				fallthrough

			case time.Now().Sub(lastFlush) > time.Second:
				fallthrough

			case update.Progress == 100:
				lastFlush = time.Now()
				lastProgress = update.Progress
				fmt.Printf("%.2f%%\n", update.Progress)
			}
		case <-doneCh:
			return
		}
	}
}
1094271
func (s Float64Slice) Less(i, j int) bool {
	return s[i] < s[j]
}
515322
func Beta(a, b float64) float64 {
	// B(x,y) = Γ(x)Γ(y) / Γ(x+y)
	return math.Exp(lgamma(a) + lgamma(b) - lgamma(a+b))
}
3383
func LinearRegression(xData, yData []float64) (slope, intercept, rsquared float64,
	count int, slopeStdErr, interceptStdErr float64) {
	var r Regression
	r.UpdateArray(xData, yData)
	ss_xy := r.n*r.sxy - r.sx*r.sy
	ss_xx := r.n*r.sxx - r.sx*r.sx
	ss_yy := r.n*r.syy - r.sy*r.sy
	slope = ss_xy / ss_xx
	intercept = (r.sy - r.Slope()*r.sx) / r.n
	rsquared = ss_xy * ss_xy / ss_xx / ss_yy
	if r.n <= 2 {
		slopeStdErr = math.NaN()
		interceptStdErr = math.NaN()
	} else {
		s := math.Sqrt((ss_yy - ss_xy*ss_xy/ss_xx) / (r.n - 2.0))
		slopeStdErr = s / math.Sqrt(ss_xx)
		mean_x := r.sx / r.n
		interceptStdErr = s * math.Sqrt(1.0/r.n+mean_x*mean_x/ss_xx)
	}
	count = int(r.n)
	return
}
1085675
public static double quantile(double p, double alpha, double beta) {
    return (Double.isNaN(alpha) || Double.isNaN(beta) || Double.isNaN(p) || alpha < 0. || beta < 0. || p < 0 || p > 1) ? Double.NaN : //
        p == 0 ? 0. : p == 1 ? 1. : p > 0.5 //
            ? 1 - rawQuantile(1 - p, beta, alpha, logBeta(beta, alpha)) //
            : rawQuantile(p, alpha, beta, logBeta(alpha, beta));
  }
1060530
func (h *Plus) Count() uint64 {
	if h == nil {
		return 0 // Nothing to do.
	}

	if h.sparse {
		h.mergeSparse()
		return uint64(h.linearCount(h.mp, h.mp-uint32(h.sparseList.count)))
	}
	sum := 0.0
	m := float64(h.m)
	var count float64
	for _, val := range h.denseList {
		sum += 1.0 / float64(uint32(1)<<val)
		if val == 0 {
			count++
		}
	}
	// Use LogLog-Beta bias estimation
	return uint64((h.alpha * m * (m - count) / (beta(count) + sum)) + 0.5)
}