// EstimatedFillRatio returns the current estimated ratio of set bits.
498538
func (p *PartitionedBloomFilter) EstimatedFillRatio() float64 {
	return 1 - math.Exp(-float64(p.count)/float64(p.s))
}
974424
func (u *Ugen) Midiratio() Input {
	return unaryOpMidiratio(u.Rate, u, u.NumOutputs)
}
1066675
func (m *MonitorValues) FlattenBinlogUsedSizeKiBValue() ([]FlatMonitorValue, error) {
	return m.flattenValue(func(v *MonitorValue) *float64 { return v.BinlogUsedSizeKiB })
}
1255286
func penetrationLevels(as []analytic, points []float64) []analytic {
	sort.Slice(as, func(a, b int) bool {
		return versionLess(as[b].Key, as[a].Key)
	})

	var res []analytic

	idx := 0
	sum := 0.0
	for _, a := range as {
		sum += a.Percentage
		if sum >= points[idx] {
			a.Count = int(points[idx])
			a.Percentage = sum
			res = append(res, a)
			idx++
			if idx == len(points) {
				break
			}
		}
	}
	return res
}
380394
func PercentilInt(data []int, p int) int {
	n := len(data)
	if n == 0 {
		return 0
	}
	if n == 1 {
		return data[0]
	}

	pos := float64(p) * float64(n+1) / 100
	fpos := math.Floor(pos)
	intPos := int(fpos)
	dif := pos - fpos
	if intPos < 1 {
		return data[0]
	}
	if intPos >= n {
		return data[n-1]
	}
	lower := data[intPos-1]
	upper := data[intPos]
	val := float64(lower) + dif*float64(upper-lower)
	return int(math.Floor(val + 0.5))
}
32710
func (m *RTMetrics) ResponseCodeRatio(startA, endA, startB, endB int) float64 {
	a := int64(0)
	b := int64(0)
	m.statusCodesLock.RLock()
	defer m.statusCodesLock.RUnlock()
	for code, v := range m.statusCodes {
		if code < endA && code >= startA {
			a += v.Count()
		}
		if code < endB && code >= startB {
			b += v.Count()
		}
	}
	if b != 0 {
		return float64(a) / float64(b)
	}
	return 0
}
1360590
func unaryOpMidiratio(rate int8, in Input, numOutputs int) Input {
	CheckRate(rate)
	return NewInput(UnaryOpUgenName, rate, UnaryOpMidiratio, numOutputs, in)
}
1356782
func (s *ScalableBloomFilter) FillRatio() float64 {
	sum := 0.0
	for _, filter := range s.filters {
		sum += filter.FillRatio()
	}
	return sum / float64(len(s.filters))
}
697520
func estimateBias(x float64, p byte) float64 {
	if p > 18 {
		return 0.0
	}
	estimateVector := rawEstimateData[p-4]
	N := len(estimateVector)
	if x < estimateVector[0] || x > estimateVector[N-1] {
		return 0.0
	}
	biasV := biasData[p-4]
	// rawEstimates are almost monotone -- there are a few small inversions for p=2 and p=3.
	// It does not matter much.
	for i := 0; i < len(estimateVector)-1; i++ {
		a := estimateVector[i]
		if x == a {
			return biasV[i]
		}
		if x > a {
			continue
		}
		b := estimateVector[i+1]
		vb := biasV[i+1]
		va := biasV[i]
		r := (x-a)*vb + (b-x)*va
		return r / (b - a)
	}
	return 0
}
907812
func (c *Client) AccountEstimateInvoice(mode string, term *int, planID *int,
	linodeID *int) (EstimatedInvoice, error) {

	args := make(map[string]interface{})
	args["mode"] = mode
	args["PaymentTerm"] = term
	args["PlanID"] = planID
	args["LinodeID"] = linodeID

	data, err := c.apiCall("account.estimateinvoice", args)
	if err != nil {
		return EstimatedInvoice{}, err
	}

	var inv EstimatedInvoice
	err = json.Unmarshal(data, &inv)
	if err != nil {
		return EstimatedInvoice{}, err
	}

	return inv, nil
}
1343843
func (m *RTMetrics) NetworkErrorRatio() float64 {
	if m.total.Count() == 0 {
		return 0
	}
	return float64(m.netErrors.Count()) / float64(m.total.Count())
}
724950
func binOpMax(rate int8, x, y Input, numOutputs int) Input {
	CheckRate(rate)
	return NewInput(BinOpUgenName, rate, BinOpMax, numOutputs, x, y)
}
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)
}
140573
func (w *WalletKit) EstimateFee(ctx context.Context,
	req *EstimateFeeRequest) (*EstimateFeeResponse, error) {

	switch {
	// A confirmation target of zero doesn't make any sense. Similarly, we
	// reject confirmation targets of 1 as they're unreasonable.
	case req.ConfTarget == 0 || req.ConfTarget == 1:
		return nil, fmt.Errorf("confirmation target must be greater " +
			"than 1")
	}

	satPerKw, err := w.cfg.FeeEstimator.EstimateFeePerKW(
		uint32(req.ConfTarget),
	)
	if err != nil {
		return nil, err
	}

	return &EstimateFeeResponse{
		SatPerKw: int64(satPerKw),
	}, nil
}
524249
func (c cTable) estimateSize(hist []uint32) int {
	nbBits := uint32(7)
	for i, v := range c[:len(hist)] {
		nbBits += uint32(v.nBits) * hist[i]
	}
	return int(nbBits >> 3)
}
712229
func (s *UserPoolType) SetEstimatedNumberOfUsers(v int64) *UserPoolType {
	s.EstimatedNumberOfUsers = &v
	return s
}
799595
func MinMax(inReal []float64, inTimePeriod int) ([]float64, []float64) {

	outMin := make([]float64, len(inReal))
	outMax := make([]float64, len(inReal))

	nbInitialElementNeeded := (inTimePeriod - 1)
	startIdx := nbInitialElementNeeded
	outIdx := startIdx
	today := startIdx
	trailingIdx := startIdx - nbInitialElementNeeded
	highestIdx := -1
	highest := 0.0
	lowestIdx := -1
	lowest := 0.0
	for today < len(inReal) {
		tmpLow, tmpHigh := inReal[today], inReal[today]
		if highestIdx < trailingIdx {
			highestIdx = trailingIdx
			highest = inReal[highestIdx]
			i := highestIdx
			i++
			for i <= today {
				tmpHigh = inReal[i]
				if tmpHigh > highest {
					highestIdx = i
					highest = tmpHigh
				}
				i++
			}
		} else if tmpHigh >= highest {
			highestIdx = today
			highest = tmpHigh
		}
		if lowestIdx < trailingIdx {
			lowestIdx = trailingIdx
			lowest = inReal[lowestIdx]
			i := lowestIdx
			i++
			for i <= today {
				tmpLow = inReal[i]
				if tmpLow < lowest {
					lowestIdx = i
					lowest = tmpLow
				}
				i++
			}
		} else if tmpLow <= lowest {
			lowestIdx = today
			lowest = tmpLow
		}
		outMax[outIdx] = highest
		outMin[outIdx] = lowest
		outIdx++
		trailingIdx++
		today++
	}
	return outMin, outMax
}