quickstep-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hbdeshm...@apache.org
Subject [18/20] incubator-quickstep git commit: Bug fixed in probability store.
Date Sat, 02 Jul 2016 23:17:54 GMT
Bug fixed in probability store.

- Correct calculation for cumulative probabilities after removing an
  object.


Project: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/commit/0b5c1db6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/tree/0b5c1db6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/diff/0b5c1db6

Branch: refs/heads/scheduler++
Commit: 0b5c1db67dab93aa95a055a2a43a7ca14fbb56b5
Parents: b382953
Author: Harshad Deshmukh <hbdeshmukh@apache.org>
Authored: Sun Jun 26 09:35:11 2016 -0500
Committer: Harshad Deshmukh <hbdeshmukh@apache.org>
Committed: Sat Jul 2 18:16:30 2016 -0500

----------------------------------------------------------------------
 query_execution/ProbabilityStore.hpp              |  4 ++--
 .../tests/ProbabilityStore_unittest.cpp           | 18 +++++++++---------
 2 files changed, 11 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/0b5c1db6/query_execution/ProbabilityStore.hpp
----------------------------------------------------------------------
diff --git a/query_execution/ProbabilityStore.hpp b/query_execution/ProbabilityStore.hpp
index ed52f75..7278e2b 100644
--- a/query_execution/ProbabilityStore.hpp
+++ b/query_execution/ProbabilityStore.hpp
@@ -173,7 +173,7 @@ class ProbabilityStore {
       }
       CHECK_GT(new_denominator, 0);
       common_denominator_ = new_denominator;
-      updateCumulativeProbabilities();
+      updateProbabilitiesNewDenominator();
     } else {
       // In order to keep the store consistent, we should keep the sizes of
       // individual_probabilities_ and cumulative_probabilities_ the same.
@@ -208,9 +208,9 @@ class ProbabilityStore {
     }
     float cumulative_probability = 0;
     for (const auto p : individual_probabilities_) {
+      cumulative_probability += p.second.second;
       cumulative_probabilities_.emplace_back(p.first,
                                              cumulative_probability);
-      cumulative_probability += p.second.second;
     }
     DCHECK(!cumulative_probabilities_.empty());
     // Adjust the last cumulative probability manually to 1, so that

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/0b5c1db6/query_execution/tests/ProbabilityStore_unittest.cpp
----------------------------------------------------------------------
diff --git a/query_execution/tests/ProbabilityStore_unittest.cpp b/query_execution/tests/ProbabilityStore_unittest.cpp
index dcec1e5..518699e 100644
--- a/query_execution/tests/ProbabilityStore_unittest.cpp
+++ b/query_execution/tests/ProbabilityStore_unittest.cpp
@@ -34,8 +34,8 @@ TEST(ProbabilityStoreTest, CountTest) {
   EXPECT_EQ(0u, store.getNumObjects());
 
   std::vector<std::size_t> objects {3, 5, 7, 9};
-  std::vector<float> numerators {1, 2, 3, 5};
-  const std::size_t kNewDenominator = 10;
+  std::vector<float> numerators {1, 2, 2, 5};
+  const std::size_t kNewDenominator = std::accumulate(numerators.begin(), numerators.end(),
0);
   store.addOrUpdateObjectsNewDenominator(objects, numerators, kNewDenominator);
 
   EXPECT_EQ(objects.size(), store.getNumObjects());
@@ -44,8 +44,8 @@ TEST(ProbabilityStoreTest, CountTest) {
 TEST(ProbabilityStoreTest, IndividualProbabilityTest) {
   ProbabilityStore store;
   std::vector<std::size_t> objects {3, 5, 7, 9};
-  std::vector<float> numerators {1, 2, 3, 5};
-  const std::size_t kNewDenominator = 10;
+  std::vector<float> numerators {1, 2, 2, 5};
+  const std::size_t kNewDenominator = std::accumulate(numerators.begin(), numerators.end(),
0);
   store.addOrUpdateObjectsNewDenominator(objects, numerators, kNewDenominator);
 
   for (std::size_t object_num = 0; object_num < objects.size(); ++object_num) {
@@ -57,8 +57,8 @@ TEST(ProbabilityStoreTest, IndividualProbabilityTest) {
 TEST(ProbabilityStoreTest, PickRandomPropertyTest) {
   ProbabilityStore store;
   std::vector<std::size_t> objects {3, 5, 7, 9};
-  std::vector<float> numerators {1, 2, 3, 5};
-  const std::size_t kNewDenominator = 10;
+  std::vector<float> numerators {1, 2, 2, 5};
+  const std::size_t kNewDenominator = std::accumulate(numerators.begin(), numerators.end(),
0);
   store.addOrUpdateObjectsNewDenominator(objects, numerators, kNewDenominator);
 
   const std::size_t kNumTrials = 10;
@@ -78,8 +78,8 @@ TEST(ProbabilityStoreTest, PickRandomPropertyTest) {
 TEST(ProbabilityStoreTest, RemoveObjectTest) {
   ProbabilityStore store;
   std::vector<std::size_t> objects {3, 5, 7, 9};
-  std::vector<float> numerators {1, 2, 3, 5};
-  const std::size_t kNewDenominator = 10;
+  std::vector<float> numerators {1, 2, 2, 5};
+  const std::size_t kNewDenominator = std::accumulate(numerators.begin(), numerators.end(),
0);
   store.addOrUpdateObjectsNewDenominator(objects, numerators, kNewDenominator);
 
   for (std::size_t object_num = 0; object_num < objects.size(); ++object_num) {
@@ -96,7 +96,7 @@ TEST(ProbabilityStoreTest, RemoveObjectTest) {
 
   EXPECT_EQ(expected_new_denominator, store.getDenominator());
   for (std::size_t object_num = 0; object_num < objects.size(); ++object_num) {
-    EXPECT_EQ(numerators[object_num] / static_cast<float>(kNewDenominator),
+    EXPECT_EQ(numerators[object_num] / static_cast<float>(expected_new_denominator),
               store.getIndividualProbability(objects[object_num]));
   }
 }


Mime
View raw message