Search in sources :

Example 6 with IncrementRows

use of com.tencent.angel.ml.matrix.psf.update.update.IncrementRows in project angel by Tencent.

the class UpdatePSFTest method testDenseFloatUDF.

public void testDenseFloatUDF() throws Exception {
    Worker worker = LocalClusterContext.get().getWorker(workerAttempt0Id).getWorker();
    MatrixClient client1 = worker.getPSAgent().getMatrixClient(DENSE_FLOAT_MAT, 0);
    int matrixW1Id = client1.getMatrixId();
    int[] index = genIndexs(feaNum, nnz);
    IntFloatVector deltaVec = new IntFloatVector(feaNum, new IntFloatDenseVectorStorage(feaNum));
    for (int i = 0; i < feaNum; i++) {
        deltaVec.set(i, i);
    }
    deltaVec.setRowId(0);
    Vector[] updates = new Vector[1];
    updates[0] = deltaVec;
    client1.asyncUpdate(new IncrementRows(new IncrementRowsParam(matrixW1Id, updates))).get();
    IntFloatVector row = (IntFloatVector) client1.getRow(0);
    for (int id : index) {
        Assert.assertTrue(row.get(id) == deltaVec.get(id));
    }
    Assert.assertTrue(feaNum == row.size());
}
Also used : IncrementRowsParam(com.tencent.angel.ml.matrix.psf.update.update.IncrementRowsParam) IncrementRows(com.tencent.angel.ml.matrix.psf.update.update.IncrementRows) IntFloatDenseVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatDenseVectorStorage) Worker(com.tencent.angel.worker.Worker) MatrixClient(com.tencent.angel.psagent.matrix.MatrixClient) IntLongVector(com.tencent.angel.ml.math2.vector.IntLongVector) LongIntVector(com.tencent.angel.ml.math2.vector.LongIntVector) Vector(com.tencent.angel.ml.math2.vector.Vector) LongFloatVector(com.tencent.angel.ml.math2.vector.LongFloatVector) IntDoubleVector(com.tencent.angel.ml.math2.vector.IntDoubleVector) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector) LongDoubleVector(com.tencent.angel.ml.math2.vector.LongDoubleVector) LongLongVector(com.tencent.angel.ml.math2.vector.LongLongVector) IntIntVector(com.tencent.angel.ml.math2.vector.IntIntVector) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector)

Example 7 with IncrementRows

use of com.tencent.angel.ml.matrix.psf.update.update.IncrementRows in project angel by Tencent.

the class UpdatePSFTest method testDenseDoubleUDF.

public void testDenseDoubleUDF() throws Exception {
    Worker worker = LocalClusterContext.get().getWorker(workerAttempt0Id).getWorker();
    MatrixClient client1 = worker.getPSAgent().getMatrixClient(DENSE_DOUBLE_MAT, 0);
    int matrixW1Id = client1.getMatrixId();
    int[] index = genIndexs(feaNum, nnz);
    IntDoubleVector deltaVec = new IntDoubleVector(feaNum, new IntDoubleDenseVectorStorage(feaNum));
    for (int i = 0; i < feaNum; i++) {
        deltaVec.set(i, i);
    }
    deltaVec.setRowId(0);
    Vector[] updates = new Vector[1];
    updates[0] = deltaVec;
    client1.asyncUpdate(new IncrementRows(new IncrementRowsParam(matrixW1Id, updates))).get();
    IntDoubleVector row = (IntDoubleVector) client1.getRow(0);
    for (int id : index) {
        Assert.assertEquals(row.get(id), deltaVec.get(id), 0);
    }
    Assert.assertEquals(feaNum, row.size());
}
Also used : IncrementRowsParam(com.tencent.angel.ml.matrix.psf.update.update.IncrementRowsParam) IntDoubleDenseVectorStorage(com.tencent.angel.ml.math2.storage.IntDoubleDenseVectorStorage) IncrementRows(com.tencent.angel.ml.matrix.psf.update.update.IncrementRows) Worker(com.tencent.angel.worker.Worker) MatrixClient(com.tencent.angel.psagent.matrix.MatrixClient) IntLongVector(com.tencent.angel.ml.math2.vector.IntLongVector) LongIntVector(com.tencent.angel.ml.math2.vector.LongIntVector) Vector(com.tencent.angel.ml.math2.vector.Vector) LongFloatVector(com.tencent.angel.ml.math2.vector.LongFloatVector) IntDoubleVector(com.tencent.angel.ml.math2.vector.IntDoubleVector) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector) LongDoubleVector(com.tencent.angel.ml.math2.vector.LongDoubleVector) LongLongVector(com.tencent.angel.ml.math2.vector.LongLongVector) IntIntVector(com.tencent.angel.ml.math2.vector.IntIntVector) IntDoubleVector(com.tencent.angel.ml.math2.vector.IntDoubleVector)

