Search in sources :

Example 1 with UnionEle

use of com.tencent.angel.ml.math2.utils.UnionEle in project angel by Tencent.

the class CompReduceExecutor method apply.

private static UnionEle apply(CompIntFloatVector v, ReduceOP op, int start, int end) {
    UnionEle res = new UnionEle();
    IntFloatVector[] parts = v.getPartitions();
    switch(op) {
        case Sum:
            for (int i = start; i <= end; i++) {
                res.setDouble1(res.getDouble1() + parts[i].sum());
            }
            break;
        case Avg:
            for (int i = start; i <= end; i++) {
                res.setDouble1(res.getDouble1() + parts[i].sum());
                res.setLong1(res.getLong1() + parts[i].getDim());
            }
            break;
        case Std:
            for (int i = start; i <= end; i++) {
                res.setDouble1(res.getDouble1() + parts[i].sum());
                double norm = parts[i].norm();
                res.setDouble2(res.getDouble2() + norm * norm);
                res.setLong1(res.getLong1() + parts[i].getDim());
            }
            break;
        case Norm:
            for (int i = start; i <= end; i++) {
                double norm = parts[i].norm();
                res.setDouble2(res.getDouble2() + norm * norm);
            }
            break;
        case Min:
            res.setDouble1(Double.MAX_VALUE);
            for (int i = start; i <= end; i++) {
                res.setDouble1(Math.min(res.getDouble1(), parts[i].min()));
            }
            break;
        case Max:
            res.setDouble1(Double.MIN_VALUE);
            for (int i = start; i <= end; i++) {
                res.setDouble1(Math.max(res.getDouble1(), parts[i].max()));
            }
            break;
        case Size:
            for (int i = start; i <= end; i++) {
                res.setLong1(res.getLong1() + parts[i].size());
            }
            break;
        case Numzeros:
            for (int i = start; i <= end; i++) {
                res.setLong1(res.getLong1() + parts[i].numZeros());
            }
            break;
    }
    return res;
}
Also used : UnionEle(com.tencent.angel.ml.math2.utils.UnionEle) CompIntFloatVector(com.tencent.angel.ml.math2.vector.CompIntFloatVector) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector)

Example 2 with UnionEle

use of com.tencent.angel.ml.math2.utils.UnionEle in project angel by Tencent.

the class CompReduceExecutor method apply.

private static UnionEle apply(CompLongLongVector v, ReduceOP op, int start, int end) {
    UnionEle res = new UnionEle();
    LongLongVector[] parts = v.getPartitions();
    switch(op) {
        case Sum:
            for (int i = start; i <= end; i++) {
                res.setDouble1(res.getDouble1() + parts[i].sum());
            }
            break;
        case Avg:
            for (int i = start; i <= end; i++) {
                res.setDouble1(res.getDouble1() + parts[i].sum());
                res.setLong1(res.getLong1() + parts[i].getDim());
            }
            break;
        case Std:
            for (int i = start; i <= end; i++) {
                res.setDouble1(res.getDouble1() + parts[i].sum());
                double norm = parts[i].norm();
                res.setDouble2(res.getDouble2() + norm * norm);
                res.setLong1(res.getLong1() + parts[i].getDim());
            }
            break;
        case Norm:
            for (int i = start; i <= end; i++) {
                double norm = parts[i].norm();
                res.setDouble2(res.getDouble2() + norm * norm);
            }
            break;
        case Min:
            res.setDouble1(Double.MAX_VALUE);
            for (int i = start; i <= end; i++) {
                res.setDouble1(Math.min(res.getDouble1(), parts[i].min()));
            }
            break;
        case Max:
            res.setDouble1(Double.MIN_VALUE);
            for (int i = start; i <= end; i++) {
                res.setDouble1(Math.max(res.getDouble1(), parts[i].max()));
            }
            break;
        case Size:
            for (int i = start; i <= end; i++) {
                res.setLong1(res.getLong1() + parts[i].size());
            }
            break;
        case Numzeros:
            for (int i = start; i <= end; i++) {
                res.setLong1(res.getLong1() + parts[i].numZeros());
            }
            break;
    }
    return res;
}
Also used : UnionEle(com.tencent.angel.ml.math2.utils.UnionEle) LongLongVector(com.tencent.angel.ml.math2.vector.LongLongVector) CompLongLongVector(com.tencent.angel.ml.math2.vector.CompLongLongVector)

