本文整理汇总了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
}