本文整理匯總了Golang中github.com/xlvector/hector/core.Vector.AddValue方法的典型用法代碼示例。如果您正苦於以下問題:Golang Vector.AddValue方法的具體用法?Golang Vector.AddValue怎麽用?Golang Vector.AddValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/xlvector/hector/core.Vector
的用法示例。
在下文中一共展示了Vector.AddValue方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: updateValueGrad
func (lr *LROWLQN) updateValueGrad(pos *core.Vector, dataset *core.DataSet) {
var totalLoss float64 = 0.0
var grad *core.Vector = core.NewVector()
for _, sample := range dataset.Samples {
var score float64 = lr.getScore(pos, sample)
var signScore float64 = score
if sample.Label == 0 {
signScore = -score
}
var prob float64
var lnProb float64
if signScore < -30 {
prob = 0
lnProb = signScore
} else if signScore > 30 {
prob = 1
lnProb = 0
} else {
prob = 1.0 / (1.0 + math.Exp(-signScore))
lnProb = math.Log(prob)
}
var scale float64
if sample.Label == 0 {
scale = (1 - prob)
} else {
scale = -(1 - prob)
}
totalLoss += -lnProb
for _, fea := range sample.Features {
grad.AddValue(fea.Id, scale*fea.Value)
}
}
lr.lastPos = pos.Copy()
lr.lastCost = totalLoss
lr.lastGrad = grad
}