Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
alaeddinms opened this issue Sep 30, 2016 · 1 comment
Labels

Comments

@alaeddinms
Copy link

alaeddinms commented Sep 30, 2016

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,

@komiya-atsushi
Copy link
Owner

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;
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants