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

    https://github.com/apache/incubator-hivemall/pull/14#discussion_r97944071
  
    --- Diff: core/src/main/java/hivemall/optimizer/Optimizer.java ---
    @@ -0,0 +1,246 @@
    +/*
    + * Hivemall: Hive scalable Machine Learning Library
    + *
    + * Copyright (C) 2015 Makoto YUI
    + * Copyright (C) 2013-2015 National Institute of Advanced Industrial 
Science and Technology (AIST)
    + *
    + * Licensed 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 hivemall.optimizer;
    +
    +import java.util.Map;
    +import javax.annotation.Nonnull;
    +import javax.annotation.concurrent.NotThreadSafe;
    +
    +import hivemall.model.WeightValue;
    +import hivemall.model.IWeightValue;
    +
    +public interface Optimizer {
    +
    +    /**
    +     * Update the weights of models thru this interface.
    +     */
    +    float computeUpdatedValue(@Nonnull Object feature, float weight, float 
gradient);
    +
    +    // Count up #step to tune learning rate
    +    void proceedStep();
    +
    +    static abstract class OptimizerBase implements Optimizer {
    +
    +        protected final EtaEstimator etaImpl;
    +        protected final Regularization regImpl;
    +
    +        protected int numStep = 1;
    +
    +        public OptimizerBase(final Map<String, String> options) {
    +            this.etaImpl = EtaEstimator.get(options);
    +            this.regImpl = Regularization.get(options);
    +        }
    +
    +        @Override
    +        public void proceedStep() {
    +            numStep++;
    +        }
    +
    +        // Directly update a given `weight` in terms of performance
    +        protected void computeUpdateValue(
    +                @Nonnull final IWeightValue weight, float gradient) {
    +            float delta = computeUpdateValueImpl(weight, 
regImpl.regularize(weight.get(), gradient));
    +            weight.set(weight.get() - etaImpl.eta(numStep) * delta);
    +        }
    +
    +        // Compute a delta to update
    +        protected float computeUpdateValueImpl(
    +                @Nonnull final IWeightValue weight, float gradient) {
    +            return gradient;
    +        }
    +
    +    }
    +
    +    @NotThreadSafe
    +    static final class SGD extends OptimizerBase {
    +
    +        private final IWeightValue weightValueReused;
    +
    +        public SGD(final Map<String, String> options) {
    +            super(options);
    +            this.weightValueReused = new WeightValue(0.f);
    +        }
    +
    +        @Override
    +        public float computeUpdatedValue(
    +                @Nonnull Object feature, float weight, float gradient) {
    +            computeUpdateValue(weightValueReused, gradient);
    +            return weightValueReused.get();
    +        }
    +
    +    }
    +
    +    static abstract class AdaDelta extends OptimizerBase {
    +
    +        private final float decay;
    +        private final float eps;
    +        private final float scale;
    +
    +        public AdaDelta(Map<String, String> options) {
    +            super(options);
    +            float decay = 0.95f;
    +            float eps = 1e-6f;
    +            float scale = 100.0f;
    --- End diff --
    
    I see. Sounds reasonable.


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to