Search in sources :

Example 76 with MatrixClient

use of com.tencent.angel.psagent.matrix.MatrixClient in project angel by Tencent.

the class UpdatePSFTest method testSparseIntLongKeyUDF.

public void testSparseIntLongKeyUDF() throws Exception {
    Worker worker = LocalClusterContext.get().getWorker(workerAttempt0Id).getWorker();
    MatrixClient client1 = worker.getPSAgent().getMatrixClient(SPARSE_INT_LONG_MAT, 0);
    int matrixW1Id = client1.getMatrixId();
    long[] index = genLongIndexs(feaNum, nnz);
    LongIntVector deltaVec = new LongIntVector(feaNum, new LongIntSparseVectorStorage(feaNum, nnz));
    for (int i = 0; i < nnz; i++) {
        deltaVec.set(index[i], (int) index[i]);
    }
    deltaVec.setRowId(0);
    Vector[] updates = new Vector[1];
    updates[0] = deltaVec;
    client1.asyncUpdate(new IncrementRows(new IncrementRowsParam(matrixW1Id, updates))).get();
    LongIntVector row = (LongIntVector) 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 : LongIntVector(com.tencent.angel.ml.math2.vector.LongIntVector) IncrementRowsParam(com.tencent.angel.ml.matrix.psf.update.update.IncrementRowsParam) IncrementRows(com.tencent.angel.ml.matrix.psf.update.update.IncrementRows) Worker(com.tencent.angel.worker.Worker) MatrixClient(com.tencent.angel.psagent.matrix.MatrixClient) LongIntSparseVectorStorage(com.tencent.angel.ml.math2.storage.LongIntSparseVectorStorage) 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 77 with MatrixClient

use of com.tencent.angel.psagent.matrix.MatrixClient 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 78 with MatrixClient

use of com.tencent.angel.psagent.matrix.MatrixClient 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 79 with MatrixClient

use of com.tencent.angel.psagent.matrix.MatrixClient in project angel by Tencent.

the class UpdateRowsTest 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 = null;
    for (int rowId = 0; rowId < rowNum; rowId++) {
        deltaVec = new LongDoubleVector(feaNum, new LongDoubleSparseVectorStorage(feaNum));
        for (int i = 0; i < index.length; i++) {
            deltaVec.set(index[i], index[i]);
        }
        client1.update(rowId, deltaVec);
    }
    int[] rowIds = new int[rowNum];
    for (int i = 0; i < rowNum; i++) {
        rowIds[i] = i;
    }
    Vector[] rows = client1.get(rowIds, index);
    for (int i = 0; i < rowNum; i++) {
        for (long id : index) {
            Assert.assertEquals(((LongDoubleVector) rows[i]).get(id), deltaVec.get(id), zero);
        }
    }
    client1.zero();
    LongDoubleVector[] deltaVecs = new LongDoubleVector[rowNum];
    for (int rowId = 0; rowId < rowNum; rowId++) {
        deltaVec = new LongDoubleVector(feaNum, new LongDoubleSparseVectorStorage(feaNum));
        for (int i = 0; i < index.length; i++) {
            deltaVec.set(index[i], index[i]);
        }
        deltaVecs[rowId] = deltaVec;
    }
    client1.update(rowIds, deltaVecs);
    rows = client1.get(rowIds, index);
    for (int i = 0; i < rowNum; i++) {
        for (long id : index) {
            Assert.assertEquals(((LongDoubleVector) rows[i]).get(id), deltaVecs[i].get(id), zero);
        }
    }
    client1.zero();
    deltaVecs = new LongDoubleVector[rowNum];
    for (int rowId = 0; rowId < rowNum; rowId++) {
        deltaVec = new LongDoubleVector(feaNum, new LongDoubleSparseVectorStorage(feaNum));
        for (int i = 0; i < index.length; i++) {
            deltaVec.set(index[i], index[i]);
        }
        deltaVecs[rowId] = deltaVec;
    }
    client1.increment(rowIds, deltaVecs, true);
    rows = client1.get(rowIds, index);
    for (int i = 0; i < rowNum; i++) {
        for (long id : index) {
            Assert.assertEquals(((LongDoubleVector) rows[i]).get(id), deltaVecs[i].get(id), zero);
        }
    }
}
Also used : Worker(com.tencent.angel.worker.Worker) MatrixClient(com.tencent.angel.psagent.matrix.MatrixClient)

