[ 
https://issues.apache.org/jira/browse/SDAP-52?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16410777#comment-16410777
 ] 

ASF GitHub Bot commented on SDAP-52:
------------------------------------

lewismc commented on a change in pull request #9: SDAP-52 Improve ranking speed
URL: 
https://github.com/apache/incubator-sdap-mudrod/pull/9#discussion_r176634815
 
 

 ##########
 File path: core/src/main/java/org/apache/sdap/mudrod/ssearch/Ranker.java
 ##########
 @@ -147,42 +137,32 @@ private double getNDForm(double d) {
       }
     }
 
-    // using collection.sort directly would cause an "not transitive" error
-    // this is because the training model is not a overfitting model
-    for (int j = 0; j < resultList.size(); j++) {
-      for (int k = 0; k < resultList.size(); k++) {
-        if (k != j) {
-          resultList.get(j).below += comp(resultList.get(j), 
resultList.get(k));
-        }
-      }
-    }
-
     Collections.sort(resultList, new ResultComparator());
     return resultList;
   }
-
+  
   /**
-   * Method of compare two search resutls
-   *
-   * @param o1 search result 1
-   * @param o2 search result 2
-   * @return 1 if o1 is greater than o2, 0 otherwise
+   * Method of comparing results based on final score
    */
-  public int comp(SResult o1, SResult o2) {
-    List<Double> instList = new ArrayList<>();
-    for (int i = 0; i < SResult.rlist.length; i++) {
-      double o2Score = SResult.get(o2, SResult.rlist[i]);
-      double o1Score = SResult.get(o1, SResult.rlist[i]);
-      instList.add(o2Score - o1Score);
-    }
+  public class ResultComparator implements Comparator<SResult> {
+    @Override
+    public int compare(SResult o1, SResult o2) {
+      List<Double> instList = new ArrayList<>();
+      for (int i = 0; i < SResult.rlist.length; i++) {
+        double o2Score = SResult.get(o2, SResult.rlist[i]);
+        double o1Score = SResult.get(o1, SResult.rlist[i]);
+        instList.add(o2Score - o1Score);
+      }
 
-    double[] ins = instList.stream().mapToDouble(i -> i).toArray();
-    LabeledPoint insPoint = new LabeledPoint(99.0, Vectors.dense(ins));
-    double prediction = le.classify(insPoint);
-    if (equalComp(prediction, 1)) { //different from weka where the return 
value is 1 or 2
-      return 0;
-    } else {
-      return 1;
+      double[] ins = instList.stream().mapToDouble(i -> i).toArray();
+      LabeledPoint insPoint = new LabeledPoint(99.0, Vectors.dense(ins));
+      int prediction = (int)le.classify(insPoint);
+      
+      if (prediction==1) { //different from weka where the return value is 1 
or 2
+        return 1;
 
 Review comment:
   Would you not just return the variable ```prediction```?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> Improve ranking speed
> ---------------------
>
>                 Key: SDAP-52
>                 URL: https://issues.apache.org/jira/browse/SDAP-52
>             Project: Apache Science Data Analytics Platform
>          Issue Type: Improvement
>            Reporter: Yongyao Jiang
>            Assignee: Yongyao Jiang
>            Priority: Minor
>
> The time complexity of the current machine learning algorithm O(n2) because 
> the order of some items are not transitive and using collection.sort directly 
> would cause an "comparison method violates it general contract" error. Needs 
> to improve it to O(N*logN).



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to