Peter-Devine / test_repo_0

A repo purely for testing Github API functions
0 stars 0 forks source link

When creating feature vector from dense representation by array, do you use the first element as the first feature or the label? #1

Open Peter-Devine opened 4 years ago

Peter-Devine commented 4 years ago

Hi,

When creating feature vector from dense representation by array, do you use the first element in the array for the first feature and the second for the second and so on or is the first element for the label as a placeholder?

Thanks,

Peter-Devine commented 4 years ago

Hi,

This library don't provide any functions to handle labeled feature vector, so you should write & use code like below:

public class FVecFloatArrayWithLabel implements FVec {
    private final float[] values;
    private final boolean treatsZeroAsNA;

    FVecFloatArrayWithLabel(float[] values, boolean treatsZeroAsNA) {
        this.values = values;
        this.treatsZeroAsNA = treatsZeroAsNA;
    }

    @Override
    public double fvalue(int index) {
        if (values.length <= index + 1) {
            return Double.NaN;
        }

        double result = values[index + 1];
        if (treatsZeroAsNA && result == 0) {
            return Double.NaN;
        }

        return result;
    }
}