Browse Source

Consensus operator equation updated

Debashis Chandra Ray 6 years ago
parent
commit
d3db8f4cdf
1 changed files with 17 additions and 20 deletions
  1. 17 20
      JavaScript/JavaScript_SDK/CertainTrust.js

+ 17 - 20
JavaScript/JavaScript_SDK/CertainTrust.js

@@ -344,6 +344,7 @@ CertainTrust.prototype._singleAND = function(arg){
 		f2 = 0.99999;
 		resF = f1*f2;
 		resC = c1 + c2 - c1*c2- (c2*t2*(1-c1)*(1-f1)+c1*t1*(1-c2)*(1-f2)) / (1 - resF);
+	}
 	else
 		resC = c1 + c2 - c1*c2 - (c2*t2*(1-c1)*(1-f1)+c1*t1*(1-c2)*(1-f2)) / (1 - resF);
 
@@ -855,17 +856,15 @@ CertainTrust.prototype._singleCONSENSUS = function(arg){
 	if (!this._operationAllowed(this, arg))
 		return undefined;
 
-	//resF = f1*f2;
-	if (this._almostEqual(resF, 1))		//avoid division by 0
-		resC = (c1+c2-2*c1*c2)/(1-c1*c2);
-	else
-		resC = (c1+c2-2*c1*c2)/(1-c1*c2);
+	var tempC = c1*c2;
+	if (this._almostEqual(tempC, 1)){		//avoid division by 0
+		c1 = 0.99999;
+		c2 = 0.99999;
+	}
 
-	if (this._almostEqual(resC, 0))
-		resT = 0.5;
-	else if (this._almostEqual(resF, 1))	//avoid division by 0
-		resT = (c1*t1*(1-c2)+c2*t2*(1-c1))/(c1*(1-c2)+c2*(1-c1));
-	else resT = (c1*t1*(1-c2)+c2*t2*(1-c1))/(c1*(1-c2)+c2*(1-c1));
+	resF = (f1*c1*(1-c2) + f2*c2*(1-c1))/(c1+c2-2*c1*c2);
+	resC = (c1+c2-2*c1*c2)/(1-c1*c2);
+	resT = (c1*t1*(1-c2)+c2*t2*(1-c1))/(c1+c2-2*c1*c2);
 
 	resT = this._adjustValue(resT);
 	resC = this._adjustValue(resC);
@@ -959,17 +958,15 @@ CertainTrustSimple.prototype._singlesimpleCONSENSUS = function(arg){
 	if (!this._operationAllowed(this, arg))
 		return undefined;
 
-	//resF = f1*f2;
-	if (this._almostEqual(resF, 1))		//avoid division by 0
-		resC = (c1+c2-2*c1*c2)/(1-c1*c2);
-	else
-		resC = (c1+c2-2*c1*c2)/(1-c1*c2);
+	var tempC = c1*c2;
+	if (this._almostEqual(tempC, 1)){		//avoid division by 0
+		c1 = 0.99999;
+		c2 = 0.99999;
+	}
 
-	if (this._almostEqual(resC, 0))
-		resT = 0.5;
-	else if (this._almostEqual(resF, 1))	//avoid division by 0
-		resT = (c1*t1*(1-c2)+c2*t2*(1-c1))/(c1*(1-c2)+c2*(1-c1));
-	else resT = (c1*t1*(1-c2)+c2*t2*(1-c1))/(c1*(1-c2)+c2*(1-c1));
+	resF = (f1*c1*(1-c2) + f2*c2*(1-c1))/(c1+c2-2*c1*c2);
+	resC = (c1+c2-2*c1*c2)/(1-c1*c2);
+	resT = (c1*t1*(1-c2)+c2*t2*(1-c1))/(c1+c2-2*c1*c2);
 
 	resT = this._adjustValue(resT);
 	resC = this._adjustValue(resC);