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

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

Introduction

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

Prototype

public FloatWritable(float value) 

Source Link

Usage

From source file:hivemall.knn.similarity.Distance2SimilarityUDF.java

License:Apache License

@Override
public FloatWritable evaluate(DeferredObject[] arguments) throws HiveException {
    float d = PrimitiveObjectInspectorUtils.getFloat(arguments[0], distanceOI);
    float sim = 1.f / (1.f + d);
    return new FloatWritable(sim);
}

From source file:hivemall.knn.similarity.EuclidSimilarity.java

License:Apache License

@Override
public FloatWritable evaluate(DeferredObject[] arguments) throws HiveException {
    List<String> ftvec1 = HiveUtils.asStringList(arguments[0], arg0ListOI);
    List<String> ftvec2 = HiveUtils.asStringList(arguments[1], arg1ListOI);
    float d = (float) EuclidDistanceUDF.euclidDistance(ftvec1, ftvec2);
    float sim = 1.0f / (1.0f + d);
    return new FloatWritable(sim);
}

From source file:hivemall.knn.similarity.JaccardIndexUDF.java

License:Apache License

public FloatWritable evaluate(final List<String> a, final List<String> b) {
    if (a == null && b == null) {
        return new FloatWritable(1.f);
    } else if (a == null || b == null) {
        return new FloatWritable(0.f);
    }// w w w. ja  v  a  2  s  .c  om
    final int asize = a.size();
    final int bsize = b.size();
    if (asize == 0 && bsize == 0) {
        return new FloatWritable(1.f);
    } else if (asize == 0 || bsize == 0) {
        return new FloatWritable(0.f);
    }

    union.addAll(a);
    union.addAll(b);
    float unionSize = union.size();
    union.clear();

    intersect.addAll(a);
    intersect.retainAll(b);
    float intersectSize = intersect.size();
    intersect.clear();

    return new FloatWritable(intersectSize / unionSize);
}

From source file:hivemall.mf.BPRMFPredictionUDF.java

License:Apache License

public FloatWritable evaluate(List<Float> Pu, List<Float> Qi, double Bi) throws HiveException {
    if (Pu == null && Qi == null) {
        return new FloatWritable(0.f);
    }/* w  ww  . j  a  va  2 s . c o m*/
    if (Pu == null) {
        return new FloatWritable((float) Bi);
    } else if (Qi == null) {
        return new FloatWritable(0.f);
    }

    final int PuSize = Pu.size();
    final int QiSize = Qi.size();
    // workaround for TD        
    if (PuSize == 0) {
        if (QiSize == 0) {
            return new FloatWritable(0.f);
        } else {
            return new FloatWritable((float) Bi);
        }
    } else if (QiSize == 0) {
        return new FloatWritable(0.f);
    }

    if (QiSize != PuSize) {
        throw new HiveException("|Pu| " + PuSize + " was not equal to |Qi| " + QiSize);
    }

    float ret = (float) Bi;
    for (int k = 0; k < PuSize; k++) {
        ret += Pu.get(k) * Qi.get(k);
    }
    return new FloatWritable(ret);
}

From source file:hivemall.mf.MFPredictionUDF.java

License:Open Source License

public FloatWritable evaluate(List<Float> Pu, List<Float> Qi) throws HiveException {
    if (Pu == null || Qi == null) {
        return null; //throw new HiveException("Pu should not be NULL");
    }//from   w w  w  .ja  va2s  . c o m
    final int factor = Pu.size();
    if (Qi.size() != factor) {
        throw new HiveException("|Pu| " + factor + " was not equal to |Qi| " + Qi.size());
    }
    float ret = 0.f;
    for (int k = 0; k < factor; k++) {
        ret += Pu.get(k) * Qi.get(k);
    }
    return new FloatWritable(ret);
}

From source file:hivemall.mf.MFPredictionUDF.java

License:Open Source License

public FloatWritable evaluate(List<Float> Pu, List<Float> Qi, double Bu, double Bi, double mu)
        throws HiveException {
    if (Pu == null && Qi == null) {
        return null; //throw new HiveException("Both Pu and Qi was NULL");
    }/*from w ww  .j a v  a 2  s .  c o  m*/

    if (Pu == null) {// TODO REVIEWME
        float ret = (float) (mu + Bi);
        return new FloatWritable(ret);
    } else if (Qi == null) {
        float ret = (float) (mu + Bu);
        return new FloatWritable(ret);
    }

    final int factor = Pu.size();
    if (Qi.size() != factor) {
        throw new HiveException("|Pu| " + factor + " was not equal to |Qi| " + Qi.size());
    }
    float ret = (float) (mu + Bu + Bi);
    for (int k = 0; k < factor; k++) {
        ret += Pu.get(k) * Qi.get(k);
    }
    return new FloatWritable(ret);
}

From source file:hivemall.smile.classification.GradientTreeBoostingClassifierUDTF.java

License:Apache License

/**
 * @param m m-th boosting iteration//from ww w .j  a va 2 s  .c  om
 */
private void forward(final int m, final double intercept, final double shrinkage, final float oobErrorRate,
        @Nonnull final RegressionTree... trees) throws HiveException {
    Text[] models = getModel(trees, _outputType);

    double[] importance = new double[_attributes.length];
    for (RegressionTree tree : trees) {
        double[] imp = tree.importance();
        for (int i = 0; i < imp.length; i++) {
            importance[i] += imp[i];
        }
    }

    Object[] forwardObjs = new Object[7];
    forwardObjs[0] = new IntWritable(m);
    forwardObjs[1] = new IntWritable(_outputType.getId());
    forwardObjs[2] = models;
    forwardObjs[3] = new DoubleWritable(intercept);
    forwardObjs[4] = new DoubleWritable(shrinkage);
    forwardObjs[5] = WritableUtils.toWritableList(importance);
    forwardObjs[6] = new FloatWritable(oobErrorRate);

    forward(forwardObjs);

    reportProgress(_progressReporter);
    incrCounter(_iterationCounter, 1);

    logger.info("Forwarded the output of " + m + "-th Boosting iteration out of " + _numTrees);
}

From source file:hivemall.tools.ConvertLabelUDF.java

License:Open Source License

public FloatWritable evaluate(int label) throws UDFArgumentException {
    if (label == -1 || label == 0) {
        return new FloatWritable(0.f);
    } else if (label == 1) {
        return new FloatWritable(1.f);
    } else {/*w w w  . ja va  2  s. co m*/
        throw new UDFArgumentException("-1 or 1 is expected. Unexpected label: " + label);
    }
}

From source file:hivemall.tools.math.SigmoidGenericUDF.java

License:Apache License

@Nullable
@Override//w ww .  ja v  a2s  .com
public FloatWritable evaluate(@Nonnull DeferredObject[] arguments) throws HiveException {
    assert (arguments.length == 1) : "sigmoid takes 1 argument: " + arguments.length;
    DeferredObject arg0 = arguments[0];
    assert (arg0 != null);
    Object obj0 = arg0.get();
    if (obj0 == null) {
        return null;
    }
    double x = PrimitiveObjectInspectorUtils.getDouble(obj0, argOI);
    float v = (float) MathUtils.sigmoid(x);
    return new FloatWritable(v);
}

From source file:hivemall.utils.hadoop.HiveUtils.java

License:Open Source License

@Nonnull
public static FloatWritable[] newFloatArray(final int size, final float defaultVal) {
    final FloatWritable[] array = new FloatWritable[size];
    for (int i = 0; i < size; i++) {
        array[i] = new FloatWritable(defaultVal);
    }/*from  w  w  w  .  j  av a 2s.  c  o m*/
    return array;
}