// Weight returns the total weight of the Sasmple.
4563
func (s Sample) Weight() float64 {
	if s.Weights == nil {
		return float64(len(s.Xs))
	}
	return vec.Sum(s.Weights)
}
1107552
func Float(v float64) *float64 {
	p := new(float64)
	*p = v
	return p
}
588901
func (n *wrsNode) insert(item wrsItem, weight int64) int {
	branch := 0
	for n.items[branch] != nil && (n.level == 0 || n.items[branch].(*wrsNode).itemCnt == n.items[branch].(*wrsNode).maxItems) {
		branch++
		if branch == wrsBranches {
			panic(nil)
		}
	}
	n.itemCnt++
	n.sumWeight += weight
	n.weights[branch] += weight
	if n.level == 0 {
		n.items[branch] = item
		return branch
	}
	var subNode *wrsNode
	if n.items[branch] == nil {
		subNode = &wrsNode{maxItems: n.maxItems / wrsBranches, level: n.level - 1}
		n.items[branch] = subNode
	} else {
		subNode = n.items[branch].(*wrsNode)
	}
	subIdx := subNode.insert(item, weight)
	return subNode.maxItems*branch + subIdx
}
869388
func ValidateWeights(weights *Weights) error {
	if weights == nil {
		return nil
	}
	if weights.Passing < 1 {
		return fmt.Errorf("Passing must be greater than 0")
	}
	if weights.Warning < 0 {
		return fmt.Errorf("Warning must be greater or equal than 0")
	}
	if weights.Passing > 65535 || weights.Warning > 65535 {
		return fmt.Errorf("DNS Weight must be between 0 and 65535")
	}
	return nil
}
33627
func (d *Diet) Balance() {
	if d.root != nil {
		d.root = balance(d.root)
	}
}
207413
func (s *Statistics) Total() float64 {
	s.RLock()
	defer s.RUnlock()
	return s.total
}
793682
func (mat *T) Scaled(f float32) T {
	r := *mat
	return *r.Scale(f)
}
1330696
func NewFeatureWithWeight(f []byte, weight int) feature {
	fw := NewFeature(f)
	fw.weight = weight
	return fw
}
6114
func (n *Network) UpdateWeights(out, err *mat.Dense, learnRate float64) {

	if n.origWeights == nil {
		n.origWeights = mat.DenseCopyOf(n.weights)
	}

	// Multiply that by the learning rate
	mulFunc := func(target, source int, v float64) float64 {
		if target == source {
			return v
		}
		if math.Abs(n.origWeights.At(target, source)) > 0.005 {
			return v + learnRate*out.At(source, 0)*err.At(target, 0)
		}
		return 0.00
	}

	// Add that to the weights
	n.weights.Apply(mulFunc, n.weights)
}
808893
func (q *Quantity) Value() int64 {
	if q.Amount == nil {
		return 0
	}
	return scaledValue(q.Amount.UnscaledBig(), int(q.Amount.Scale()), 0)
}
1018553
func (t Result) Float() float64 {
	switch t.Type {
	default:
		return 0
	case True:
		return 1
	case String:
		n, _ := strconv.ParseFloat(t.Str, 64)
		return n
	case Number:
		return t.Num
	}
}
1102026
func (th treeHeap) Less(i int, j int) bool {
	if th[i].Weight() == th[j].Weight() {
		return th[i].Value() >= th[j].Value()
	} else {
		return th[i].Weight() < th[j].Weight()
	}
}
478467
func boundedWeightedAverage(x1 float64, w1 float64, x2 float64, w2 float64) float64 {
	if x1 > x2 {
		x1, x2, w1, w2 = x2, x1, w2, w1
	}
	result := (x1*w1 + x2*w2) / (w1 + w2)
	return math.Max(x1, math.Min(result, x2))
}
329511
func (bg *balancerGroup) changeWeight(id string, newWeight uint32) {
	bg.pickerMu.Lock()
	defer bg.pickerMu.Unlock()
	pState, ok := bg.idToPickerState[id]
	if !ok {
		return
	}
	if pState.weight == newWeight {
		return
	}
	pState.weight = newWeight
	// Update state and picker to reflect the changes.
	bg.cc.UpdateBalancerState(buildPickerAndState(bg.idToPickerState))
}
100969
func (s *EndpointDescription) SetWeight(v int64) *EndpointDescription {
	s.Weight = &v
	return s
}
1271588
func (lr *LinearSVC) Fit(X base.FixedDataGrid) error {

	var weightVec []float64
	var weightClasses []C.int

	// Creates the class weighting
	if lr.Param.ClassWeights == nil {
		if lr.Param.WeightClassesAutomatically {
			weightVec = generateClassWeightVectorFromDist(X)
		} else {
			weightVec = generateClassWeightVectorFromFixed(X)
		}
	} else {
		weightVec = lr.Param.ClassWeights
	}

	weightClasses = make([]C.int, len(weightVec))
	for i := range weightVec {
		weightClasses[i] = C.int(i)
	}

	// Convert the problem
	problemVec := convertInstancesToProblemVec(X)
	labelVec := convertInstancesToLabelVec(X)

	// Train
	prob := NewProblem(problemVec, labelVec, 0)
	lr.param.c_param.nr_weight = C.int(len(weightVec))
	lr.param.c_param.weight_label = &(weightClasses[0])
	lr.param.c_param.weight = (*C.double)(unsafe.Pointer(&weightVec[0]))

	//	lr.param.weights = (*C.double)unsafe.Pointer(&(weightVec[0]));
	lr.model = Train(prob, lr.param)
	return nil
}
1180560
func (wd *WeightDevice) WeightString() string {
	return fmt.Sprintf("%d:%d %d", wd.Major, wd.Minor, wd.Weight)
}