Search in sources :

Example 1 with ServerRow

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);
}
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 ServerRow

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();
}
Also used : ServerDenseIntRow(com.tencent.angel.ps.impl.matrix.ServerDenseIntRow) IntBuffer(java.nio.IntBuffer) PartitionKey(com.tencent.angel.PartitionKey) ServerRow(com.tencent.angel.ps.impl.matrix.ServerRow)

Example 3 with ServerRow

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;
}
Also used : ServerRow(com.tencent.angel.ps.impl.matrix.ServerRow) ServerPartition(com.tencent.angel.ps.impl.matrix.ServerPartition)

Example 4 with ServerRow

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);
}
Also used : ServerRow(com.tencent.angel.ps.impl.matrix.ServerRow) ServerPartition(com.tencent.angel.ps.impl.matrix.ServerPartition)

Example 5 with ServerRow

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);
        }
    }
}
Also used : ServerRow(com.tencent.angel.ps.impl.matrix.ServerRow) ServerPartition(com.tencent.angel.ps.impl.matrix.ServerPartition)

Aggregations

ServerRow (com.tencent.angel.ps.impl.matrix.ServerRow)16 ServerPartition (com.tencent.angel.ps.impl.matrix.ServerPartition)9 PartitionKey (com.tencent.angel.PartitionKey)4 ArrayList (java.util.ArrayList)3 GradStats (com.tencent.angel.ml.GBDT.algo.RegTree.GradStats)1 SplitEntry (com.tencent.angel.ml.GBDT.algo.tree.SplitEntry)1 TVector (com.tencent.angel.ml.math.TVector)1 MatrixMeta (com.tencent.angel.ml.matrix.MatrixMeta)1 ScalarPartitionAggrResult (com.tencent.angel.ml.matrix.psf.aggr.enhance.ScalarPartitionAggrResult)1 PartitionGetRowsParam (com.tencent.angel.ml.matrix.psf.get.multi.PartitionGetRowsParam)1 ParameterServerId (com.tencent.angel.ps.ParameterServerId)1 MatrixStorageManager (com.tencent.angel.ps.impl.MatrixStorageManager)1 ServerDenseDoubleRow (com.tencent.angel.ps.impl.matrix.ServerDenseDoubleRow)1 ServerDenseIntRow (com.tencent.angel.ps.impl.matrix.ServerDenseIntRow)1 MatricesCache (com.tencent.angel.psagent.matrix.cache.MatricesCache)1 MatrixStorage (com.tencent.angel.psagent.matrix.storage.MatrixStorage)1 MatrixTransportClient (com.tencent.angel.psagent.matrix.transport.MatrixTransportClient)1 IntBuffer (java.nio.IntBuffer)1 Map (java.util.Map)1