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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations