Search in sources :

Example 1 with PartitionGetRowResult

use of com.tencent.angel.ml.matrix.psf.get.getrow.PartitionGetRowResult 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 GBDT, 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();
    ServerIntDoubleRow row = (ServerIntDoubleRow) 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);
    // each split contains 7 doubles
    int sendStartCol = startFid * 7;
    // int sendStartCol = (int) row.getStartCol();
    int sendEndCol = sendStartCol + 7;
    ServerIntDoubleRow sendRow = new ServerIntDoubleRow(param.getRowId(), RowType.T_DOUBLE_DENSE, sendStartCol, sendEndCol, sendEndCol - sendStartCol, RouterType.RANGE);
    LOG.info(String.format("Create server row of split result: row id[%d], start col[%d], end col[%d]", param.getRowId(), sendStartCol, sendEndCol));
    sendRow.set(0 + sendStartCol, fid);
    sendRow.set(1 + sendStartCol, splitIndex);
    sendRow.set(2 + sendStartCol, lossGain);
    sendRow.set(3 + sendStartCol, leftSumGrad);
    sendRow.set(4 + sendStartCol, leftSumHess);
    sendRow.set(5 + sendStartCol, rightSumGrad);
    sendRow.set(6 + sendStartCol, rightSumHess);
    return new PartitionGetRowResult(sendRow);
}
Also used : ServerIntDoubleRow(com.tencent.angel.ps.storage.vector.ServerIntDoubleRow) 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.getrow.PartitionGetRowResult) GBDTParam(com.tencent.angel.ml.GBDT.param.GBDTParam)

Aggregations

GradStats (com.tencent.angel.ml.GBDT.algo.RegTree.GradStats)1 SplitEntry (com.tencent.angel.ml.GBDT.algo.tree.SplitEntry)1 GBDTParam (com.tencent.angel.ml.GBDT.param.GBDTParam)1 PartitionGetRowResult (com.tencent.angel.ml.matrix.psf.get.getrow.PartitionGetRowResult)1 ServerIntDoubleRow (com.tencent.angel.ps.storage.vector.ServerIntDoubleRow)1