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

    https://github.com/apache/incubator-hivemall/pull/14#discussion_r97715714
  
    --- Diff: core/src/main/java/hivemall/model/NewDenseModel.java ---
    @@ -0,0 +1,293 @@
    +/*
    + * 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 java.util.Arrays;
    +import javax.annotation.Nonnull;
    +
    +import org.apache.commons.logging.Log;
    +import org.apache.commons.logging.LogFactory;
    +
    +import hivemall.model.WeightValue.WeightValueWithCovar;
    +import hivemall.utils.collections.IMapIterator;
    +import hivemall.utils.hadoop.HiveUtils;
    +import hivemall.utils.lang.Copyable;
    +import hivemall.utils.math.MathUtils;
    +
    +public final class NewDenseModel extends AbstractPredictionModel {
    +    private static final Log logger = 
LogFactory.getLog(NewDenseModel.class);
    +
    +    private int size;
    +    private float[] weights;
    +    private float[] covars;
    +
    +    // optional value for MIX
    +    private short[] clocks;
    +    private byte[] deltaUpdates;
    +
    +    public NewDenseModel(int ndims) {
    +        this(ndims, false);
    +    }
    +
    +    public NewDenseModel(int ndims, boolean withCovar) {
    +        super();
    +        int size = ndims + 1;
    +        this.size = size;
    +        this.weights = new float[size];
    +        if (withCovar) {
    +            float[] covars = new float[size];
    +            Arrays.fill(covars, 1f);
    +            this.covars = covars;
    +        } else {
    +            this.covars = null;
    +        }
    +        this.clocks = null;
    +        this.deltaUpdates = null;
    +    }
    +
    +    @Override
    +    protected boolean isDenseModel() {
    +        return true;
    +    }
    +
    +    @Override
    +    public boolean hasCovariance() {
    +        return covars != null;
    +    }
    +
    +    @Override
    +    public void configureParams(boolean sum_of_squared_gradients, boolean 
sum_of_squared_delta_x,
    +            boolean sum_of_gradients) {}
    +
    +    @Override
    +    public void configureClock() {
    +        if (clocks == null) {
    +            this.clocks = new short[size];
    +            this.deltaUpdates = new byte[size];
    +        }
    +    }
    +
    +    @Override
    +    public boolean hasClock() {
    +        return clocks != null;
    +    }
    +
    +    @Override
    +    public void resetDeltaUpdates(int feature) {
    +        deltaUpdates[feature] = 0;
    +    }
    +
    +    private void ensureCapacity(final int index) {
    +        if (index >= size) {
    +            int bits = MathUtils.bitsRequired(index);
    +            int newSize = (1 << bits) + 1;
    +            int oldSize = size;
    +            logger.info("Expands internal array size from " + oldSize + " 
to " + newSize + " ("
    +                    + bits + " bits)");
    +            this.size = newSize;
    +            this.weights = Arrays.copyOf(weights, newSize);
    +            if (covars != null) {
    +                this.covars = Arrays.copyOf(covars, newSize);
    +                Arrays.fill(covars, oldSize, newSize, 1.f);
    +            }
    +            if(clocks != null) {
    +                this.clocks = Arrays.copyOf(clocks, newSize);
    +                this.deltaUpdates = Arrays.copyOf(deltaUpdates, newSize);
    +            }
    +        }
    +    }
    +
    +    @SuppressWarnings("unchecked")
    +    @Override
    +    public <T extends IWeightValue> T get(Object feature) {
    +        final int i = HiveUtils.parseInt(feature);
    +        if (i >= size) {
    +            return null;
    +        }
    +        if(covars != null) {
    +            return (T) new WeightValueWithCovar(weights[i], covars[i]);
    +        } else {
    +            return (T) new WeightValue(weights[i]);
    +        }
    +    }
    +
    +    @Override
    +    public <T extends IWeightValue> void set(Object feature, T value) {
    --- End diff --
    
    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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to