Example 80 with MatrixClient

use of com.tencent.angel.psagent.matrix.MatrixClient in project angel by Tencent.

the class UpdateRowsTest method testSparseIntUDF.

public void testSparseIntUDF() throws Exception {
    Worker worker = LocalClusterContext.get().getWorker(workerAttempt0Id).getWorker();
    MatrixClient client1 = worker.getPSAgent().getMatrixClient(SPARSE_INT_MAT, 0);
    int matrixW1Id = client1.getMatrixId();
    int[] index = genIndexs(feaNum, nnz);
    IntIntVector deltaVec = null;
    for (int rowId = 0; rowId < rowNum; rowId++) {
        deltaVec = new IntIntVector(feaNum, new IntIntSparseVectorStorage(feaNum));
        for (int i = 0; i < index.length; i++) {
            deltaVec.set(index[i], index[i]);
        }
        client1.update(rowId, deltaVec);
    }
    int[] rowIds = new int[rowNum];
    for (int i = 0; i < rowNum; i++) {
        rowIds[i] = i;
    }
    Vector[] rows = client1.get(rowIds, index);
    for (int i = 0; i < rowNum; i++) {
        for (int id : index) {
            Assert.assertEquals(((IntIntVector) rows[i]).get(id), deltaVec.get(id), zero);
        }
        Assert.assertTrue(index.length == ((IntIntVector) rows[i]).size());
    }
    client1.zero();
    IntIntVector[] deltaVecs = new IntIntVector[rowNum];
    for (int rowId = 0; rowId < rowNum; rowId++) {
        deltaVec = VFactory.sparseIntVector(feaNum, index.length);
        for (int i = 0; i < index.length; i++) {
            deltaVec.set(index[i], index[i]);
        }
        deltaVecs[rowId] = deltaVec;
    }
    client1.update(rowIds, deltaVecs);
    rows = client1.get(rowIds, index);
    for (int i = 0; i < rowNum; i++) {
        for (int id : index) {
            Assert.assertEquals(((IntIntVector) rows[i]).get(id), deltaVecs[i].get(id), zero);
        }
    }
    client1.zero();
    for (int rowId = 0; rowId < rowNum; rowId++) {
        deltaVec = VFactory.sparseIntVector(feaNum, index.length);
        for (int i = 0; i < index.length; i++) {
            deltaVec.set(index[i], index[i]);
        }
        deltaVecs[rowId] = deltaVec;
    }
    client1.increment(rowIds, deltaVecs, true);
    rows = client1.get(rowIds, index);
    for (int i = 0; i < rowNum; i++) {
        for (int id : index) {
            Assert.assertEquals(((IntIntVector) rows[i]).get(id), deltaVecs[i].get(id), zero);
        }
    }
}
Also used : Worker(com.tencent.angel.worker.Worker) MatrixClient(com.tencent.angel.psagent.matrix.MatrixClient)

Aggregations

MatrixClient (com.tencent.angel.psagent.matrix.MatrixClient)198 Worker (com.tencent.angel.worker.Worker)183 IntDoubleVector (com.tencent.angel.ml.math2.vector.IntDoubleVector)14 IntFloatVector (com.tencent.angel.ml.math2.vector.IntFloatVector)14 LongFloatVector (com.tencent.angel.ml.math2.vector.LongFloatVector)14 IntIntVector (com.tencent.angel.ml.math2.vector.IntIntVector)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 Test (org.junit.Test)13 IntLongVector (com.tencent.angel.ml.math2.vector.IntLongVector)12 LongDoubleVector (com.tencent.angel.ml.math2.vector.LongDoubleVector)12 LongIntVector (com.tencent.angel.ml.math2.vector.LongIntVector)12 LongLongVector (com.tencent.angel.ml.math2.vector.LongLongVector)12 AngelException (com.tencent.angel.exception.AngelException)10 LongIndexGet (com.tencent.angel.ml.matrix.psf.get.indexed.LongIndexGet)9 LongIndexGetParam (com.tencent.angel.ml.matrix.psf.get.indexed.LongIndexGetParam)9 TVector (com.tencent.angel.ml.math.TVector)6 MasterServiceTest (com.tencent.angel.master.MasterServiceTest)5 DenseDoubleVector (com.tencent.angel.ml.math.vector.DenseDoubleVector)5