Example 3 with UnionEle

use of com.tencent.angel.ml.math2.utils.UnionEle in project angel by Tencent.

the class CompReduceExecutor method merge.

private static UnionEle merge(UnionEle left, UnionEle right, ReduceOP op) {
    UnionEle res = new UnionEle();
    switch(op) {
        case Min:
            res.setDouble1(Math.min(left.getDouble1(), right.getDouble1()));
            res.setDouble2(Math.min(left.getDouble2(), right.getDouble2()));
            res.setFloat1(Math.min(left.getFloat1(), right.getFloat1()));
            res.setFloat2(Math.min(left.getFloat2(), right.getFloat2()));
            res.setLong1(Math.min(left.getLong1(), right.getLong1()));
            res.setLong2(Math.min(left.getLong2(), right.getLong2()));
            res.setInt1(Math.min(left.getInt1(), right.getInt1()));
            res.setInt2(Math.min(left.getInt2(), right.getInt2()));
            break;
        case Max:
            res.setDouble1(Math.max(left.getDouble1(), right.getDouble1()));
            res.setDouble2(Math.max(left.getDouble2(), right.getDouble2()));
            res.setFloat1(Math.max(left.getFloat1(), right.getFloat1()));
            res.setFloat2(Math.max(left.getFloat2(), right.getFloat2()));
            res.setLong1(Math.max(left.getLong1(), right.getLong1()));
            res.setLong2(Math.max(left.getLong2(), right.getLong2()));
            res.setInt1(Math.max(left.getInt1(), right.getInt1()));
            res.setInt2(Math.max(left.getInt2(), right.getInt2()));
            break;
        default:
            res.setDouble1(left.getDouble1() + right.getDouble1());
            res.setDouble2(left.getDouble2() + right.getDouble2());
            res.setFloat1(left.getFloat1() + right.getFloat1());
            res.setFloat2(left.getFloat2() + right.getFloat2());
            res.setLong1(left.getLong1() + right.getLong1());
            res.setLong2(left.getLong2() + right.getLong2());
            res.setInt1(left.getInt1() + right.getInt1());
            res.setInt2(left.getInt2() + right.getInt2());
    }
    res.setBool(left.isBool() && right.isBool());
    return res;
}
Also used : UnionEle(com.tencent.angel.ml.math2.utils.UnionEle)

Example 4 with UnionEle

use of com.tencent.angel.ml.math2.utils.UnionEle in project angel by Tencent.

the class CompReduceExecutor method apply.

