Commit e7a2d749 authored by dominich@chromium.org's avatar dominich@chromium.org

Confidence ranges were coming in too high and had occasional divide-by-zero...

Confidence ranges were coming in too high and had occasional divide-by-zero leading to CHECK failures. Changed the math and the unit tests to satisfy stricter confidence requirements and remove divide by zero.

BUG=95453
TEST=None

Review URL: http://codereview.chromium.org/7833046

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@99879 0039d316-1c4b-4281-b951-d872f2087c98
parent 2c471c7b
...@@ -52,9 +52,9 @@ NetworkActionPredictor::Action ...@@ -52,9 +52,9 @@ NetworkActionPredictor::Action
const double base_score = 1.0; const double base_score = 1.0;
// This constant is ln(1/0.8) so we end up decaying to 80% of the base score // This constant is ln(1/0.65) so we end up decaying to 65% of the base score
// for each week that passes. // for each week that passes.
const double kLnDecayPercent = 0.2231435513142097; const double kLnDecayPercent = 0.43078291609245;
base::TimeDelta time_passed = base::Time::Now() - url_row.last_visit(); base::TimeDelta time_passed = base::Time::Now() - url_row.last_visit();
// Clamp to 0. // Clamp to 0.
...@@ -63,13 +63,12 @@ NetworkActionPredictor::Action ...@@ -63,13 +63,12 @@ NetworkActionPredictor::Action
base::Time::kMicrosecondsPerWeek); base::Time::kMicrosecondsPerWeek);
const double kMaxDecaySpeedDivisor = 5.0; const double kMaxDecaySpeedDivisor = 5.0;
const double kNumUsesPerDecaySpeedDivisorIncrement = 1.0; const double kNumUsesPerDecaySpeedDivisorIncrement = 2.0;
const double decay_divisor = std::min(kMaxDecaySpeedDivisor, const double decay_divisor = std::min(kMaxDecaySpeedDivisor,
(url_row.typed_count() + kNumUsesPerDecaySpeedDivisorIncrement - 1) / (url_row.typed_count() + kNumUsesPerDecaySpeedDivisorIncrement - 1) /
kNumUsesPerDecaySpeedDivisorIncrement); kNumUsesPerDecaySpeedDivisorIncrement);
const double confidence = base_score / exp(decay_exponent / decay_divisor); const double confidence = base_score / exp(decay_exponent / decay_divisor);
CHECK(confidence >= 0.0 && confidence <= 1.0); CHECK(confidence >= 0.0 && confidence <= 1.0);
UMA_HISTOGRAM_COUNTS_100("NetworkActionPredictor.Confidence", UMA_HISTOGRAM_COUNTS_100("NetworkActionPredictor.Confidence",
......
...@@ -47,11 +47,11 @@ TEST_F(NetworkActionPredictorTest, RecommendAction) { ...@@ -47,11 +47,11 @@ TEST_F(NetworkActionPredictorTest, RecommendAction) {
{ GURL("http://www.testsite.com/b.html"), { GURL("http://www.testsite.com/b.html"),
ASCIIToUTF16("Test - site - just a test"), 0, 1, ASCIIToUTF16("Test - site - just a test"), 0, 1,
ASCIIToUTF16("just"), ASCIIToUTF16("just"),
NetworkActionPredictor::ACTION_NONE }, NetworkActionPredictor::ACTION_PRERENDER },
{ GURL("http://www.testsite.com/c.html"), { GURL("http://www.testsite.com/c.html"),
ASCIIToUTF16("Test - site - just a test"), 1, 5, ASCIIToUTF16("Test - site - just a test"), 1, 5,
ASCIIToUTF16("just"), ASCIIToUTF16("just"),
NetworkActionPredictor::ACTION_PRERENDER }, NetworkActionPredictor::ACTION_PRECONNECT },
{ GURL("http://www.testsite.com/d.html"), { GURL("http://www.testsite.com/d.html"),
ASCIIToUTF16("Test - site - just a test"), 2, 5, ASCIIToUTF16("Test - site - just a test"), 2, 5,
ASCIIToUTF16("just"), ASCIIToUTF16("just"),
...@@ -67,13 +67,13 @@ TEST_F(NetworkActionPredictorTest, RecommendAction) { ...@@ -67,13 +67,13 @@ TEST_F(NetworkActionPredictorTest, RecommendAction) {
{ GURL("http://www.testsite.com/g.html"), { GURL("http://www.testsite.com/g.html"),
ASCIIToUTF16("Test - site - just a test"), 1, 12, ASCIIToUTF16("Test - site - just a test"), 1, 12,
ASCIIToUTF16("just a"), ASCIIToUTF16("just a"),
NetworkActionPredictor::ACTION_PRECONNECT }, NetworkActionPredictor::ACTION_NONE },
{ GURL("http://www.testsite.com/h.html"), { GURL("http://www.testsite.com/h.html"),
ASCIIToUTF16("Test - site - just a test"), 1, 21, ASCIIToUTF16("Test - site - just a test"), 2, 21,
ASCIIToUTF16("just a test"), ASCIIToUTF16("just a test"),
NetworkActionPredictor::ACTION_PRECONNECT }, NetworkActionPredictor::ACTION_NONE },
{ GURL("http://www.testsite.com/i.html"), { GURL("http://www.testsite.com/i.html"),
ASCIIToUTF16("Test - site - just a test"), 1, 28, ASCIIToUTF16("Test - site - just a test"), 3, 28,
ASCIIToUTF16("just a test"), ASCIIToUTF16("just a test"),
NetworkActionPredictor::ACTION_NONE } NetworkActionPredictor::ACTION_NONE }
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment