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

    https://github.com/apache/incubator-hivemall/pull/149#discussion_r200605210
  
    --- Diff: core/src/main/java/hivemall/fm/FactorizationMachineUDTF.java ---
    @@ -351,19 +370,29 @@ private static void writeBuffer(@Nonnull ByteBuffer 
srcBuf, @Nonnull NioStateful
             srcBuf.clear();
         }
     
    -    public void train(@Nonnull final Feature[] x, final double y,
    -            final boolean adaptiveRegularization) throws HiveException {
    +    protected void checkInputVector(@Nonnull final Feature[] x) throws 
HiveException {
             _model.check(x);
    +    }
    +
    +    protected void processValidationSample(@Nonnull final Feature[] x, 
final double y)
    +            throws HiveException {
    +        if (_adaptiveRegularization) {
    +            trainLambda(x, y); // adaptive regularization
    +        }
    +        if (_earlyStopping) {
    +            double p = _model.predict(x);
    +            double loss = _lossFunction.loss(p, y);
    +            _validationState.incrLoss(loss);
    +        }
    +    }
    +
    +    public void train(@Nonnull final Feature[] x, final double y, final 
boolean validation)
    +            throws HiveException {
    +        checkInputVector(x);
    --- End diff --
    
    avoid too many virtual method call. 
    
    `_model.check(x);` is enough both for FM and FFM.


---

Reply via email to