Search in sources :

Example 16 with ServerRow

use of com.tencent.angel.ps.storage.vector.ServerRow in project angel by Tencent.

the class Min method partitionUpdate.

@Override
public void partitionUpdate(PartitionUpdateParam partParam) {
    PartIncrementRowsParam param = (PartIncrementRowsParam) partParam;
    List<RowUpdateSplit> updates = param.getUpdates();
    for (RowUpdateSplit update : updates) {
        ServerRow row = psContext.getMatrixStorageManager().getRow(param.getPartKey(), update.getRowId());
        row.startWrite();
        try {
            Vector vector = getVector(param.getMatrixId(), update.getRowId(), param.getPartKey());
            Ufuncs.imin(vector, update.getVector());
        } finally {
            row.endWrite();
        }
    }
}
Also used : PartIncrementRowsParam(com.tencent.angel.ml.matrix.psf.update.update.PartIncrementRowsParam) RowUpdateSplit(com.tencent.angel.psagent.matrix.oplog.cache.RowUpdateSplit) ServerRow(com.tencent.angel.ps.storage.vector.ServerRow) Vector(com.tencent.angel.ml.math2.vector.Vector)

Example 17 with ServerRow

use of com.tencent.angel.ps.storage.vector.ServerRow in project angel by Tencent.

the class Max method partitionUpdate.

@Override
public void partitionUpdate(PartitionUpdateParam partParam) {
    PartIncrementRowsParam param = (PartIncrementRowsParam) partParam;
    List<RowUpdateSplit> updates = param.getUpdates();
    for (RowUpdateSplit update : updates) {
        ServerRow row = psContext.getMatrixStorageManager().getRow(param.getPartKey(), update.getRowId());
        row.startWrite();
        try {
            Vector vector = getVector(param.getMatrixId(), update.getRowId(), param.getPartKey());
            Ufuncs.imax(vector, update.getVector());
        } finally {
            row.endWrite();
        }
    }
}
Also used : PartIncrementRowsParam(com.tencent.angel.ml.matrix.psf.update.update.PartIncrementRowsParam) RowUpdateSplit(com.tencent.angel.psagent.matrix.oplog.cache.RowUpdateSplit) ServerRow(com.tencent.angel.ps.storage.vector.ServerRow) Vector(com.tencent.angel.ml.math2.vector.Vector)

Example 18 with ServerRow

use of com.tencent.angel.ps.storage.vector.ServerRow in project angel by Tencent.

the class Sub method partitionUpdate.

@Override
public void partitionUpdate(PartitionUpdateParam partParam) {
    PartIncrementRowsParam param = (PartIncrementRowsParam) partParam;
    List<RowUpdateSplit> updates = param.getUpdates();
    for (RowUpdateSplit update : updates) {
        ServerRow row = psContext.getMatrixStorageManager().getRow(param.getPartKey(), update.getRowId());
        row.startWrite();
        try {
            Vector vector = getVector(param.getMatrixId(), update.getRowId(), param.getPartKey());
            vector.isub(update.getVector());
        } finally {
            row.endWrite();
        }
    }
}
Also used : PartIncrementRowsParam(com.tencent.angel.ml.matrix.psf.update.update.PartIncrementRowsParam) RowUpdateSplit(com.tencent.angel.psagent.matrix.oplog.cache.RowUpdateSplit) ServerRow(com.tencent.angel.ps.storage.vector.ServerRow) Vector(com.tencent.angel.ml.math2.vector.Vector)

Example 19 with ServerRow

use of com.tencent.angel.ps.storage.vector.ServerRow in project angel by Tencent.

the class PartCSRResult method bufferLen.

