本文整理匯總了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,
}
}