Example 8 with IncrementRows

use of com.tencent.angel.ml.matrix.psf.update.update.IncrementRows in project angel by Tencent.

the class PytorchPSFTask method run.

@Override
public void run(TaskContext taskContext) throws AngelException {
    int feaNum = taskContext.getConf().getInt("col", 100000000);
    int batchNNZ = taskContext.getConf().getInt("batch.nnz", 10000);
    int updateTime = 0;
    long startTs = System.currentTimeMillis();
    try {
        while (true) {
            int[] indices = genIndexs(feaNum, batchNNZ);
            IntFloatVector deltaVec = VFactory.sparseFloatVector(feaNum, batchNNZ);
            for (int i = 0; i < indices.length; i++) {
                deltaVec.set(indices[i], 1);
            }
            Vector[] updates = new Vector[1];
            updates[0] = deltaVec;
            MatrixClient client = taskContext.getMatrix("psf_test");
            client.asyncUpdate(new IncrementRows(new IncrementRowsParam(client.getMatrixId(), updates))).get();
            updateTime++;
            if (updateTime % 100 == 0) {
                LOG.info("update num = " + updateTime + ", avg update time=" + (System.currentTimeMillis() - startTs) / updateTime);
            }
        }
    } catch (Throwable ie) {
    }
}
Also used : IncrementRowsParam(com.tencent.angel.ml.matrix.psf.update.update.IncrementRowsParam) IncrementRows(com.tencent.angel.ml.matrix.psf.update.update.IncrementRows) MatrixClient(com.tencent.angel.psagent.matrix.MatrixClient) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector) Vector(com.tencent.angel.ml.math2.vector.Vector) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector)

Example 9 with IncrementRows

use of com.tencent.angel.ml.matrix.psf.update.update.IncrementRows in project angel by Tencent.

the class UpdatePSFTest method testSparseLongLongKeyUDF.

public void testSparseLongLongKeyUDF() throws Exception {
    Worker worker = LocalClusterContext.get().getWorker(workerAttempt0Id).getWorker();
    MatrixClient client1 = worker.getPSAgent().getMatrixClient(SPARSE_LONG_LONG_MAT, 0);
    int matrixW1Id = client1.getMatrixId();
    long[] index = genLongIndexs(feaNum, nnz);
    LongLongVector deltaVec = new LongLongVector(feaNum, new LongLongSparseVectorStorage(feaNum, nnz));
    for (int i = 0; i < nnz; i++) {
        deltaVec.set(index[i], index[i]);
    }
    deltaVec.setRowId(0);
    Vector[] updates = new Vector[1];
    updates[0] = deltaVec;
    client1.asyncUpdate(new IncrementRows(new IncrementRowsParam(matrixW1Id, updates))).get();
    LongLongVector row = (LongLongVector) client1.getRow(0);
    for (long id : index) {
        // System.out.println("id=" + id + ", value=" + row.get(id));
        Assert.assertEquals(row.get(id), deltaVec.get(id));
    }
// Assert.assertTrue(index.length == row.size());
}
Also used : IncrementRowsParam(com.tencent.angel.ml.matrix.psf.update.update.IncrementRowsParam) IncrementRows(com.tencent.angel.ml.matrix.psf.update.update.IncrementRows) LongLongVector(com.tencent.angel.ml.math2.vector.LongLongVector) Worker(com.tencent.angel.worker.Worker) MatrixClient(com.tencent.angel.psagent.matrix.MatrixClient) LongLongSparseVectorStorage(com.tencent.angel.ml.math2.storage.LongLongSparseVectorStorage) IntLongVector(com.tencent.angel.ml.math2.vector.IntLongVector) LongIntVector(com.tencent.angel.ml.math2.vector.LongIntVector) Vector(com.tencent.angel.ml.math2.vector.Vector) LongFloatVector(com.tencent.angel.ml.math2.vector.LongFloatVector) IntDoubleVector(com.tencent.angel.ml.math2.vector.IntDoubleVector) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector) LongDoubleVector(com.tencent.angel.ml.math2.vector.LongDoubleVector) LongLongVector(com.tencent.angel.ml.math2.vector.LongLongVector) IntIntVector(com.tencent.angel.ml.math2.vector.IntIntVector)