@Override
public int bufferLen() {
    int len = 4;
    for (ServerRow row : splits) {
        if (row.isDense()) {
            int[] values = ServerRowUtils.getVector((ServerIntIntRow) row).getStorage().getValues();
            int size = (int) (row.getEndCol() - row.getStartCol());
            int cnt = 0;
            for (int i = 0; i < size; i++) if (values[i] > 0)
                cnt++;
            len += 1 + 4;
            if (cnt > size * 0.5) {
                // dense
                len += 4 * size;
            } else {
                // sparse
                len += 8 * cnt;
            }
        } else if (row.isSparse()) {
            int[] values = ServerRowUtils.getVector((ServerIntIntRow) row).getStorage().getValues();
            int size = values.length;
            int cnt = 0;
            for (int i = 0; i < size; i++) if (values[i] > 0)
                cnt++;
            len += 1 + 4 + 8 * cnt;
        } else
            return len;
    }
    return len;
}
Also used : ServerRow(com.tencent.angel.ps.storage.vector.ServerRow) ServerIntIntRow(com.tencent.angel.ps.storage.vector.ServerIntIntRow)

Example 20 with ServerRow

use of com.tencent.angel.ps.storage.vector.ServerRow in project angel by Tencent.

the class AdaGradUpdateFunc method update.

@Override
public void update(RowBasedPartition partition, int factor, double[] scalars) {
    double epsilon = scalars[0];
    double beta = scalars[1];
    double lr = scalars[2];
    double l1RegParam = scalars[3];
    double l2RegParam = scalars[4];
    double epoch = (int) scalars[5];
    double batchSize = (int) scalars[6];
    for (int f = 0; f < factor; f++) {
        ServerRow gradientServerRow = partition.getRow(f + 2 * factor);
        try {
            gradientServerRow.startWrite();
            Vector weight = ServerRowUtils.getVector(partition.getRow(f));
            Vector square = ServerRowUtils.getVector(partition.getRow(f + factor));
            Vector gradient = ServerRowUtils.getVector(gradientServerRow);
            if (batchSize > 1) {
                gradient.idiv(batchSize);
            }
            OptFuncs.iexpsmoothing2(square, gradient, beta);
            if (l2RegParam != 0) {
                gradient.iaxpy(weight, l2RegParam);
            }
            OptFuncs.iadagraddelta(gradient, square, l2RegParam, lr);
            weight.isub(gradient);
            if (l1RegParam != 0) {
                OptFuncs.iadagradthredshold(weight, square, l1RegParam, l2RegParam, lr);
            }
            gradient.clear();
        } finally {
            gradientServerRow.endWrite();
        }
    }
}
Also used : ServerRow(com.tencent.angel.ps.storage.vector.ServerRow) Vector(com.tencent.angel.ml.math2.vector.Vector)

Aggregations

ServerRow (com.tencent.angel.ps.storage.vector.ServerRow)42 Vector (com.tencent.angel.ml.math2.vector.Vector)13 RowBasedPartition (com.tencent.angel.ps.storage.partition.RowBasedPartition)6 PartIncrementRowsParam (com.tencent.angel.ml.matrix.psf.update.update.PartIncrementRowsParam)5 RowUpdateSplit (com.tencent.angel.psagent.matrix.oplog.cache.RowUpdateSplit)5 ArrayList (java.util.ArrayList)5 PartitionKey (com.tencent.angel.PartitionKey)4 ServerIntIntRow (com.tencent.angel.ps.storage.vector.ServerIntIntRow)4 AngelException (com.tencent.angel.exception.AngelException)2 FloatVector (com.tencent.angel.ml.math2.vector.FloatVector)2 RowType (com.tencent.angel.ml.matrix.RowType)2 PartitionGetRowsParam (com.tencent.angel.ml.matrix.psf.get.getrows.PartitionGetRowsParam)2 GetRowSplitResponse (com.tencent.angel.ps.server.data.response.GetRowSplitResponse)2 GetRowsSplitResponse (com.tencent.angel.ps.server.data.response.GetRowsSplitResponse)2 Response (com.tencent.angel.ps.server.data.response.Response)2 MatrixStorageManager (com.tencent.angel.ps.storage.MatrixStorageManager)2 ServerMatrix (com.tencent.angel.ps.storage.matrix.ServerMatrix)2 ServerPartition (com.tencent.angel.ps.storage.partition.ServerPartition)2 ServerRowsStorage (com.tencent.angel.ps.storage.partition.storage.ServerRowsStorage)2 KeyPart (com.tencent.angel.psagent.matrix.transport.router.KeyPart)2