當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Vector.Add方法代碼示例

本文整理匯總了Golang中github.com/unixpickle/num-analysis/linalg.Vector.Add方法的典型用法代碼示例。如果您正苦於以下問題:Golang Vector.Add方法的具體用法?Golang Vector.Add怎麽用?Golang Vector.Add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/unixpickle/num-analysis/linalg.Vector的用法示例。


在下文中一共展示了Vector.Add方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: PropagateRGradient

func (s *stateOutBlockRResult) PropagateRGradient(u, uR []linalg.Vector, su []RStateGrad,
	rg autofunc.RGradient, g autofunc.Gradient) []RStateGrad {
	downstream := make([]RStateGrad, len(s.WrappedOut.Outputs()))
	for i := range s.WrappedOut.Outputs() {
		var vec, vecR linalg.Vector
		if u != nil {
			vec = u[i].Copy()
			vecR = uR[i].Copy()
		}
		if su != nil && su[i] != nil {
			sVec := su[i].(VecRStateGrad)
			if vec == nil {
				vec = sVec.State.Copy()
				vecR = sVec.RState.Copy()
			} else {
				vec.Add(sVec.State)
				vecR.Add(sVec.RState)
			}
		}
		if vec != nil {
			downstream[i] = VecRStateGrad{State: vec, RState: vecR}
		}
	}
	return s.WrappedOut.PropagateRGradient(nil, nil, downstream, rg, g)
}
開發者ID:unixpickle,項目名稱:weakai,代碼行數:25,代碼來源:state_out_block.go

示例2: Classify

func (s *SumClassifier) Classify(list SampleList) linalg.Vector {
	if len(s.Classifiers) == 0 {
		return make(linalg.Vector, list.Len())
	} else if len(s.Classifiers) != len(s.Weights) {
		panic("classifier count must match weight count")
	}
	var res linalg.Vector
	for i, c := range s.Classifiers {
		w := s.Weights[i]
		if res == nil {
			res = c.Classify(list).Scale(w)
		} else {
			res.Add(c.Classify(list).Scale(w))
		}
	}
	return res
}
開發者ID:unixpickle,項目名稱:weakai,代碼行數:17,代碼來源:boosting.go

示例3: PropagateGradient

func (s *stateOutBlockResult) PropagateGradient(u []linalg.Vector, su []StateGrad,
	g autofunc.Gradient) []StateGrad {
	downstream := make([]StateGrad, len(s.WrappedOut.Outputs()))
	for i := range s.WrappedOut.Outputs() {
		var vec linalg.Vector
		if u != nil {
			vec = u[i].Copy()
		}
		if su != nil && su[i] != nil {
			sVec := su[i].(VecStateGrad)
			if vec == nil {
				vec = linalg.Vector(sVec).Copy()
			} else {
				vec.Add(linalg.Vector(sVec))
			}
		}
		if vec != nil {
			downstream[i] = VecStateGrad(vec)
		}
	}
	return s.WrappedOut.PropagateGradient(nil, downstream, g)
}
開發者ID:unixpickle,項目名稱:weakai,代碼行數:22,代碼來源:state_out_block.go

示例4: Step

// Step adds d.Scale(amount) to coeffs.
// If any of the entries in coeffs hits a
// constraint, then the step is stopped
// short and true is returned to indicate
// that a new constraint has been added.
//
// This may modify d in any way it pleases.
func (a *activeSet) Step(coeffs, d linalg.Vector, amount float64) bool {
	var maxStep, minStep float64
	var maxIdx, minIdx int
	isFirst := true
	for i, x := range d {
		if x == 0 {
			continue
		}
		coeff := coeffs[i]
		maxValue := (a.MaxCoeff - coeff) / x
		minValue := -coeff / x
		if x < 0 {
			maxValue, minValue = minValue, maxValue
		}
		if isFirst {
			isFirst = false
			minStep, maxStep = minValue, maxValue
			maxIdx, minIdx = i, i
		} else {
			if minValue > minStep {
				minStep = minValue
				minIdx = i
			}
			if maxValue < maxStep {
				maxStep = maxValue
				maxIdx = i
			}
		}
	}

	if isFirst {
		return false
	}

	if amount < minStep {
		coeffs.Add(d.Scale(minStep))
		a.addConstraint(coeffs, minIdx)
	} else if amount > maxStep {
		coeffs.Add(d.Scale(maxStep))
		a.addConstraint(coeffs, maxIdx)
	} else {
		coeffs.Add(d.Scale(amount))
		return false
	}
	return true
}
開發者ID:unixpickle,項目名稱:weakai,代碼行數:53,代碼來源:active_set.go


注:本文中的github.com/unixpickle/num-analysis/linalg.Vector.Add方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。