You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by to...@apache.org on 2017/06/08 15:43:51 UTC
svn commit: r1798083 - in /jackrabbit/oak/branches/1.6: ./
oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/
oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/
Author: tommaso
Date: Thu Jun 8 15:43:51 2017
New Revision: 1798083
URL: http://svn.apache.org/viewvc?rev=1798083&view=rev
Log:
OAK-6317 - fixed LMSEstimator update rule (branch 1.6)
Modified:
jackrabbit/oak/branches/1.6/ (props changed)
jackrabbit/oak/branches/1.6/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/LMSEstimator.java
jackrabbit/oak/branches/1.6/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/LMSEstimatorTest.java
Propchange: jackrabbit/oak/branches/1.6/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Jun 8 15:43:51 2017
@@ -1,3 +1,3 @@
/jackrabbit/oak/branches/1.0:1665962
-/jackrabbit/oak/trunk:1781068,1781075,1781248,1781386,1781846,1781907,1782000,1782029,1782196,1782447,1782476,1782770,1782945,1782966,1782973,1782990,1783061,1783066,1783089,1783104-1783105,1783110,1783619,1783720,1783731,1783733,1783738,1783742,1783773,1783855,1783891,1784023,1784034,1784130,1784162,1784251,1784401,1784551,1784574,1784689,1785095,1785108,1785283,1785838,1785919,1785946,1787074,1787145,1787217,1787425,1788056,1788378,1788387-1788389,1788850,1789056,1789534,1790382,1792463,1792742,1792746,1793088,1793618,1793627,1793644,1795138,1795314,1795330,1795475,1795488,1795491,1795502,1795594,1795613,1795618,1796144,1796230,1796239,1796274,1796278,1796988
+/jackrabbit/oak/trunk:1781068,1781075,1781248,1781386,1781846,1781907,1782000,1782029,1782196,1782447,1782476,1782770,1782945,1782966,1782973,1782990,1783061,1783066,1783089,1783104-1783105,1783110,1783619,1783720,1783731,1783733,1783738,1783742,1783773,1783855,1783891,1784023,1784034,1784130,1784162,1784251,1784401,1784551,1784574,1784689,1785095,1785108,1785283,1785838,1785919,1785946,1787074,1787145,1787217,1787425,1788056,1788378,1788387-1788389,1788850,1789056,1789534,1790382,1792463,1792742,1792746,1793088,1793618,1793627,1793644,1795138,1795314,1795330,1795475,1795488,1795491,1795502,1795594,1795613,1795618,1796144,1796230,1796239,1796274,1796278,1796988,1798035
/jackrabbit/trunk:1345480
Modified: jackrabbit/oak/branches/1.6/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/LMSEstimator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.6/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/LMSEstimator.java?rev=1798083&r1=1798082&r2=1798083&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.6/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/LMSEstimator.java (original)
+++ jackrabbit/oak/branches/1.6/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/LMSEstimator.java Thu Jun 8 15:43:51 2017
@@ -22,11 +22,13 @@ import org.apache.jackrabbit.oak.spi.que
import org.apache.solr.common.SolrDocumentList;
/**
- * A very simple estimator for no. of entries in the index using least mean square update method but not the full stochastic
- * gradient descent algorithm (yet?), on a linear interpolation model.
+ * A very simple estimator for no. of entries in the index using least mean square update method for linear regression.
*/
class LMSEstimator {
+ private static final double DEFAULT_ALPHA = 0.03;
+ private static final int DEFAULT_THRESHOLD = 5;
+
private double[] weights;
private final double alpha;
private final long threshold;
@@ -38,23 +40,25 @@ class LMSEstimator {
}
LMSEstimator(double[] weights) {
- this(0.03, weights, 5);
+ this(DEFAULT_ALPHA, weights, DEFAULT_THRESHOLD);
}
LMSEstimator() {
- this(0.03, new double[5], 5);
+ this(DEFAULT_ALPHA, new double[5], 5);
}
synchronized void update(Filter filter, SolrDocumentList docs) {
double[] updatedWeights = new double[weights.length];
+
+ // least mean square cost
long estimate = estimate(filter);
long numFound = docs.getNumFound();
- long diff = numFound - estimate;
- double delta = Math.pow(diff, 2) / 2;
+ long residual = numFound - estimate;
+ double delta = Math.pow(residual, 2);
+
if (Math.abs(delta) > threshold) {
for (int i = 0; i < updatedWeights.length; i++) {
- double errors = delta * getInput(filter, i);
- updatedWeights[i] = weights[i] + (diff > 0 ? 1 : -1) * alpha * errors;
+ updatedWeights[i] = weights[i] + alpha * residual * getInput(filter, i);
}
// weights updated
weights = Arrays.copyOf(updatedWeights, 5);
Modified: jackrabbit/oak/branches/1.6/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/LMSEstimatorTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.6/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/LMSEstimatorTest.java?rev=1798083&r1=1798082&r2=1798083&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.6/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/LMSEstimatorTest.java (original)
+++ jackrabbit/oak/branches/1.6/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/LMSEstimatorTest.java Thu Jun 8 15:43:51 2017
@@ -53,18 +53,22 @@ public class LMSEstimatorTest {
docs.setNumFound(actualCount);
long estimate = lmsEstimator.estimate(filter);
+ assertEquals(estimate, lmsEstimator.estimate(filter));
long diff = actualCount - estimate;
// update causes weights adjustment
lmsEstimator.update(filter, docs);
long estimate2 = lmsEstimator.estimate(filter);
+ assertEquals(estimate2, lmsEstimator.estimate(filter));
long diff2 = actualCount - estimate2;
assertTrue(diff2 < diff); // new estimate is more accurate than previous one
// update doesn't cause weight adjustments therefore estimates stays unchanged
lmsEstimator.update(filter, docs);
long estimate3 = lmsEstimator.estimate(filter);
- assertEquals(estimate3, estimate2);
+ assertEquals(estimate3, lmsEstimator.estimate(filter));
+ long diff3 = actualCount - estimate3;
+ assertTrue(diff3 < diff2);
}
@Test