You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@quickstep.apache.org by hb...@apache.org on 2016/06/29 21:06:33 UTC

[04/19] incubator-quickstep git commit: Bug fixed in probability store.

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/91ec0b32
Tree: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/tree/91ec0b32
Diff: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/diff/91ec0b32

Branch: refs/heads/scheduler++
Commit: 91ec0b323cc3c5fdb43d3a24b29c23570f355c1e
Parents: 54d934a
Author: Harshad Deshmukh <hb...@apache.org>
Authored: Sun Jun 26 09:35:11 2016 -0500
Committer: Harshad Deshmukh <hb...@apache.org>
Committed: Wed Jun 29 16:06:07 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/91ec0b32/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/91ec0b32/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]));
   }
 }