Browse Source

Safe Probability with Panic

Loweel 4 years ago
parent
commit
5cddb90d89
1 changed files with 14 additions and 9 deletions
  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.