lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbern...@apache.org
Subject lucene-solr:branch_7x: SOLR-11697: Add geometricDistribution Stream Evaluator
Date Wed, 29 Nov 2017 02:31:45 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/branch_7x a3b46e45c -> 0ea1b3a80


SOLR-11697: Add geometricDistribution Stream Evaluator


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/0ea1b3a8
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/0ea1b3a8
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/0ea1b3a8

Branch: refs/heads/branch_7x
Commit: 0ea1b3a80a1d99c88b12596dd9ec3e19b2dab5c2
Parents: a3b46e4
Author: Joel Bernstein <jbernste@apache.org>
Authored: Tue Nov 28 21:16:06 2017 -0500
Committer: Joel Bernstein <jbernste@apache.org>
Committed: Tue Nov 28 21:27:55 2017 -0500

----------------------------------------------------------------------
 .../org/apache/solr/handler/StreamHandler.java  |  1 +
 .../io/eval/GeometricDistributionEvaluator.java | 44 ++++++++++++++++++++
 .../io/eval/PoissonDistributionEvaluator.java   |  2 +-
 .../solrj/io/stream/StreamExpressionTest.java   | 39 +++++++++++++++++
 4 files changed, 85 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0ea1b3a8/solr/core/src/java/org/apache/solr/handler/StreamHandler.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/StreamHandler.java b/solr/core/src/java/org/apache/solr/handler/StreamHandler.java
index a0a83c1..9446463 100644
--- a/solr/core/src/java/org/apache/solr/handler/StreamHandler.java
+++ b/solr/core/src/java/org/apache/solr/handler/StreamHandler.java
@@ -279,6 +279,7 @@ public class StreamHandler extends RequestHandlerBase implements SolrCoreAware,
         .withFunctionName("diff", TimeDifferencingEvaluator.class)
         .withFunctionName("corrPValues", CorrelationSignificanceEvaluator.class)
         .withFunctionName("normalizeSum", NormalizeSumEvaluator.class)
+        .withFunctionName("geometricDistribution", GeometricDistributionEvaluator.class)
 
         // Boolean Stream Evaluators
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0ea1b3a8/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/GeometricDistributionEvaluator.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/GeometricDistributionEvaluator.java
b/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/GeometricDistributionEvaluator.java
new file mode 100644
index 0000000..5874af3
--- /dev/null
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/GeometricDistributionEvaluator.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.client.solrj.io.eval;
+
+import java.io.IOException;
+import java.util.Locale;
+
+import org.apache.commons.math3.distribution.GeometricDistribution;
+import org.apache.solr.client.solrj.io.stream.expr.StreamExpression;
+import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;
+
+public class GeometricDistributionEvaluator extends RecursiveNumericEvaluator implements
OneValueWorker {
+
+  private static final long serialVersionUID = 1;
+
+  public GeometricDistributionEvaluator(StreamExpression expression, StreamFactory factory)
throws IOException {
+    super(expression, factory);
+  }
+
+  @Override
+  public Object doWork(Object first) throws IOException{
+    if(null == first){
+      throw new IOException(String.format(Locale.ROOT,"Invalid expression %s - null found
for the first value",toExpression(constructingFactory)));
+    }
+
+    Number prob = (Number)first;
+
+    return new GeometricDistribution(prob.doubleValue());
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0ea1b3a8/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/PoissonDistributionEvaluator.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/PoissonDistributionEvaluator.java
b/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/PoissonDistributionEvaluator.java
index 864a039..d3e89a9 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/PoissonDistributionEvaluator.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/PoissonDistributionEvaluator.java
@@ -39,6 +39,6 @@ public class PoissonDistributionEvaluator extends RecursiveNumericEvaluator
impl
 
     Number mean = (Number)first;
 
-    return new PoissonDistribution(mean.intValue());
+    return new PoissonDistribution(mean.doubleValue());
   }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0ea1b3a8/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionTest.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionTest.java
b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionTest.java
index 8f3c3f5..c9fa396 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionTest.java
@@ -6766,6 +6766,45 @@ public class StreamExpressionTest extends SolrCloudTestCase {
   }
 
   @Test
+  public void testGeometricDistribution() throws Exception {
+    String cexpr = "let(a=geometricDistribution(.2)," +
+        "               b=geometricDistribution(.5)," +
+        "               c=geometricDistribution(.8)," +
+        "               d=sample(a, 10000)," +
+        "               e=sample(b, 10000)," +
+        "               f=sample(c, 10000)," +
+        "               g=freqTable(d)," +
+        "               h=freqTable(e)," +
+        "               i=freqTable(f)," +
+        "               tuple(g=g, h=h, i=i))";
+
+    ModifiableSolrParams paramsLoc = new ModifiableSolrParams();
+    paramsLoc.set("expr", cexpr);
+    paramsLoc.set("qt", "/stream");
+    String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;
+    TupleStream solrStream = new SolrStream(url, paramsLoc);
+    StreamContext context = new StreamContext();
+    solrStream.setStreamContext(context);
+    List<Tuple> tuples = getTuples(solrStream);
+    assertTrue(tuples.size() == 1);
+
+    List<Map> listg = (List<Map>)tuples.get(0).get("g");
+    Map mapg = listg.get(0);
+    double pctg = (double) mapg.get("pct");
+    assertEquals(pctg, .2, .02 );
+
+    List<Map> listh = (List<Map>)tuples.get(0).get("h");
+    Map maph = listh.get(0);
+    double pcth = (double)maph.get("pct");
+    assertEquals(pcth, .5, .02 );
+
+    List<Map> listi = (List<Map>)tuples.get(0).get("i");
+    Map mapi = listi.get(0);
+    double pcti = (double)mapi.get("pct");
+    assertEquals(pcti, .8, .02 );
+  }
+
+  @Test
   public void testBinomialDistribution() throws Exception {
     String cexpr = "let(a=binomialDistribution(100, .50)," +
         "               b=sample(a, 10000)," +


Mime
View raw message