Search in sources :

Example 16 with DenseDoubleVector

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

the class DoubleVectorTest method densePlusByDummyTest.

@Test
public void densePlusByDummyTest() {
    DenseDoubleVector vector = new DenseDoubleVector(10);
    vector.set(1, 1.0);
    vector.set(3, 3.0);
    vector.set(5, 5.0);
    SparseDummyVector dummyVector = new SparseDummyVector(10);
    dummyVector.set(1, 1.0);
    dummyVector.set(3, 1.0);
    vector.plusBy(dummyVector, 1.0);
    Assert.assertEquals(2.0, vector.get(1), 0.0);
    Assert.assertEquals(4.0, vector.get(3), 0.0);
    Assert.assertEquals(5.0, vector.get(5), 0.0);
    Assert.assertEquals(0.0, vector.get(7), 0.0);
}
Also used : DenseDoubleVector(com.tencent.angel.ml.math.vector.DenseDoubleVector) SparseDummyVector(com.tencent.angel.ml.math.vector.SparseDummyVector) Test(org.junit.Test)

Example 17 with DenseDoubleVector

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

the class DoubleVectorTest method densePlusBySparseTest.

@Test
public void densePlusBySparseTest() {
    DenseDoubleVector vector = new DenseDoubleVector(10);
    vector.set(1, 1.0);
    vector.set(3, 3.0);
    vector.set(5, 5.0);
    SparseDoubleVector sparseDoubleVector = new SparseDoubleVector(10);
    sparseDoubleVector.set(1, 1.0);
    sparseDoubleVector.set(3, 3.0);
    sparseDoubleVector.set(7, 7.0);
    vector.plusBy(sparseDoubleVector, 1.0);
    Assert.assertEquals(2.0, vector.get(1), 0.0);
    Assert.assertEquals(6.0, vector.get(3), 0.0);
    Assert.assertEquals(5.0, vector.get(5), 0.0);
    Assert.assertEquals(7.0, vector.get(7), 0.0);
}
Also used : DenseDoubleVector(com.tencent.angel.ml.math.vector.DenseDoubleVector) SparseDoubleVector(com.tencent.angel.ml.math.vector.SparseDoubleVector) Test(org.junit.Test)

Example 18 with DenseDoubleVector

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

the class DenseDoubleMatrixTest method plusBy2.

@Test
public void plusBy2() throws Exception {
    double[][] value = { { 1.0, 2.0 }, { 3.0, 4.0 } };
    DenseDoubleMatrix mat = new DenseDoubleMatrix(2, 2, value);
    DenseDoubleVector vec = new DenseDoubleVector(2, new double[] { 1.0, 1.0 });
    vec.setRowId(0);
    mat.plusBy(vec);
    assertEquals(2.0, mat.get(0, 0));
    assertEquals(3.0, mat.get(0, 1));
    assertEquals(3.0, mat.get(1, 0));
}
Also used : DenseDoubleVector(com.tencent.angel.ml.math.vector.DenseDoubleVector) Test(org.junit.Test)

Example 19 with DenseDoubleVector

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

the class DenseDoubleMatrixTest method getTDoubleVector.

@Test
public void getTDoubleVector() throws Exception {
    double[][] value = { { 1.0, 2.0 }, { 3.0, 4.0 } };
    DenseDoubleMatrix mat = new DenseDoubleMatrix(2, 2, value);
    TDoubleVector vec = (TDoubleVector) mat.getRow(0);
    assertEquals(2, vec.size());
    assertEquals(0, vec.getRowId());
    assertEquals(1.0, vec.get(0));
    assertEquals(2.0, vec.get(1));
    DenseDoubleMatrix mat_1 = new DenseDoubleMatrix(2, 2, new double[2][2]);
    TDoubleVector vec_1 = new DenseDoubleVector(2, new double[] { 1.0, 2.0 });
    vec_1.setRowId(0);
    mat_1.plusBy(vec_1);
    TDoubleVector vec_2 = (TDoubleVector) mat_1.getRow(0);
    assertEquals(1.0, vec_2.get(0));
    assertEquals(2.0, vec_2.get(1));
}
Also used : TDoubleVector(com.tencent.angel.ml.math.vector.TDoubleVector) DenseDoubleVector(com.tencent.angel.ml.math.vector.DenseDoubleVector) Test(org.junit.Test)

Example 20 with DenseDoubleVector

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

the class DenseDoubleMatrix method initVector.

/**
 * init the vector by set the value
 *
 * @param rowIndex
 * @param values
 * @return
 */
private DenseDoubleVector initVector(int rowIndex, double[] values) {
    DenseDoubleVector ret = new DenseDoubleVector((int) col, values);
    ret.setMatrixId(matrixId);
    ret.setRowId(rowIndex);
    return ret;
}
Also used : DenseDoubleVector(com.tencent.angel.ml.math.vector.DenseDoubleVector)

Aggregations

DenseDoubleVector (com.tencent.angel.ml.math.vector.DenseDoubleVector)20 Test (org.junit.Test)15 MatrixClient (com.tencent.angel.psagent.matrix.MatrixClient)5 AngelException (com.tencent.angel.exception.AngelException)3 TVector (com.tencent.angel.ml.math.TVector)3 SparseDoubleVector (com.tencent.angel.ml.math.vector.SparseDoubleVector)3 TDoubleVector (com.tencent.angel.ml.math.vector.TDoubleVector)3 MasterServiceTest (com.tencent.angel.master.MasterServiceTest)2 TAbstractVector (com.tencent.angel.ml.math.TAbstractVector)2 MathsTest (com.tencent.angel.ml.utils.MathsTest)2 IOException (java.io.IOException)2 Random (java.util.Random)2 DenseDoubleMatrix (com.tencent.angel.ml.math.matrix.DenseDoubleMatrix)1 CompSparseLongKeyDoubleVector (com.tencent.angel.ml.math.vector.CompSparseLongKeyDoubleVector)1 SparseDummyVector (com.tencent.angel.ml.math.vector.SparseDummyVector)1 SparseLongKeyDoubleVector (com.tencent.angel.ml.math.vector.SparseLongKeyDoubleVector)1 Pull (com.tencent.angel.ml.matrix.psf.aggr.Pull)1 IndexGetFunc (com.tencent.angel.ml.matrix.psf.get.enhance.indexed.IndexGetFunc)1 IndexGetParam (com.tencent.angel.ml.matrix.psf.get.enhance.indexed.IndexGetParam)1 GetRowResult (com.tencent.angel.ml.matrix.psf.get.single.GetRowResult)1