Search in sources :

Example 1 with SparseLongKeyDoubleVector

use of com.tencent.angel.ml.math.vector.SparseLongKeyDoubleVector in project angel by Tencent.

the class LongKeyTestTask method run.

@Override
public void run(TaskContext taskContext) throws AngelException {
    try {
        MatrixClient client = taskContext.getMatrix("longkey_test");
        while (taskContext.getEpoch() < 100) {
            long startTs = System.currentTimeMillis();
            TVector row = client.getRow(0);
            LOG.info("Task " + taskContext.getTaskId() + " in iteration " + taskContext.getEpoch() + " pull use time=" + (System.currentTimeMillis() - startTs) + ", sum=" + ((CompSparseLongKeyDoubleVector) row).sum());
            startTs = System.currentTimeMillis();
            CompSparseLongKeyDoubleVector deltaV = new CompSparseLongKeyDoubleVector(client.getMatrixId(), 0, 2100000000, 110000000);
            SparseLongKeyDoubleVector deltaV1 = new SparseLongKeyDoubleVector(2100000000, 150000000);
            DenseDoubleVector deltaV2 = new DenseDoubleVector(110000000);
            for (int i = 0; i < 2100000000; i += 20) {
                deltaV.set(i, 1.0);
                deltaV1.set(i, 1.0);
            }
            for (int i = 0; i < 110000000; i++) {
                deltaV2.set(i, 1.0);
            }
            startTs = System.currentTimeMillis();
            int tryNum = 100;
            while (tryNum-- > 0) {
                deltaV.timesBy(2.0);
            }
            LOG.info("combine times use time " + (System.currentTimeMillis() - startTs));
            startTs = System.currentTimeMillis();
            tryNum = 100;
            while (tryNum-- > 0) {
                deltaV1.timesBy(2.0);
            }
            LOG.info("single times use time " + (System.currentTimeMillis() - startTs));
            startTs = System.currentTimeMillis();
            tryNum = 100;
            while (tryNum-- > 0) {
                deltaV2.timesBy(2.0);
            }
            LOG.info("dense times use time " + (System.currentTimeMillis() - startTs));
            deltaV.setMatrixId(client.getMatrixId());
            deltaV.setRowId(0);
            LOG.info("Task " + taskContext.getTaskId() + " in iteration " + taskContext.getEpoch() + " train use time=" + (System.currentTimeMillis() - startTs));
            startTs = System.currentTimeMillis();
            client.increment(deltaV);
            client.clock().get();
            LOG.info("Task " + taskContext.getTaskId() + " in iteration " + taskContext.getEpoch() + " flush use time=" + (System.currentTimeMillis() - startTs));
            taskContext.incEpoch();
        }
    } catch (Throwable x) {
        throw new AngelException("run task failed ", x);
    }
}
Also used : AngelException(com.tencent.angel.exception.AngelException) CompSparseLongKeyDoubleVector(com.tencent.angel.ml.math.vector.CompSparseLongKeyDoubleVector) DenseDoubleVector(com.tencent.angel.ml.math.vector.DenseDoubleVector) MatrixClient(com.tencent.angel.psagent.matrix.MatrixClient) TVector(com.tencent.angel.ml.math.TVector) CompSparseLongKeyDoubleVector(com.tencent.angel.ml.math.vector.CompSparseLongKeyDoubleVector) SparseLongKeyDoubleVector(com.tencent.angel.ml.math.vector.SparseLongKeyDoubleVector)

Example 2 with SparseLongKeyDoubleVector

use of com.tencent.angel.ml.math.vector.SparseLongKeyDoubleVector in project angel by Tencent.

the class SparseDoubleLongKeyMatrixTest method testPlusByGet.

@Test
public void testPlusByGet() {
    SparseDoubleLongKeyMatrix matrix = new SparseDoubleLongKeyMatrix(2, -1);
    matrix.plusBy(0, -100, 1.0);
    matrix.plusBy(1, 100, 1.0);
    assertEquals(matrix.get(0, -100), 1.0);
    assertEquals(matrix.get(1, 100), 1.0);
    matrix.clear();
    SparseLongKeyDoubleVector incVec = new SparseLongKeyDoubleVector(-1);
    incVec.set(-100, 1);
    incVec.set(100, 1);
    incVec.setRowId(0);
    matrix.plusBy(incVec);
    assertEquals(matrix.get(0, -100), 1.0);
    assertEquals(matrix.get(0, 100), 1.0);
    matrix.clear();
    int[] rowIndexes = { 0, 1 };
    long[] colIndexes = { -100, 100 };
    double[] values = { 1.0, 1.0 };
    matrix.plusBy(rowIndexes, colIndexes, values);
    assertEquals(matrix.get(0, -100), 1.0);
    assertEquals(matrix.get(1, 100), 1.0);
    matrix.clear();
    colIndexes[0] = -100;
    colIndexes[1] = 100;
    values[0] = 1.0;
    values[1] = 1.0;
    matrix.plusBy(0, colIndexes, values);
    assertEquals(matrix.get(0, -100), 1.0);
    assertEquals(matrix.get(0, 100), 1.0);
    SparseDoubleLongKeyMatrix matrix1 = new SparseDoubleLongKeyMatrix(2, -1);
    matrix.clear();
    matrix.plusBy(0, -100, 1.0);
    matrix.plusBy(1, 100, 1.0);
    matrix1.plusBy(0, -100, 1.0);
    matrix1.plusBy(1, 100, 1.0);
    matrix.plusBy(matrix1);
    assertEquals(((SparseLongKeyDoubleVector) matrix.getRow(0)).get(-100), 2.0);
    assertEquals(((SparseLongKeyDoubleVector) matrix.getRow(1)).get(100), 2.0);
}
Also used : SparseLongKeyDoubleVector(com.tencent.angel.ml.math.vector.SparseLongKeyDoubleVector) Test(org.junit.Test)

Example 3 with SparseLongKeyDoubleVector

use of com.tencent.angel.ml.math.vector.SparseLongKeyDoubleVector in project angel by Tencent.

the class SparseDoubleLongKeyMatrix method initVector.

@Override
public SparseLongKeyDoubleVector initVector(int rowIndex) {
    SparseLongKeyDoubleVector ret = new SparseLongKeyDoubleVector(col);
    ret.setMatrixId(matrixId);
    ret.setRowId(rowIndex);
    return ret;
}
Also used : SparseLongKeyDoubleVector(com.tencent.angel.ml.math.vector.SparseLongKeyDoubleVector)

Aggregations

SparseLongKeyDoubleVector (com.tencent.angel.ml.math.vector.SparseLongKeyDoubleVector)3 AngelException (com.tencent.angel.exception.AngelException)1 TVector (com.tencent.angel.ml.math.TVector)1 CompSparseLongKeyDoubleVector (com.tencent.angel.ml.math.vector.CompSparseLongKeyDoubleVector)1 DenseDoubleVector (com.tencent.angel.ml.math.vector.DenseDoubleVector)1 MatrixClient (com.tencent.angel.psagent.matrix.MatrixClient)1 Test (org.junit.Test)1