本文整理汇总了Golang中github.com/mafredri/go-trueskill/collection.DistributionBag.Put方法的典型用法代码示例。如果您正苦于以下问题:Golang DistributionBag.Put方法的具体用法?Golang DistributionBag.Put怎么用?Golang DistributionBag.Put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/mafredri/go-trueskill/collection.DistributionBag
的用法示例。
在下文中一共展示了DistributionBag.Put方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: sendMessageHelper
func sendMessageHelper(msgIdx, varIdx int, msgBag, varBag *collection.DistributionBag) float64 {
mar := varBag.Get(varIdx)
msg := msgBag.Get(msgIdx)
varBag.Put(varIdx, mar.Mul(msg))
// logZ
return gaussian.LogProdNorm(mar, msg)
}
示例2: gaussianGreaterThanOrWithinUpdateMessage
func gaussianGreaterThanOrWithinUpdateMessage(epsilon float64, msgIdx, varIdx int,
msgBag, varBag *collection.DistributionBag, vFunc, wFunc func(t, epsilon float64) float64) float64 {
oldMarginal := varBag.Get(varIdx)
oldMsg := msgBag.Get(msgIdx)
msgFromVar := oldMarginal.Div(oldMsg)
c := msgFromVar.Precision
d := msgFromVar.PrecisionMean
sqrtC := math.Sqrt(c)
dOnSqrtC := d / sqrtC
epsTimesSqrtC := epsilon * sqrtC
denom := 1.0 - wFunc(dOnSqrtC, epsTimesSqrtC)
newPrecision := c / denom
newPrecisionMean := (d + sqrtC*vFunc(dOnSqrtC, epsTimesSqrtC)) / denom
newMarginal := gaussian.NewFromPrecision(newPrecisionMean, newPrecision)
newMsg := oldMsg.Mul(newMarginal).Div(oldMarginal)
msgBag.Put(msgIdx, newMsg)
varBag.Put(varIdx, newMarginal)
return newMarginal.Sub(oldMarginal)
}
示例3: GaussianPrior
// GaussianPrior calculates the prior for the factor graph.
func (gf GaussianFactors) GaussianPrior(mu, sigmaSquared float64, varIdx int,
varBag *collection.DistributionBag) Factor {
msgIdx := gf.msgBag.NextIndex()
newMsg := gaussian.NewFromMeanAndVariance(mu, sigmaSquared)
updateMessage := func(i int) float64 {
if i != 0 {
panic("Index out of range")
}
oldMarginal := varBag.Get(varIdx)
oldMsg := gf.msgBag.Get(msgIdx)
newMarginal := gaussian.NewFromPrecision(oldMarginal.PrecisionMean+newMsg.PrecisionMean-oldMsg.PrecisionMean,
oldMarginal.Precision+newMsg.Precision-oldMsg.Precision)
varBag.Put(varIdx, newMarginal)
gf.msgBag.Put(msgIdx, newMsg)
delta := oldMarginal.Sub(newMarginal)
return delta
}
sendMessage := func(i int) float64 {
if i != 0 {
panic("Index out of range")
}
return sendMessageHelper(msgIdx, varIdx, gf.msgBag, varBag)
}
return Factor{
UpdateMessage: updateMessage,
LogNormalization: func() float64 { return 0 },
NumMessages: 1,
ResetMarginals: func() { varBag.PutPriorAt(varIdx) },
SendMessage: sendMessage,
}
}