Java Code Examples for org.datavec.api.writable.Writable#toInt()

The following examples show how to use org.datavec.api.writable.Writable#toInt() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IntegerColumnCondition.java    From DataVec with Apache License 2.0 6 votes vote down vote up
@Override
public boolean columnCondition(Writable writable) {
    switch (op) {
        case LessThan:
            return writable.toInt() < value;
        case LessOrEqual:
            return writable.toInt() <= value;
        case GreaterThan:
            return writable.toInt() > value;
        case GreaterOrEqual:
            return writable.toInt() >= value;
        case Equal:
            return writable.toInt() == value;
        case NotEqual:
            return writable.toInt() != value;
        case InSet:
            return set.contains(writable.toInt());
        case NotInSet:
            return !set.contains(writable.toInt());
        default:
            throw new RuntimeException("Unknown or not implemented op: " + op);
    }
}
 
Example 2
Source File: IntegerColumnCondition.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
@Override
public boolean columnCondition(Writable writable) {
    switch (op) {
        case LessThan:
            return writable.toInt() < value;
        case LessOrEqual:
            return writable.toInt() <= value;
        case GreaterThan:
            return writable.toInt() > value;
        case GreaterOrEqual:
            return writable.toInt() >= value;
        case Equal:
            return writable.toInt() == value;
        case NotEqual:
            return writable.toInt() != value;
        case InSet:
            return set.contains(writable.toInt());
        case NotInSet:
            return !set.contains(writable.toInt());
        default:
            throw new RuntimeException("Unknown or not implemented op: " + op);
    }
}
 
Example 3
Source File: IntegerToOneHotTransform.java    From DataVec with Apache License 2.0 5 votes vote down vote up
@Override
public List<Writable> map(List<Writable> writables) {
    if (writables.size() != inputSchema.numColumns()) {
        throw new IllegalStateException("Cannot execute transform: input writables list length (" + writables.size()
                        + ") does not " + "match expected number of elements (schema: " + inputSchema.numColumns()
                        + "). Transform = " + toString());
    }
    int idx = getColumnIdx();

    int n = maxValue - minValue + 1;
    List<Writable> out = new ArrayList<>(writables.size() + n);

    int i = 0;
    for (Writable w : writables) {

        if (i++ == idx) {
            int currValue = w.toInt();
            if (currValue < minValue || currValue > maxValue) {
                throw new IllegalStateException("Invalid value: integer value (" + currValue + ") is outside of "
                                + "valid range: must be between " + minValue + " and " + maxValue + " inclusive");
            }

            for (int j = minValue; j <= maxValue; j++) {
                if (j == currValue) {
                    out.add(new IntWritable(1));
                } else {
                    out.add(new IntWritable(0));
                }
            }
        } else {
            //No change to this column
            out.add(w);
        }
    }
    return out;
}
 
Example 4
Source File: ConvertToInteger.java    From DataVec with Apache License 2.0 5 votes vote down vote up
@Override
public IntWritable map(Writable writable) {
    if(writable.getType() == WritableType.Int){
        return (IntWritable)writable;
    }
    return new IntWritable(writable.toInt());
}
 
Example 5
Source File: IntegerAnalysisCounter.java    From DataVec with Apache License 2.0 5 votes vote down vote up
@Override
public IntegerAnalysisCounter add(Writable writable) {
    int value = writable.toInt();

    if (value == 0)
        countZero++;

    if (value == getMinValueSeen())
        countMinValue++;
    else if (value < getMinValueSeen()) {
        countMinValue = 1;
    }

    if (value == getMaxValueSeen())
        countMaxValue++;
    else if (value > getMaxValueSeen()) {
        countMaxValue = 1;
    }

    if (value >= 0) {
        countPositive++;
    } else {
        countNegative++;
    } ;

    digest.add((double) value);

    counter.merge((double) value);

    return this;
}
 
Example 6
Source File: IntegerToOneHotTransform.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Override
public List<Writable> map(List<Writable> writables) {
    if (writables.size() != inputSchema.numColumns()) {
        throw new IllegalStateException("Cannot execute transform: input writables list length (" + writables.size()
                        + ") does not " + "match expected number of elements (schema: " + inputSchema.numColumns()
                        + "). Transform = " + toString());
    }
    int idx = getColumnIdx();

    int n = maxValue - minValue + 1;
    List<Writable> out = new ArrayList<>(writables.size() + n);

    int i = 0;
    for (Writable w : writables) {

        if (i++ == idx) {
            int currValue = w.toInt();
            if (currValue < minValue || currValue > maxValue) {
                throw new IllegalStateException("Invalid value: integer value (" + currValue + ") is outside of "
                                + "valid range: must be between " + minValue + " and " + maxValue + " inclusive");
            }

            for (int j = minValue; j <= maxValue; j++) {
                if (j == currValue) {
                    out.add(new IntWritable(1));
                } else {
                    out.add(new IntWritable(0));
                }
            }
        } else {
            //No change to this column
            out.add(w);
        }
    }
    return out;
}
 
Example 7
Source File: ConvertToInteger.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Override
public IntWritable map(Writable writable) {
    if(writable.getType() == WritableType.Int){
        return (IntWritable)writable;
    }
    return new IntWritable(writable.toInt());
}
 
Example 8
Source File: IntegerAnalysisCounter.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Override
public IntegerAnalysisCounter add(Writable writable) {
    int value = writable.toInt();

    if (value == 0)
        countZero++;

    if (value == getMinValueSeen())
        countMinValue++;
    else if (value < getMinValueSeen()) {
        countMinValue = 1;
    }

    if (value == getMaxValueSeen())
        countMaxValue++;
    else if (value > getMaxValueSeen()) {
        countMaxValue = 1;
    }

    if (value >= 0) {
        countPositive++;
    } else {
        countNegative++;
    } ;

    digest.add((double) value);
    counter.add((double) value);

    return this;
}
 
Example 9
Source File: ByteWritableOp.java    From DataVec with Apache License 2.0 4 votes vote down vote up
@Override
public void accept(Writable writable) {
    int val = writable.toInt();
    operation.accept((byte) val);
}
 
Example 10
Source File: TypeConversion.java    From DataVec with Apache License 2.0 4 votes vote down vote up
public int convertInt(Writable writable) {
    return writable.toInt();
}
 
Example 11
Source File: ByteWritableOp.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
@Override
public void accept(Writable writable) {
    int val = writable.toInt();
    operation.accept((byte) val);
}
 
Example 12
Source File: TypeConversion.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
public int convertInt(Writable writable) {
    return writable.toInt();
}