Example 10 with IncrementRows

use of com.tencent.angel.ml.matrix.psf.update.update.IncrementRows in project angel by Tencent.

the class UpdatePSFTest method testSparseDoubleLongKeyUDF.

public void testSparseDoubleLongKeyUDF() throws Exception {
    Worker worker = LocalClusterContext.get().getWorker(workerAttempt0Id).getWorker();
    MatrixClient client1 = worker.getPSAgent().getMatrixClient(SPARSE_DOUBLE_LONG_MAT, 0);
    int matrixW1Id = client1.getMatrixId();
    long[] index = genLongIndexs(feaNum, nnz);
    LongDoubleVector deltaVec = new LongDoubleVector(feaNum, new LongDoubleSparseVectorStorage(feaNum, nnz));
    for (int i = 0; i < feaNum; i++) {
        deltaVec.set(i, i);
    }
    deltaVec.setRowId(0);
    Vector[] updates = new Vector[1];
    updates[0] = deltaVec;
    client1.asyncUpdate(new IncrementRows(new IncrementRowsParam(matrixW1Id, updates))).get();
    // client1.clock().get();
    LongDoubleVector row = (LongDoubleVector) client1.getRow(0);
    for (long id : index) {
        // System.out.println("id=" + id + ", value=" + row.get(id));
        Assert.assertTrue(row.get(id) == deltaVec.get(id));
    }
// Assert.assertTrue(index.length == row.size());
}
Also used : IncrementRowsParam(com.tencent.angel.ml.matrix.psf.update.update.IncrementRowsParam) IncrementRows(com.tencent.angel.ml.matrix.psf.update.update.IncrementRows) LongDoubleVector(com.tencent.angel.ml.math2.vector.LongDoubleVector) Worker(com.tencent.angel.worker.Worker) MatrixClient(com.tencent.angel.psagent.matrix.MatrixClient) LongDoubleSparseVectorStorage(com.tencent.angel.ml.math2.storage.LongDoubleSparseVectorStorage) IntLongVector(com.tencent.angel.ml.math2.vector.IntLongVector) LongIntVector(com.tencent.angel.ml.math2.vector.LongIntVector) Vector(com.tencent.angel.ml.math2.vector.Vector) LongFloatVector(com.tencent.angel.ml.math2.vector.LongFloatVector) IntDoubleVector(com.tencent.angel.ml.math2.vector.IntDoubleVector) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector) LongDoubleVector(com.tencent.angel.ml.math2.vector.LongDoubleVector) LongLongVector(com.tencent.angel.ml.math2.vector.LongLongVector) IntIntVector(com.tencent.angel.ml.math2.vector.IntIntVector)

Aggregations

IntFloatVector (com.tencent.angel.ml.math2.vector.IntFloatVector)13 Vector (com.tencent.angel.ml.math2.vector.Vector)13 IncrementRows (com.tencent.angel.ml.matrix.psf.update.update.IncrementRows)13 IncrementRowsParam (com.tencent.angel.ml.matrix.psf.update.update.IncrementRowsParam)13 MatrixClient (com.tencent.angel.psagent.matrix.MatrixClient)13 IntDoubleVector (com.tencent.angel.ml.math2.vector.IntDoubleVector)12 IntIntVector (com.tencent.angel.ml.math2.vector.IntIntVector)12 IntLongVector (com.tencent.angel.ml.math2.vector.IntLongVector)12 LongDoubleVector (com.tencent.angel.ml.math2.vector.LongDoubleVector)12 LongFloatVector (com.tencent.angel.ml.math2.vector.LongFloatVector)12 LongIntVector (com.tencent.angel.ml.math2.vector.LongIntVector)12 LongLongVector (com.tencent.angel.ml.math2.vector.LongLongVector)12 Worker (com.tencent.angel.worker.Worker)12 IntDoubleDenseVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleDenseVectorStorage)1 IntDoubleSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSparseVectorStorage)1 IntFloatDenseVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatDenseVectorStorage)1 IntFloatSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatSparseVectorStorage)1 IntIntDenseVectorStorage (com.tencent.angel.ml.math2.storage.IntIntDenseVectorStorage)1 IntIntSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntIntSparseVectorStorage)1 IntLongDenseVectorStorage (com.tencent.angel.ml.math2.storage.IntLongDenseVectorStorage)1