Java Code Examples for org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorUtils#getFloat()

The following examples show how to use org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorUtils#getFloat() . 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: XGBoostBatchPredictUDTF.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
@Nonnull
private static LabeledPointWithRowId parseDenseFeatures(@Nonnull final Writable rowId,
        @Nonnull final Object argObj, @Nonnull final ListObjectInspector featureListOI,
        @Nonnull final PrimitiveObjectInspector featureElemOI) throws UDFArgumentException {
    final int size = featureListOI.getListLength(argObj);

    final float[] values = new float[size];
    for (int i = 0; i < size; i++) {
        final Object o = featureListOI.getListElement(argObj, i);
        if (o == null) {
            values[i] = Float.NaN;
        } else {
            float v = PrimitiveObjectInspectorUtils.getFloat(o, featureElemOI);
            values[i] = v;
        }
    }

    return new LabeledPointWithRowId(rowId, /* dummy label */ 0.f, null, values);

}
 
Example 2
Source File: GeneralLearnerBaseUDTF.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
@Override
public void process(Object[] args) throws HiveException {
    if (is_mini_batch && accumulated == null) {
        this.accumulated = new HashMap<Object, FloatAccumulator>(1024);
    }

    List<?> features = (List<?>) featureListOI.getList(args[0]);
    FeatureValue[] featureVector = parseFeatures(features);
    if (featureVector == null) {
        return;
    }
    float target = PrimitiveObjectInspectorUtils.getFloat(args[1], targetOI);
    checkTargetValue(target);

    count++;
    train(featureVector, target);

    recordTrainSampleToTempFile(featureVector, target);
}
 
Example 3
Source File: SlimUDTF.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
@Nonnull
private static Int2FloatMap int2floatMap(@Nonnull final Map<?, ?> map,
        @Nonnull final PrimitiveObjectInspector keyOI,
        @Nonnull final PrimitiveObjectInspector valueOI) {
    final Int2FloatMap result = new Int2FloatOpenHashMap(map.size());
    result.defaultReturnValue(0.f);

    for (Map.Entry<?, ?> entry : map.entrySet()) {
        float v = PrimitiveObjectInspectorUtils.getFloat(entry.getValue(), valueOI);
        if (v == 0.f) {
            continue;
        }
        int k = PrimitiveObjectInspectorUtils.getInt(entry.getKey(), keyOI);
        result.put(k, v);
    }

    return result;
}
 
Example 4
Source File: SlimUDTF.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
@Nonnull
private static Int2FloatMap int2floatMap(final int item, @Nonnull final Map<?, ?> map,
        @Nonnull final PrimitiveObjectInspector keyOI,
        @Nonnull final PrimitiveObjectInspector valueOI, @Nullable final FloatMatrix dataMatrix,
        @Nullable Int2FloatMap dst) {
    if (dst == null) {
        dst = new Int2FloatOpenHashMap(map.size());
        dst.defaultReturnValue(0.f);
    } else {
        dst.clear();
    }

    for (Map.Entry<?, ?> entry : map.entrySet()) {
        float rating = PrimitiveObjectInspectorUtils.getFloat(entry.getValue(), valueOI);
        if (rating == 0.f) {
            continue;
        }
        int user = PrimitiveObjectInspectorUtils.getInt(entry.getKey(), keyOI);
        dst.put(user, rating);
        if (dataMatrix != null) {
            dataMatrix.set(item, user, rating);
        }
    }

    return dst;
}
 
Example 5
Source File: HiveUtils.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
@Nullable
public static float[] asFloatArray(@Nullable final Object argObj,
        @Nonnull final ListObjectInspector listOI,
        @Nonnull final PrimitiveObjectInspector elemOI, final boolean avoidNull)
        throws UDFArgumentException {
    if (argObj == null) {
        return null;
    }
    final int length = listOI.getListLength(argObj);
    final float[] ary = new float[length];
    for (int i = 0; i < length; i++) {
        Object o = listOI.getListElement(argObj, i);
        if (o == null) {
            if (avoidNull) {
                continue;
            }
            throw new UDFArgumentException("Found null at index " + i);
        }
        ary[i] = PrimitiveObjectInspectorUtils.getFloat(o, elemOI);
    }
    return ary;
}
 
Example 6
Source File: PLSAPredictUDAF.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
@Override
public void iterate(@SuppressWarnings("deprecation") AggregationBuffer agg,
        Object[] parameters) throws HiveException {
    PLSAPredictAggregationBuffer myAggr = (PLSAPredictAggregationBuffer) agg;

    if (parameters[0] == null || parameters[1] == null || parameters[2] == null
            || parameters[3] == null) {
        return;
    }

    String word = PrimitiveObjectInspectorUtils.getString(parameters[0], wordOI);
    float value = PrimitiveObjectInspectorUtils.getFloat(parameters[1], valueOI);
    int label = PrimitiveObjectInspectorUtils.getInt(parameters[2], labelOI);
    float prob = PrimitiveObjectInspectorUtils.getFloat(parameters[3], probOI);

    myAggr.iterate(word, value, label, prob);
}
 