private static UnionEle apply(CompLongIntVector v, ReduceOP op, int start, int end) {
    UnionEle res = new UnionEle();
    LongIntVector[] parts = v.getPartitions();
    switch(op) {
        case Sum:
            for (int i = start; i <= end; i++) {
                res.setDouble1(res.getDouble1() + parts[i].sum());
            }
            break;
        case Avg:
            for (int i = start; i <= end; i++) {
                res.setDouble1(res.getDouble1() + parts[i].sum());
                res.setLong1(res.getLong1() + parts[i].getDim());
            }
            break;
        case Std:
            for (int i = start; i <= end; i++) {
                res.setDouble1(res.getDouble1() + parts[i].sum());
                double norm = parts[i].norm();
                res.setDouble2(res.getDouble2() + norm * norm);
                res.setLong1(res.getLong1() + parts[i].getDim());
            }
            break;
        case Norm:
            for (int i = start; i <= end; i++) {
                double norm = parts[i].norm();
                res.setDouble2(res.getDouble2() + norm * norm);
            }
            break;
        case Min:
            res.setDouble1(Double.MAX_VALUE);
            for (int i = start; i <= end; i++) {
                res.setDouble1(Math.min(res.getDouble1(), parts[i].min()));
            }
            break;
        case Max:
            res.setDouble1(Double.MIN_VALUE);
            for (int i = start; i <= end; i++) {
                res.setDouble1(Math.max(res.getDouble1(), parts[i].max()));
            }
            break;
        case Size:
            for (int i = start; i <= end; i++) {
                res.setLong1(res.getLong1() + parts[i].size());
            }
            break;
        case Numzeros:
            for (int i = start; i <= end; i++) {
                res.setLong1(res.getLong1() + parts[i].numZeros());
            }
            break;
    }
    return res;
}
Also used : UnionEle(com.tencent.angel.ml.math2.utils.UnionEle) CompLongIntVector(com.tencent.angel.ml.math2.vector.CompLongIntVector) LongIntVector(com.tencent.angel.ml.math2.vector.LongIntVector)

Example 5 with UnionEle

use of com.tencent.angel.ml.math2.utils.UnionEle in project angel by Tencent.

the class CompReduceExecutor method apply.

public static double apply(ComponentVector vector, ReduceOP op) {
    CompRedExe task = new CompRedExe(vector, op, 0, vector.getNumPartitions() - 1);
    Future<UnionEle> futRes = pool.submit(task);
    try {
        UnionEle tmpRes = futRes.get();
        switch(op) {
            case Avg:
                return tmpRes.getDouble1() / tmpRes.getLong1();
            case Std:
                double avg1 = tmpRes.getDouble1() / tmpRes.getLong1();
                double avg2 = tmpRes.getDouble2() / tmpRes.getLong1();
                return Math.sqrt(avg2 - avg1 * avg1);
            case Norm:
                return Math.sqrt(tmpRes.getDouble2());
            default:
                return tmpRes.getDouble1() + tmpRes.getLong1();
        }
    } catch (InterruptedException | ExecutionException e) {
        e.printStackTrace();
    }
    return Double.NaN;
}
Also used : UnionEle(com.tencent.angel.ml.math2.utils.UnionEle) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

UnionEle (com.tencent.angel.ml.math2.utils.UnionEle)10 CompIntDoubleVector (com.tencent.angel.ml.math2.vector.CompIntDoubleVector)1 CompIntFloatVector (com.tencent.angel.ml.math2.vector.CompIntFloatVector)1 CompIntIntVector (com.tencent.angel.ml.math2.vector.CompIntIntVector)1 CompIntLongVector (com.tencent.angel.ml.math2.vector.CompIntLongVector)1 CompLongDoubleVector (com.tencent.angel.ml.math2.vector.CompLongDoubleVector)1 CompLongFloatVector (com.tencent.angel.ml.math2.vector.CompLongFloatVector)1 CompLongIntVector (com.tencent.angel.ml.math2.vector.CompLongIntVector)1 CompLongLongVector (com.tencent.angel.ml.math2.vector.CompLongLongVector)1 IntDoubleVector (com.tencent.angel.ml.math2.vector.IntDoubleVector)1 IntFloatVector (com.tencent.angel.ml.math2.vector.IntFloatVector)1 IntIntVector (com.tencent.angel.ml.math2.vector.IntIntVector)1 IntLongVector (com.tencent.angel.ml.math2.vector.IntLongVector)1 LongDoubleVector (com.tencent.angel.ml.math2.vector.LongDoubleVector)1 LongFloatVector (com.tencent.angel.ml.math2.vector.LongFloatVector)1 LongIntVector (com.tencent.angel.ml.math2.vector.LongIntVector)1 LongLongVector (com.tencent.angel.ml.math2.vector.LongLongVector)1 ExecutionException (java.util.concurrent.ExecutionException)1