use of com.tencent.angel.ps.impl.matrix.ServerRow in project angel by Tencent.
the class GBDTGradHistGetRowFunc method merge.
@Override
public GetResult merge(List<PartitionGetResult> partResults) {
int size = partResults.size();
List<ServerRow> rowSplits = new ArrayList<ServerRow>(size);
for (int i = 0; i < size; i++) {
rowSplits.add(((PartitionGetRowResult) partResults.get(i)).getRowSplit());
}
SplitEntry splitEntry = new SplitEntry();
for (int i = 0; i < size; i++) {
ServerDenseDoubleRow row = (ServerDenseDoubleRow) ((PartitionGetRowResult) partResults.get(i)).getRowSplit();
int fid = (int) row.getData().get(0);
if (fid != -1) {
int splitIndex = (int) row.getData().get(1);
float lossGain = (float) row.getData().get(2);
float leftSumGrad = (float) row.getData().get(3);
float leftSumHess = (float) row.getData().get(4);
float rightSumGrad = (float) row.getData().get(5);
float rightSumHess = (float) row.getData().get(6);
LOG.debug(String.format("psFunc: the best split after looping a split: fid[%d], fvalue[%d], loss gain[%f]" + ", leftSumGrad[%f], leftSumHess[%f], rightSumGrad[%f], rightSumHess[%f]", fid, splitIndex, lossGain, leftSumGrad, leftSumHess, rightSumGrad, rightSumHess));
GradStats curLeftGradStat = new GradStats(leftSumGrad, leftSumHess);
GradStats curRightGradStat = new GradStats(rightSumGrad, rightSumHess);
SplitEntry curSplitEntry = new SplitEntry(fid, splitIndex, lossGain);
curSplitEntry.leftGradStat = curLeftGradStat;
curSplitEntry.rightGradStat = curRightGradStat;
splitEntry.update(curSplitEntry);
}
}
return new GBDTGradHistGetRowResult(ResponseType.SUCCESS, splitEntry);
}
use of com.tencent.angel.ps.impl.matrix.ServerRow in project angel by Tencent.
the class UpdatePartFunc method partitionUpdate.
@Override
public void partitionUpdate(PartitionUpdateParam partParam) {
CSRPartUpdateParam param = (CSRPartUpdateParam) partParam;
PartitionKey pkey = partParam.getPartKey();
pkey = psContext.getMatrixMetaManager().getMatrixMeta(pkey.getMatrixId()).getPartitionMeta(pkey.getPartitionId()).getPartitionKey();
while (param.buf.isReadable()) {
int row = param.buf.readInt();
int len = param.buf.readShort();
ServerRow serverRow = psContext.getMatrixStorageManager().getRow(pkey, row);
serverRow.getLock().writeLock().lock();
ServerDenseIntRow denseIntRow = (ServerDenseIntRow) serverRow;
IntBuffer buffer = denseIntRow.getData();
for (int i = 0; i < len; i++) {
short key = param.buf.readShort();
int val = param.buf.readInt();
buffer.put(key, buffer.get(key) + val);
}
serverRow.getLock().writeLock().unlock();
}
param.buf.release();
}
use of com.tencent.angel.ps.impl.matrix.ServerRow in project angel by Tencent.
the class ArrayAggrFunc method partitionGet.
@Override
public PartitionGetResult partitionGet(PartitionGetParam partKey) {
ServerPartition part = psContext.getMatrixStorageManager().getPart(partKey.getMatrixId(), partKey.getPartKey().getPartitionId());
if (part != null) {
int rowId = ((ArrayAggrParam.ArrayPartitionAggrParam) partKey).getRowId();
if (Utils.withinPart(part.getPartitionKey(), new int[] { rowId })) {
ServerRow row = part.getRow(rowId);
long[] colsParam = ((ArrayAggrParam.ArrayPartitionAggrParam) partKey).getCols();
List<Map.Entry<Long, Double>> result = processRow(row, colsParam);
long[] cols = new long[result.size()];
double[] values = new double[result.size()];
for (int i = 0; i < result.size(); i++) {
cols[i] = result.get(i).getKey();
values[i] = result.get(i).getValue();
}
return new ArrayPartitionAggrResult(cols, values);
}
}
return null;
}
use of com.tencent.angel.ps.impl.matrix.ServerRow in project angel by Tencent.
the class MultiAggrFunc method partitionGet.
@Override
public PartitionGetResult partitionGet(PartitionGetParam partKey) {
ServerPartition part = psContext.getMatrixStorageManager().getPart(partKey.getMatrixId(), partKey.getPartKey().getPartitionId());
int[] rowIds = ((MultiAggrParam.MultiPartitionAggrParam) partKey).getRowIds();
double[] result = null;
if (Utils.withinPart(partKey.getPartKey(), rowIds)) {
if (part != null) {
ServerRow[] rows = new ServerRow[rowIds.length];
for (int i = 0; i < rowIds.length; i++) {
rows[i] = part.getRow(rowIds[i]);
}
result = processRows(rows);
}
}
return new ArrayPartitionAggrResult(result);
}
use of com.tencent.angel.ps.impl.matrix.ServerRow in project angel by Tencent.
the class MUpdateFunc method partitionUpdate.
@Override
public void partitionUpdate(PartitionUpdateParam partParam) {
ServerPartition part = psContext.getMatrixStorageManager().getPart(partParam.getMatrixId(), partParam.getPartKey().getPartitionId());
if (part != null) {
MUpdateParam.MPartitionUpdateParam m = (MUpdateParam.MPartitionUpdateParam) partParam;
int[] rowIds = m.getRowIds();
if (Utils.withinPart(partParam.getPartKey(), rowIds)) {
ServerRow[] rows = new ServerRow[rowIds.length];
for (int i = 0; i < rowIds.length; i++) {
rows[i] = part.getRow(rowIds[i]);
}
update(rows);
}
}
}
Aggregations