Example 7
Source File: RegressionBaseUDTF.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
@Override
public void process(Object[] args) throws HiveException {
    if (is_mini_batch && accumulated == null) {
        this.accumulated = new HashMap<Object, FloatAccumulator>(1024);
    }

    List<?> features = (List<?>) featureListOI.getList(args[0]);
    FeatureValue[] featureVector = parseFeatures(features);
    if (featureVector == null) {
        return;
    }
    float target = PrimitiveObjectInspectorUtils.getFloat(args[1], targetOI);
    checkTargetValue(target);

    count++;

    train(featureVector, target);
}
 
Example 8
Source File: DataToSketchUDAF.java    From incubator-datasketches-hive with Apache License 2.0 6 votes vote down vote up
private void initializeState(final UnionState state, final Object[] parameters) {
  int sketchSize = DEFAULT_NOMINAL_ENTRIES;
  if (nominalEntriesObjectInspector != null) {
    sketchSize = PrimitiveObjectInspectorUtils.getInt(parameters[1], nominalEntriesObjectInspector);
  }
  float samplingProbability = UnionState.DEFAULT_SAMPLING_PROBABILITY;
  if (samplingProbabilityObjectInspector != null) {
    samplingProbability = PrimitiveObjectInspectorUtils.getFloat(parameters[2],
        samplingProbabilityObjectInspector);
  }
  long seed = DEFAULT_UPDATE_SEED;
  if (seedObjectInspector != null) {
    seed = PrimitiveObjectInspectorUtils.getLong(parameters[3], seedObjectInspector);
  }
  state.init(sketchSize, samplingProbability, seed);
}
 
Example 9
Source File: XGBoostTrainUDTF.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
@Override
public void process(@Nonnull Object[] args) throws HiveException {
    if (args[0] == null) {
        throw new HiveException("array<double> features was null");
    }
    parseFeatures(args[0], matrixBuilder);

    float target = PrimitiveObjectInspectorUtils.getFloat(args[1], targetOI);
    labels.add(processTargetValue(target));
}
 
Example 10
Source File: DataToSketchUDAF.java    From incubator-datasketches-hive with Apache License 2.0 5 votes vote down vote up
private void initializeState(final SketchState<U, S> state, final Object[] data) {
  int nominalNumEntries = DEFAULT_NOMINAL_ENTRIES;
  if (nominalNumEntriesInspector_ != null) {
    nominalNumEntries = PrimitiveObjectInspectorUtils.getInt(data[2], nominalNumEntriesInspector_);
  }
  float samplingProbability = DEFAULT_SAMPLING_PROBABILITY;
  if (samplingProbabilityInspector_ != null) {
    samplingProbability = PrimitiveObjectInspectorUtils.getFloat(data[3],
        samplingProbabilityInspector_);
  }
  state.init(nominalNumEntries, samplingProbability, getSummaryFactory(data));
}
 
Example 11
Source File: DataToArrayOfDoublesSketchUDAF.java    From incubator-datasketches-hive with Apache License 2.0 5 votes vote down vote up
private void initializeState(final ArrayOfDoublesSketchState state, final Object[] data) {
  int nominalNumEntries = DEFAULT_NOMINAL_ENTRIES;
  if (nominalNumEntriesInspector_ != null) {
    nominalNumEntries =
        PrimitiveObjectInspectorUtils.getInt(data[numValues_ + 1], nominalNumEntriesInspector_);
  }
  float samplingProbability = DEFAULT_SAMPLING_PROBABILITY;
  if (samplingProbabilityInspector_ != null) {
    samplingProbability = PrimitiveObjectInspectorUtils.getFloat(data[numValues_ + 2],
        samplingProbabilityInspector_);
  }
  state.init(nominalNumEntries, samplingProbability, numValues_);
}
 
Example 12
Source File: HiveUtils.java    From incubator-hivemall with Apache License 2.0 4 votes vote down vote up
public static float getFloat(@Nullable Object o, @Nonnull PrimitiveObjectInspector oi) {
    if (o == null) {
        return 0.f;
    }
    return PrimitiveObjectInspectorUtils.getFloat(o, oi);
}
 
Example 13
Source File: Distance2SimilarityUDF.java    From incubator-hivemall with Apache License 2.0 4 votes vote down vote up
@Override
public FloatWritable evaluate(DeferredObject[] arguments) throws HiveException {
    float d = PrimitiveObjectInspectorUtils.getFloat(arguments[0].get(), distanceOI);
    float sim = 1.f / (1.f + d);
    return new FloatWritable(sim);
}