Github user takuti commented on a diff in the pull request:

    https://github.com/apache/incubator-hivemall/pull/52#discussion_r103401513
  
    --- Diff: core/src/main/java/hivemall/evaluation/AUCUDAF.java ---
    @@ -49,35 +50,251 @@
     @SuppressWarnings("deprecation")
     @Description(
             name = "auc",
    -        value = "_FUNC_(array rankItems, array correctItems [, const int 
recommendSize = rankItems.size])"
    +        value = "_FUNC_(array rankItems | double score, array correctItems 
| double label "
    +                + "[, const int recommendSize = rankItems.size ])"
                     + " - Returns AUC")
     public final class AUCUDAF extends AbstractGenericUDAFResolver {
     
    -    // prevent instantiation
    -    private AUCUDAF() {}
    -
         @Override
         public GenericUDAFEvaluator getEvaluator(@Nonnull TypeInfo[] typeInfo) 
throws SemanticException {
             if (typeInfo.length != 2 && typeInfo.length != 3) {
                 throw new UDFArgumentTypeException(typeInfo.length - 1,
                     "_FUNC_ takes two or three arguments");
             }
     
    -        ListTypeInfo arg1type = HiveUtils.asListTypeInfo(typeInfo[0]);
    -        if 
(!HiveUtils.isPrimitiveTypeInfo(arg1type.getListElementTypeInfo())) {
    -            throw new UDFArgumentTypeException(0,
    -                "The first argument `array rankItems` is invalid form: " + 
typeInfo[0]);
    +        if (HiveUtils.isNumberTypeInfo(typeInfo[0]) && 
HiveUtils.isNumberTypeInfo(typeInfo[1])) {
    +            return new ClassificationEvaluator();
    +        } else {
    +            ListTypeInfo arg1type = HiveUtils.asListTypeInfo(typeInfo[0]);
    +            if 
(!HiveUtils.isPrimitiveTypeInfo(arg1type.getListElementTypeInfo())) {
    +                throw new UDFArgumentTypeException(0,
    +                    "The first argument `array rankItems` is invalid form: 
" + typeInfo[0]);
    +            }
    +
    +            ListTypeInfo arg2type = HiveUtils.asListTypeInfo(typeInfo[1]);
    +            if 
(!HiveUtils.isPrimitiveTypeInfo(arg2type.getListElementTypeInfo())) {
    +                throw new UDFArgumentTypeException(1,
    +                    "The second argument `array correctItems` is invalid 
form: " + typeInfo[1]);
    +            }
    +
    +            return new RankingEvaluator();
    +        }
    +    }
    +
    +    public static class ClassificationEvaluator extends 
GenericUDAFEvaluator {
    +
    +        private PrimitiveObjectInspector scoreOI;
    +        private PrimitiveObjectInspector labelOI;
    +
    +        private StructObjectInspector internalMergeOI;
    +        private StructField aField;
    +        private StructField scorePrevField;
    +        private StructField fpField;
    +        private StructField tpField;
    +        private StructField fpPrevField;
    +        private StructField tpPrevField;
    +
    +        public ClassificationEvaluator() {}
    +
    +        @Override
    +        public ObjectInspector init(Mode mode, ObjectInspector[] 
parameters) throws HiveException {
    +            assert (parameters.length == 2 || parameters.length == 3) : 
parameters.length;
    +            super.init(mode, parameters);
    +
    +            // initialize input
    +            if (mode == Mode.PARTIAL1 || mode == Mode.COMPLETE) {// from 
original data
    +                this.scoreOI = (PrimitiveObjectInspector) parameters[0];
    +                this.labelOI = (PrimitiveObjectInspector) parameters[1];
    +            } else {// from partial aggregation
    +                StructObjectInspector soi = (StructObjectInspector) 
parameters[0];
    +                this.internalMergeOI = soi;
    +                this.aField = soi.getStructFieldRef("a");
    +                this.scorePrevField = soi.getStructFieldRef("scorePrev");
    +                this.fpField = soi.getStructFieldRef("fp");
    +                this.tpField = soi.getStructFieldRef("tp");
    +                this.fpPrevField = soi.getStructFieldRef("fpPrev");
    +                this.tpPrevField = soi.getStructFieldRef("tpPrev");
    +            }
    +
    +            // initialize output
    +            final ObjectInspector outputOI;
    +            if (mode == Mode.PARTIAL1 || mode == Mode.PARTIAL2) {// 
terminatePartial
    +                outputOI = internalMergeOI();
    +            } else {// terminate
    +                outputOI = 
PrimitiveObjectInspectorFactory.writableDoubleObjectInspector;
    +            }
    +            return outputOI;
    +        }
    +
    +        private static StructObjectInspector internalMergeOI() {
    +            ArrayList<String> fieldNames = new ArrayList<String>();
    +            ArrayList<ObjectInspector> fieldOIs = new 
ArrayList<ObjectInspector>();
    +
    +            fieldNames.add("a");
    +            
fieldOIs.add(PrimitiveObjectInspectorFactory.writableDoubleObjectInspector);
    +            fieldNames.add("scorePrev");
    +            
fieldOIs.add(PrimitiveObjectInspectorFactory.writableDoubleObjectInspector);
    +            fieldNames.add("fp");
    +            
fieldOIs.add(PrimitiveObjectInspectorFactory.writableLongObjectInspector);
    +            fieldNames.add("tp");
    +            
fieldOIs.add(PrimitiveObjectInspectorFactory.writableLongObjectInspector);
    +            fieldNames.add("fpPrev");
    +            
fieldOIs.add(PrimitiveObjectInspectorFactory.writableLongObjectInspector);
    +            fieldNames.add("tpPrev");
    +            
fieldOIs.add(PrimitiveObjectInspectorFactory.writableLongObjectInspector);
    +
    +            return 
ObjectInspectorFactory.getStandardStructObjectInspector(fieldNames, fieldOIs);
             }
    -        ListTypeInfo arg2type = HiveUtils.asListTypeInfo(typeInfo[1]);
    -        if 
(!HiveUtils.isPrimitiveTypeInfo(arg2type.getListElementTypeInfo())) {
    -            throw new UDFArgumentTypeException(1,
    -                "The second argument `array correctItems` is invalid form: 
" + typeInfo[1]);
    +
    +        @Override
    +        public AggregationBuffer getNewAggregationBuffer() throws 
HiveException {
    +            AggregationBuffer myAggr = new 
ClassificationAUCAggregationBuffer();
    +            reset(myAggr);
    +            return myAggr;
             }
     
    -        return new Evaluator();
    +        @Override
    +        public void reset(AggregationBuffer agg) throws HiveException {
    +            ClassificationAUCAggregationBuffer myAggr = 
(ClassificationAUCAggregationBuffer) agg;
    +            myAggr.reset();
    +        }
    +
    +        @Override
    +        public void iterate(AggregationBuffer agg, Object[] parameters) 
throws HiveException {
    +            ClassificationAUCAggregationBuffer myAggr = 
(ClassificationAUCAggregationBuffer) agg;
    +
    +            double score = HiveUtils.getDouble(parameters[0], scoreOI);
    +            double label = HiveUtils.getDouble(parameters[1], labelOI);
    --- End diff --
    
    `continue;` -> `return;`


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to