Search in sources :

Example 1 with TDoubleVector

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

the class L2HingeLossTest method testLoss2.

@Test
public void testLoss2() throws Exception {
    double[] data1 = { 1.0, 2.0 };
    double[] data2 = { 2.0, 1.0 };
    DenseDoubleVector denseDoubleVector1 = new DenseDoubleVector(2, data1);
    DenseDoubleVector denseDoubleVector2 = new DenseDoubleVector(2, data1);
    DenseDoubleVector w = new DenseDoubleVector(2, data2);
    TDoubleVector[] xList = new TDoubleVector[2];
    xList[0] = denseDoubleVector1;
    xList[1] = denseDoubleVector2;
    double[] yList = new double[2];
    yList[0] = 0;
    yList[1] = 1;
    double test = l2HingeLoss.loss(xList, yList, w, 2);
    assertEquals(1.025, test, 0.00000001);
}
Also used : DenseDoubleVector(com.tencent.angel.ml.math.vector.DenseDoubleVector) TDoubleVector(com.tencent.angel.ml.math.vector.TDoubleVector) Test(org.junit.Test)

Example 2 with TDoubleVector

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

the class DenseDoubleMatrixTest method plusBy1.

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

Example 3 with TDoubleVector

use of com.tencent.angel.ml.math.vector.TDoubleVector 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)

Aggregations

DenseDoubleVector (com.tencent.angel.ml.math.vector.DenseDoubleVector)3 TDoubleVector (com.tencent.angel.ml.math.vector.TDoubleVector)3 Test (org.junit.Test)3 SparseDoubleVector (com.tencent.angel.ml.math.vector.SparseDoubleVector)1