Search in sources :

Example 41 with ServerRow

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

the class FTRLUpdateFunc method update.

@Override
public void update(RowBasedPartition partition, int factor, double[] scalars) {
    double alpha = scalars[0];
    double beta = scalars[1];
    double lambda1 = scalars[2];
    double lambda2 = scalars[3];
    int epoch = (int) scalars[4];
    int batchSize = (int) scalars[5];
    for (int f = 0; f < factor; f++) {
        ServerRow gradientServerRow = partition.getRow(f + 3 * factor);
        try {
            gradientServerRow.startWrite();
            Vector weight = ServerRowUtils.getVector(partition.getRow(f));
            Vector zModel = ServerRowUtils.getVector(partition.getRow(f + factor));
            Vector nModel = ServerRowUtils.getVector(partition.getRow(f + 2 * factor));
            Vector gradient = ServerRowUtils.getVector(gradientServerRow);
            if (batchSize > 1) {
                gradient.idiv(batchSize);
            }
            Vector delta = OptFuncs.ftrldelta(nModel, gradient, alpha);
            Ufuncs.iaxpy2(nModel, gradient, 1);
            zModel.iadd(gradient.sub(delta.mul(weight)));
            Vector newWeight = Ufuncs.ftrlthreshold(zModel, nModel, alpha, beta, lambda1, lambda2);
            weight.setStorage(newWeight.getStorage());
            gradient.clear();
        } finally {
            gradientServerRow.endWrite();
        }
    }
}
Also used : ServerRow(com.tencent.angel.ps.storage.vector.ServerRow) Vector(com.tencent.angel.ml.math2.vector.Vector)

Example 42 with ServerRow

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

the class StreamSerdeUtils method deserializeServerRow.

public static ServerRow deserializeServerRow(DataInputStream in) throws IOException {
    ServerRow rowSplit = ServerRowFactory.createEmptyServerRow(RowType.valueOf(in.readInt()));
    rowSplit.deserialize(in);
    return rowSplit;
}
Also used : ServerRow(com.tencent.angel.ps.storage.vector.ServerRow)

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