func (this Histogram) LogFactorAlpha(alpha float64) (lf float64) { var sum float64 for _, c := range this { sum += float64(c) lf -= stat.LnΓ(float64(c) + alpha) } lf += stat.LnΓ(sum + alpha*float64(len(this))) return }
func (this Histogram) LogFactorCount() (lf float64) { var sum float64 for _, c := range this { sum += float64(c) lf -= stat.LnΓ(float64(c + 1)) } lf += stat.LnΓ(sum + 1) //fmt.Printf("%v %f\n", this, lf) return }
func (this Histogram) LoglihoodRatio(alpha float64) (ll float64) { //factorials * 1/gammas total := 0.0 for _, c := range this { cf := float64(c) total += cf //ll -= stat.LnΓ(cf + 1) ll -= stat.LnΓ(alpha) ll += stat.LnΓ(cf + alpha) } //ll += stat.LnΓ(total + 1) ll += stat.LnΓ(alpha * float64(len(this))) ll -= stat.LnΓ(total + alpha*float64(len(this))) return }
func InsertLoglihood(numActions, numOutcomes uint64, alpha []float64, Oc, Os []SAHist) (ll float64) { for a := uint64(0); a < numActions; a++ { totalDenom := 0.0 totalNum := 0.0 for o := uint64(0); o < numOutcomes; o++ { coTerm := alpha[o] + float64(Oc[a][o]) + float64(Os[a][o]) soTerm := float64(Os[a][o] + 1) ll += stat.LnΓ(coTerm) ll -= stat.LnΓ(soTerm) totalDenom += coTerm totalNum += soTerm } ll += stat.LnΓ(totalNum + 1) ll -= stat.LnΓ(totalDenom) } return }
func NewDepLearner(child int, cfg Config, stateRanges, actionRanges rlglue.IntRanges) (this *DepLearner) { this = new(DepLearner) this.bg = new(DBaggage) this.bg.cfg = cfg this.bg.myRange = stateRanges[child] this.bg.ranges = stateRanges this.bg.numStates = stateRanges.Count() this.bg.numActions = actionRanges.Count() this.bg.numOutcomes = stateRanges[child].Count() this.bg.alphaLogFactor = stat.LnΓ(this.bg.cfg.Alpha * float64(this.bg.numOutcomes)) this.bg.alphaLogFactor -= stat.LnΓ(this.bg.cfg.Alpha) * float64(this.bg.numOutcomes) this.bg.stateValues = make([][]int32, this.bg.numStates) for s := range this.bg.stateValues { this.bg.stateValues[s] = this.bg.ranges.Values(uint64(s)) } this.history = make([]Histogram, this.bg.numStates*this.bg.numActions) for i := range this.history { this.history[i] = make(Histogram, this.bg.numOutcomes) } this.cutRanges = this.parents.CutRanges(this.bg.ranges) this.mappedHistory = this.MakeMappedHistory(this.parents, this.cutRanges) this.mappedLoglihood = this.MappedLoglihoodRatio(this.mappedHistory) return }