Example usage for org.apache.hadoop.io FloatWritable get

List of usage examples for org.apache.hadoop.io FloatWritable get

Introduction

In this page you can find the example usage for org.apache.hadoop.io FloatWritable get.

Prototype

public float get() 

Source Link

Document

Return the value of this FloatWritable.

Usage

From source file:edu.ucsb.cs.hybrid.mappers.IDMapper.java

License:Apache License

@Override
public void map(DocDocWritable key, FloatWritable value, OutputCollector<Text, Text> output, Reporter reporter)
        throws IOException {
    StringBuilder bd = new StringBuilder(md5ToIdMap.get(String.valueOf(key.getDoc1())) + " "
            + md5ToIdMap.get(String.valueOf(key.getDoc2())));
    output.collect(new Text(bd.toString()), new Text(value.get() + ""));
}

From source file:edu.ucsb.cs.invertedindex.reducers.InvertedSimReducer.java

License:Apache License

public void reduce(DocDocWritable key, Iterator<FloatWritable> values,
        OutputCollector<DocDocWritable, FloatWritable> output, Reporter reporter) throws IOException {
    float sum = 0;
    while (values.hasNext()) {
        FloatWritable s = values.next();
        sum += s.get();
        if (sum > 0.9) {
            docdoc.doc1 = key.doc1;//  ww  w.j  a v a2  s.  c om
            docdoc.doc2 = key.doc2;
            outsum.set(sum);
            output.collect(docdoc, outsum);
        }
    }
}

From source file:hivemall.ftvec.conv.ToSparseFeaturesUDF.java

License:Apache License

@Nullable
public List<String> evaluate(@Nullable final List<FloatWritable> features, @Nullable String biasName) {
    if (features == null) {
        return null;
    }/* w w w . j ava2s .c o  m*/
    final int size = features.size();
    if (size == 0) {
        return Collections.emptyList();
    }

    final StringBuilder buf = new StringBuilder(64);
    final ArrayList<String> list = new ArrayList<String>(size);
    for (int i = 0; i < size; i++) {
        final FloatWritable o = features.get(i);
        if (o != null) {
            final String s;
            final float v = o.get();
            if (biasName != null) {
                s = buf.append(biasName).append(':').append(v).toString();
            } else {
                s = buf.append(i).append(':').append(v).toString();
            }
            list.add(s);
            StringUtils.clear(buf);
        }
    }
    return list;
}

From source file:hivemall.regression.LogressIterUDTF.java

License:Open Source License

@Override
public void process(Object[] args) throws HiveException {
    @SuppressWarnings("unchecked")
    final Map<Object, FloatWritable> featuresWithWeight = (Map<Object, FloatWritable>) featuresWithWeightOI
            .getMap(args[0]);/*w  w w.  ja v  a  2s .co m*/
    float target = targetOI.get(args[1]);
    checkTargetValue(target);

    final ObjectInspector featureInspector = featuresWithWeightOI.getMapKeyObjectInspector();
    for (Map.Entry<Object, FloatWritable> e : featuresWithWeight.entrySet()) {
        FloatWritable weight = e.getValue();
        if (weight == null) {
            continue;
        }
        float v = weight.get();
        if (v == 0.f) {
            continue; // could be skipped
        }

        final Object feature;
        Object k = e.getKey();
        if (parseFeature) {
            FeatureValue fv = FeatureValue.parse(k);
            feature = fv.getFeature();
        } else {
            feature = ObjectInspectorUtils.copyToStandardObject(k, featureInspector);
        }

        if (!model.contains(feature)) {
            model.set(feature, new WeightValue(v));
        }
    }

    Set<Object> features = featuresWithWeight.keySet();
    train(features, target);
    count++;
}

From source file:hivemall.tools.map.MapGetSumUDF.java

License:Open Source License

public DoubleWritable evaluate(Map<IntWritable, FloatWritable> map, List<IntWritable> keys) {
    double sum = 0d;
    for (IntWritable k : keys) {
        FloatWritable v = map.get(k);
        if (v != null) {
            sum += (double) v.get();
        }/*w  ww.j  a v a 2 s  . c o  m*/
    }
    return val(sum);
}

From source file:io.apigee.lembos.mapreduce.converters.input.FloatWritableConverter.java

License:Apache License

/**
 * Takes in a {@link FloatWritable} and returns a {@link Float}.
 *
 * @param scope the JavaScript scope/*from   w  w w.  j  a  v a  2  s. com*/
 * @param writable the value to convert
 *
 * @return the {@link Float} equivalent
 */
@Override
public Object toJavaScript(final Scriptable scope, final FloatWritable writable) {
    return writable.get();
}

From source file:it.crs4.pydoop.mapreduce.pipes.PipeApplicationRunnableStub.java

License:Apache License

public void binaryProtocolStub() {
    try {/*from w  ww . ja  v  a  2 s  .c  o  m*/

        initSoket();
        System.out.println("start OK");

        // RUN_MAP.code
        // should be 3

        int answer = WritableUtils.readVInt(dataInput);
        System.out.println("RunMap:" + answer);
        FileSplit split = new FileSplit();
        readObject(split, dataInput);

        WritableUtils.readVInt(dataInput);
        WritableUtils.readVInt(dataInput);
        // end runMap
        // get InputTypes
        WritableUtils.readVInt(dataInput);
        String inText = Text.readString(dataInput);
        System.out.println("Key class:" + inText);
        inText = Text.readString(dataInput);
        System.out.println("Value class:" + inText);

        @SuppressWarnings("unused")
        int inCode = 0;

        // read all data from sender and write to output
        while ((inCode = WritableUtils.readVInt(dataInput)) == 4) {
            FloatWritable key = new FloatWritable();
            NullWritable value = NullWritable.get();
            readObject(key, dataInput);
            System.out.println("value:" + key.get());
            readObject(value, dataInput);
        }

        WritableUtils.writeVInt(dataOut, 54);

        dataOut.flush();
        dataOut.close();

    } catch (Exception x) {
        x.printStackTrace();
    } finally {
        closeSoket();
    }

}

From source file:mapreducemaxstock.StockPriceReducer.java

public void reduce(Text key, Iterable<FloatWritable> values, Context context)
        throws IOException, InterruptedException {
    float maxClosePrice = Float.MIN_VALUE;

    for (FloatWritable value : values) {
        maxClosePrice = Math.max(maxClosePrice, value.get());
    }/*w  ww .  j a v a 2s  . co m*/

    context.write(key, new FloatWritable(maxClosePrice));
}

From source file:org.apache.giraph.aggregators.FloatAverageAggregator.java

License:Apache License

@Override
public void aggregate(FloatWritable value) {
    sum += value.get();
    count++;
}

From source file:org.apache.giraph.aggregators.FloatMaxAggregator.java

License:Apache License

@Override
public void aggregate(FloatWritable value) {
    getAggregatedValue().set(Math.max(getAggregatedValue().get(), value.get()));
}