Browse Source

Switching to enthropy

Loweel 4 years ago
parent
commit
0bf231430d
1 changed files with 8 additions and 8 deletions
  1. 8 8
      matrix.go

+ 8 - 8
matrix.go

@@ -91,7 +91,6 @@ func (c *ByClassifier) IsGOOD(key string) {
 
 //Posterior calculates Shannon based entropy using bad and good as different distributions
 func (c *ByClassifier) Posterior(hdr string) map[string]float64 {
-	
 
 	c.Matrix.busy.Lock()
 	defer c.Matrix.busy.Unlock()
@@ -131,13 +130,8 @@ func (c *ByClassifier) Posterior(hdr string) map[string]float64 {
 	hBadM = math.Log2(lenTokens) - (hBadM / lenTokens)
 	hGoodM = math.Log2(lenTokens) - (hGoodM / lenTokens)
 
-	if math.Abs(hGoodM) >= math.Abs(hBadM) {
-		ff["GOOD"] = 1
-		ff["BAD"] = 0
-	} else {
-		ff["GOOD"] = 0
-		ff["BAD"] = 1
-	}
+	ff["BAD"] = sigmoid(-hBadM)
+	ff["GOOD"] = sigmoid(-hGoodM)
 
 	log.Println("Entropies: ", ff)
 
@@ -223,3 +217,9 @@ func (c *ByClassifier) readInitList(filePath, class string) {
 	}
 
 }
+
+func sigmoid(x float64) float64 {
+
+	return 1.0 / (1.0 + math.Exp(-x))
+
+}