// Max returns the MAP state given a valuation. func (g *Gaussian) Max(val VarSet) float64 { v, ok := val[g.varid] if ok { z := math.Log(float64(C.gsl_ran_ugaussian_pdf(C.double((float64(v) - g.mean) / g.sd)))) return z } return math.Log(GaussMax) }
// ArgMax returns both the arguments and the value of the MAP state given a certain valuation. func (g *Gaussian) ArgMax(val VarSet) (VarSet, float64) { retval := make(VarSet) v, ok := val[g.varid] if ok { retval[g.varid] = v z := math.Log(float64(C.gsl_ran_ugaussian_pdf(C.double((float64(v) - g.mean) / g.sd)))) return retval, z } retval[g.varid] = int(g.mean) return retval, math.Log(GaussMax) }
// Soft is a common base for all soft inference methods. func (g *Gaussian) Soft(val VarSet, key string) float64 { if _lv, ok := g.Stored(key); ok && g.stores { return _lv } v, ok := val[g.varid] var l float64 if ok { l = float64(C.gsl_ran_ugaussian_pdf(C.double((float64(v) - g.mean) / g.sd))) } else { l = 1.0 } g.Store(key, l) return l }
// LSoft is Soft in logspace. func (g *Gaussian) LSoft(val VarSet, key string) float64 { _lv := g.s[key] if _lv >= 0 { return _lv } v, ok := val[g.varid] var l float64 if ok { l = math.Log(float64(C.gsl_ran_ugaussian_pdf(C.double((float64(v) - g.mean) / g.sd)))) } else { l = 0.0 // ln(1.0) = 0.0 } g.Store(key, l) return l }
func UgaussianPdf(x float64) float64 { return float64(C.gsl_ran_ugaussian_pdf(C.double(x))) }