Browse Source

Better normalization

Loweel 4 years ago
parent
commit
5ffac87f1e
1 changed files with 8 additions and 9 deletions
  1. 8 9
      matrix.go

+ 8 - 9
matrix.go

@@ -34,6 +34,8 @@ var ControPlane ByControlPlane
 type ByClassifier struct {
 	STATS  sync.Map
 	Matrix bMap
+	bReg   float64
+	gReg   float64
 }
 
 //AddStats adds the statistics after proper blocking.
@@ -66,7 +68,7 @@ func (c *ByClassifier) IsBAD(key string) {
 	}
 
 	c.Matrix.bScores[key] = t
-
+	c.bReg++
 }
 
 //IsGOOD inserts the key in the right place.
@@ -86,6 +88,7 @@ func (c *ByClassifier) IsGOOD(key string) {
 	}
 
 	c.Matrix.bScores[key] = t
+	c.gReg++
 
 }
 
@@ -121,14 +124,8 @@ func (c *ByClassifier) Posterior(hdr string) map[string]float64 {
 		}
 	}
 
-	maxScore := float64(ProxyFlow.seniority) * lenTokens
-
-	if maxScore == 0 {
-		maxScore = 1
-	}
-
-	ff["BAD"] = hBadM / maxScore
-	ff["GOOD"] = hGoodM / maxScore
+	ff["BAD"] = hBadM / (c.bReg * lenTokens)
+	ff["GOOD"] = hGoodM / (c.gReg * lenTokens)
 
 	log.Println("Entropies: ", ff)
 
@@ -145,6 +142,8 @@ func (c *ByClassifier) enroll() {
 	c.Matrix.busy.Lock()
 	c.Matrix.bScores = make(map[string]bScore)
 	c.Matrix.busy.Unlock()
+	c.bReg = 0
+	c.gReg = 0
 
 	c.readInitList("blacklist.txt", "BAD")
 	c.readInitList("whitelist.txt", "GOOD")