Search in sources :

Example 1 with ServerDenseDoubleRow

use of com.tencent.angel.ps.impl.matrix.ServerDenseDoubleRow 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);
}
Also used : SplitEntry(com.tencent.angel.ml.GBDT.algo.tree.SplitEntry) ArrayList(java.util.ArrayList) GradStats(com.tencent.angel.ml.GBDT.algo.RegTree.GradStats) ServerRow(com.tencent.angel.ps.impl.matrix.ServerRow) ServerDenseDoubleRow(com.tencent.angel.ps.impl.matrix.ServerDenseDoubleRow)

Example 2 with ServerDenseDoubleRow

use of com.tencent.angel.ps.impl.matrix.ServerDenseDoubleRow in project angel by Tencent.

the class Random method doUpdate.

@Override
protected void doUpdate(ServerDenseDoubleRow[] rows, double[] value) {
    for (ServerDenseDoubleRow row : rows) {
        try {
            row.getLock().writeLock().lock();
            DoubleBuffer rowData = row.getData();
            java.util.Random rand = new java.util.Random(row.getRowId());
            for (int j = 0; j < row.size(); j++) {
                rowData.put(j, rand.nextDouble());
            }
        } finally {
            row.getLock().writeLock().unlock();
        }
    }
}
Also used : DoubleBuffer(java.nio.DoubleBuffer) ServerDenseDoubleRow(com.tencent.angel.ps.impl.matrix.ServerDenseDoubleRow)

Example 3 with ServerDenseDoubleRow

use of com.tencent.angel.ps.impl.matrix.ServerDenseDoubleRow in project angel by Tencent.

the class GBDTGradHistGetRowFunc method partitionGet.

@Override
public PartitionGetResult partitionGet(PartitionGetParam partParam) {
    HistAggrParam.HistPartitionAggrParam param = (HistAggrParam.HistPartitionAggrParam) partParam;
    LOG.info("For the gradient histogram of GBT, we use PS to find the optimal split");
    GBDTParam gbtparam = new GBDTParam();
    gbtparam.numSplit = param.getSplitNum();
    gbtparam.minChildWeight = param.getMinChildWeight();
    gbtparam.regAlpha = param.getRegAlpha();
    gbtparam.regLambda = param.getRegLambda();
    ServerDenseDoubleRow row = (ServerDenseDoubleRow) psContext.getMatrixStorageManager().getRow(param.getMatrixId(), param.getRowId(), param.getPartKey().getPartitionId());
    SplitEntry splitEntry = GradHistHelper.findSplitOfServerRow(row, gbtparam);
    int fid = splitEntry.getFid();
    int splitIndex = (int) splitEntry.getFvalue();
    double lossGain = splitEntry.getLossChg();
    GradStats leftGradStat = splitEntry.leftGradStat;
    GradStats rightGradStat = splitEntry.rightGradStat;
    double leftSumGrad = leftGradStat.sumGrad;
    double leftSumHess = leftGradStat.sumHess;
    double rightSumGrad = rightGradStat.sumGrad;
    double rightSumHess = rightGradStat.sumHess;
    LOG.info(String.format("split of matrix[%d] part[%d] row[%d]: fid[%d], split index[%d], loss gain[%f], " + "left sumGrad[%f], left sum hess[%f], right sumGrad[%f], right sum hess[%f]", param.getMatrixId(), param.getPartKey().getPartitionId(), param.getRowId(), fid, splitIndex, lossGain, leftSumGrad, leftSumHess, rightSumGrad, rightSumHess));
    int startFid = (int) row.getStartCol() / (2 * gbtparam.numSplit);
    // int sendStartCol = startFid * 7; // each split contains 7 doubles
    int sendStartCol = (int) row.getStartCol();
    int sendEndCol = sendStartCol + 7;
    ServerDenseDoubleRow sendRow = new ServerDenseDoubleRow(param.getRowId(), sendStartCol, sendEndCol);
    LOG.info(String.format("Create server row of split result: row id[%d], start col[%d], end col[%d]", param.getRowId(), sendStartCol, sendEndCol));
    sendRow.getData().put(0, fid);
    sendRow.getData().put(1, splitIndex);
    sendRow.getData().put(2, lossGain);
    sendRow.getData().put(3, leftSumGrad);
    sendRow.getData().put(4, leftSumHess);
    sendRow.getData().put(5, rightSumGrad);
    sendRow.getData().put(6, rightSumHess);
    return new PartitionGetRowResult(sendRow);
}
Also used : SplitEntry(com.tencent.angel.ml.GBDT.algo.tree.SplitEntry) GradStats(com.tencent.angel.ml.GBDT.algo.RegTree.GradStats) PartitionGetRowResult(com.tencent.angel.ml.matrix.psf.get.single.PartitionGetRowResult) ServerDenseDoubleRow(com.tencent.angel.ps.impl.matrix.ServerDenseDoubleRow) GBDTParam(com.tencent.angel.ml.param.GBDTParam)

Example 4 with ServerDenseDoubleRow

use of com.tencent.angel.ps.impl.matrix.ServerDenseDoubleRow in project angel by Tencent.

the class Diag method doUpdate.

@Override
protected void doUpdate(ServerDenseDoubleRow[] rows, double[] values) {
    for (ServerDenseDoubleRow row : rows) {
        int rowId = row.getRowId();
        if (rowId >= row.getStartCol() && rowId < row.getEndCol()) {
            try {
                row.getLock().writeLock().lock();
                DoubleBuffer rowData = row.getData();
                rowData.put(rowId - (int) row.getStartCol(), values[rowId]);
            } finally {
                row.getLock().writeLock().unlock();
            }
        }
    }
}
Also used : DoubleBuffer(java.nio.DoubleBuffer) ServerDenseDoubleRow(com.tencent.angel.ps.impl.matrix.ServerDenseDoubleRow)

Example 5 with ServerDenseDoubleRow

use of com.tencent.angel.ps.impl.matrix.ServerDenseDoubleRow in project angel by Tencent.

the class Eye method doUpdate.

@Override
protected void doUpdate(ServerDenseDoubleRow[] rows, double[] values) {
    for (ServerDenseDoubleRow row : rows) {
        int rowId = row.getRowId();
        if (rowId >= row.getStartCol() && rowId < row.getEndCol()) {
            try {
                row.getLock().writeLock().lock();
                DoubleBuffer rowData = row.getData();
                rowData.put(rowId - (int) row.getStartCol(), 1);
            } finally {
                row.getLock().writeLock().unlock();
            }
        }
    }
}
Also used : DoubleBuffer(java.nio.DoubleBuffer) ServerDenseDoubleRow(com.tencent.angel.ps.impl.matrix.ServerDenseDoubleRow)

Aggregations

ServerDenseDoubleRow (com.tencent.angel.ps.impl.matrix.ServerDenseDoubleRow)6 DoubleBuffer (java.nio.DoubleBuffer)4 GradStats (com.tencent.angel.ml.GBDT.algo.RegTree.GradStats)2 SplitEntry (com.tencent.angel.ml.GBDT.algo.tree.SplitEntry)2 PartitionGetRowResult (com.tencent.angel.ml.matrix.psf.get.single.PartitionGetRowResult)1 GBDTParam (com.tencent.angel.ml.param.GBDTParam)1 ServerRow (com.tencent.angel.ps.impl.matrix.ServerRow)1 ArrayList (java.util.ArrayList)1