All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ciir.umass.edu.learning.DenseDataPoint Maven / Gradle / Ivy

There is a newer version: 2.10.1
Show newest version
package ciir.umass.edu.learning;

import ciir.umass.edu.utilities.RankLibError;

public class DenseDataPoint extends DataPoint {

    public DenseDataPoint(final String text) {
        super(text);
    }

    public DenseDataPoint(final DenseDataPoint dp) {
        label = dp.label;
        id = dp.id;
        description = dp.description;
        cached = dp.cached;
        fVals = new float[dp.fVals.length];
        System.arraycopy(dp.fVals, 0, fVals, 0, dp.fVals.length);
    }

    @Override
    public float getFeatureValue(final int fid) {
        if (fid <= 0 || fid >= fVals.length) {
            if (missingZero) {
                return 0f;
            }
            throw RankLibError.create("Error in DenseDataPoint::getFeatureValue(): requesting unspecified feature, fid=" + fid);
        }
        if (isUnknown(fVals[fid])) {
            return 0;
        }
        return fVals[fid];
    }

    @Override
    public void setFeatureValue(final int fid, final float fval) {
        if (fid <= 0 || fid >= fVals.length) {
            throw RankLibError.create("Error in DenseDataPoint::setFeatureValue(): feature (id=" + fid + ") not found.");
        }
        fVals[fid] = fval;
    }

    @Override
    public void setFeatureVector(final float[] dfVals) {
        fVals = dfVals;
    }

    @Override
    public float[] getFeatureVector() {
        return fVals;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy