hivemall-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From myui <...@git.apache.org>
Subject [GitHub] incubator-hivemall pull request #14: [WIP] Separate optimizer implementation...
Date Thu, 26 Jan 2017 07:12:46 GMT
Github user myui commented on a diff in the pull request:

    https://github.com/apache/incubator-hivemall/pull/14#discussion_r97716643
  
    --- Diff: core/src/main/java/hivemall/model/NewSparseModel.java ---
    @@ -0,0 +1,197 @@
    +/*
    + * 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.model;
    +
    +import hivemall.model.WeightValueWithClock.WeightValueParamsF1Clock;
    +import hivemall.model.WeightValueWithClock.WeightValueParamsF2Clock;
    +import hivemall.model.WeightValueWithClock.WeightValueWithCovarClock;
    +import hivemall.utils.collections.IMapIterator;
    +import hivemall.utils.collections.OpenHashMap;
    +
    +import javax.annotation.Nonnull;
    +
    +import org.apache.commons.logging.Log;
    +import org.apache.commons.logging.LogFactory;
    +
    +public final class NewSparseModel extends AbstractPredictionModel {
    +    private static final Log logger = LogFactory.getLog(NewSparseModel.class);
    +
    +    private final OpenHashMap<Object, IWeightValue> weights;
    +    private final boolean hasCovar;
    +    private boolean clockEnabled;
    +
    +    public NewSparseModel(int size) {
    +        this(size, false);
    +    }
    +
    +    public NewSparseModel(int size, boolean hasCovar) {
    +        super();
    +        this.weights = new OpenHashMap<Object, IWeightValue>(size);
    +        this.hasCovar = hasCovar;
    +        this.clockEnabled = false;
    +    }
    +
    +    @Override
    +    protected boolean isDenseModel() {
    +        return false;
    +    }
    +
    +    @Override
    +    public boolean hasCovariance() {
    +        return hasCovar;
    +    }
    +
    +    @Override
    +    public void configureParams(boolean sum_of_squared_gradients, boolean sum_of_squared_delta_x,
    +            boolean sum_of_gradients) {}
    +
    +    @Override
    +    public void configureClock() {
    +        this.clockEnabled = true;
    +    }
    +
    +    @Override
    +    public boolean hasClock() {
    +        return clockEnabled;
    +    }
    +
    +    @SuppressWarnings("unchecked")
    +    @Override
    +    public <T extends IWeightValue> T get(final Object feature) {
    +        return (T) weights.get(feature);
    +    }
    +
    +    @Override
    +    public <T extends IWeightValue> void set(final Object feature, final T value)
{
    +        assert (feature != null);
    +        assert (value != null);
    +
    +        final IWeightValue wrapperValue = wrapIfRequired(value);
    +
    +        if (clockEnabled && value.isTouched()) {
    +            IWeightValue old = weights.get(feature);
    +            if (old != null) {
    +                short newclock = (short) (old.getClock() + (short) 1);
    +                wrapperValue.setClock(newclock);
    +                int newDelta = old.getDeltaUpdates() + 1;
    +                wrapperValue.setDeltaUpdates((byte) newDelta);
    +            }
    +        }
    +        weights.put(feature, wrapperValue);
    +
    +        onUpdate(feature, wrapperValue);
    +    }
    +
    +    @Override
    +    public void delete(@Nonnull Object feature) {
    +        weights.remove(feature);
    +    }
    +
    +    private IWeightValue wrapIfRequired(final IWeightValue value) {
    +        final IWeightValue wrapper;
    +        if (clockEnabled) {
    +            switch (value.getType()) {
    +                case NoParams:
    +                    wrapper = new WeightValueWithClock(value);
    +                    break;
    +                case ParamsCovar:
    +                    wrapper = new WeightValueWithCovarClock(value);
    +                    break;
    +                case ParamsF1:
    +                    wrapper = new WeightValueParamsF1Clock(value);
    +                    break;
    +                case ParamsF2:
    +                    wrapper = new WeightValueParamsF2Clock(value);
    +                    break;
    +                default:
    +                    throw new IllegalStateException("Unexpected value type: " + value.getType());
    --- End diff --
    
    It was a bug. Fixed.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message