// weight corresponds to the weight given between
// two datapoints (based on how 'far apart' they
// are.)
//
// w[i] = exp(-1 * |x[i] - x|^2 / 2σ^2)
15186
func (l *LocalLinear) weight(X []float64, x []float64) float64 {
	// don't throw error but fail peacefully
	//
	// returning "not at all similar", basically
	if len(X) != len(x) {
		return 0.0
	}

	var diff float64

	for i := range X {
		diff += (X[i] - x[i]) * (X[i] - x[i])
	}

	return math.Exp(-1 * diff / (2 * l.bandwidth * l.bandwidth))
}
1037885
func (fn ScriptFunction) Weight(weight float64) ScriptFunction {
	fn.weight = &weight
	return fn
}
10214
func (p Point) Distance(b Point) s1.Angle {
	return p.Vector.Angle(b.Vector)
}
997314
func (n *Network) GetWeight(src, target int) float64 {
	src--
	target--
	return n.weights.At(target, src)
}
1107552
func Float(v float64) *float64 {
	p := new(float64)
	*p = v
	return p
}
390770
func (e *knownEntry) Weight() int64 {
	if e.state != psNotConnected || !e.known || e.delayedRetry {
		return 0
	}
	return int64(1000000000 * e.connectStats.recentAvg() * math.Exp(-float64(e.lastConnected.fails)*failDropLn-e.responseStats.recentAvg()/float64(responseScoreTC)-e.delayStats.recentAvg()/float64(delayScoreTC)) * math.Pow(1-e.timeoutStats.recentAvg(), timeoutPow))
}
720620
func (fn *ExponentialDecayFunction) Weight(weight float64) *ExponentialDecayFunction {
	fn.weight = &weight
	return fn
}
706573
func (fn *WeightFactorFunction) Weight(weight float64) *WeightFactorFunction {
	fn.weight = weight
	return fn
}
238867
func Total(scores []*Score) uint8 {
	totalWeight := float32(0)
	var max, score, weight []float32
	for _, ts := range scores {
		totalWeight += float32(ts.Weight)
		weight = append(weight, float32(ts.Weight))
		score = append(score, float32(ts.Score))
		max = append(max, float32(ts.MaxScore))
	}

	total := float32(0)
	for i := 0; i < len(scores); i++ {
		if score[i] > max[i] {
			score[i] = max[i]
		}
		total += ((score[i] / max[i]) * (weight[i] / totalWeight))
	}

	return uint8(total * 100)
}
721587
func (a Axis) Value() float32 {
	for _, pair := range a.Pairs {
		v := pair.Value()
		if v != AxisNeutral {
			return v
		}
	}

	return AxisNeutral
}
531006
func (a *AlgorithmChain) WeightingRelation(
	word1ID int,
	word2ID int,
	rank *Rank,
) float32 {
	relationQty := rank.Relation.Node[word1ID][word2ID].Qty
	word1Qty := rank.Words[word1ID].Qty
	word2Qty := rank.Words[word2ID].Qty

	qDiff := float32(math.Abs(float64(word1Qty)-float64(word2Qty))) / 100
	weight := float32(relationQty) + qDiff

	return weight
}
265034
func (q1 Quat) ApproxEqual(q2 Quat) bool {
	return FloatEqual(q1.W, q2.W) && q1.V.ApproxEqual(q2.V)
}
1232911
func (rb *Rebalancer) adjustWeights() {
	rb.mtx.Lock()
	defer rb.mtx.Unlock()

	// In this case adjusting weights would have no effect, so do nothing
	if len(rb.servers) < 2 {
		return
	}
	// Metrics are not ready
	if !rb.metricsReady() {
		return
	}
	if !rb.timerExpired() {
		return
	}
	if rb.markServers() {
		if rb.setMarkedWeights() {
			rb.setTimer()
		}
	} else { // No servers that are different by their quality, so converge weights
		if rb.convergeWeights() {
			rb.setTimer()
		}
	}
}
735616
func (p *Point) Scale(factor float64) *Point {
	p[0] *= factor
	p[1] *= factor

	return p
}
1180560
func (wd *WeightDevice) WeightString() string {
	return fmt.Sprintf("%d:%d %d", wd.Major, wd.Minor, wd.Weight)
}
1074349
func bumpWeight(from, to *node, w int64, residual bool) {
	if from.out[to] != to.in[from] {
		panic(fmt.Errorf("asymmetric edges %v %v", *from, *to))
	}

	if n := from.out[to]; n != nil {
		n.weight += w
		if n.residual && !residual {
			n.residual = false
		}
		return
	}

	info := &edgeInfo{src: from, dest: to, weight: w, residual: residual}
	from.out[to] = info
	to.in[from] = info
}
1301013
func (e EdgeMap) Sum() int64 {
	var ret int64
	for _, edge := range e {
		ret += edge.Weight
	}
	return ret
}