Explorar o código

Safe Probability with Panic

Loweel %!s(int64=4) %!d(string=hai) anos
pai
achega
5cddb90d89
Modificáronse 1 ficheiros con 14 adicións e 9 borrados
  1. 14 9
      matrix.go

+ 14 - 9
matrix.go

@@ -89,15 +89,20 @@ func (c *ByClassifier) IsGOOD(key string) {
 }
 
 //Posterior calculates the posterior probabilities in pseudo-bayes.
-func (c *ByClassifier) Posterior(hdr string) map[string]float64 {
-
-	var ff map[string]float64
-	ff = make(map[string]float64)
-	ff["BAD"] = 0.5
-	ff["GOOD"] = 0.5
-	defer handlepanic()
-	ff = c.bayez.Posterior(hdr)
-	return ff
+func (c *ByClassifier) Posterior(hdr string) (ff map[string]float64) {
+
+	defer func() {
+
+		if a := recover(); a != nil {
+			fmt.Println("OPS!: Recovering from:", a)
+			ff = make(map[string]float64)
+			ff["BAD"] = 0.5
+			ff["GOOD"] = 0.5
+		}
+	}()
+
+	return c.bayez.Posterior(hdr)
+
 }
 
 //Janitor keeps the maps under a certain size, keeping the biggest values.