Search in sources :

Example 6 with DenseDoubleVector

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

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

the class L2HingeLossTest method testLoss1.

@Test
public void testLoss1() throws Exception {
    double[] data1 = { 1.0, 2.0 };
    DenseDoubleVector denseDoubleVector1 = new DenseDoubleVector(2, data1);
    double[] data2 = { 1.0, 2.0 };
    DenseDoubleVector denseDoubleVector2 = new DenseDoubleVector(2, data2);
    double test = l2HingeLoss.loss(denseDoubleVector1, 2, denseDoubleVector2);
    assertEquals(0.00, test, 0.00);
}
Also used : DenseDoubleVector(com.tencent.angel.ml.math.vector.DenseDoubleVector) Test(org.junit.Test)

Example 8 with DenseDoubleVector

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

the class L2LogLossTest method testLoss.

@Test
public void testLoss() throws Exception {
    double[] data1 = { 1.0, 2.0 };
    DenseDoubleVector denseDoubleVector1 = new DenseDoubleVector(2, data1);
    double[] data2 = { 1.0, 2.0 };
    DenseDoubleVector denseDoubleVector2 = new DenseDoubleVector(2, data2);
    double test = l2LogLoss.loss(denseDoubleVector1, 2, denseDoubleVector2);
    assertEquals(Math.log(1 + Math.exp(-5 * 2)), test, 0.00);
}
Also used : DenseDoubleVector(com.tencent.angel.ml.math.vector.DenseDoubleVector) Test(org.junit.Test) MathsTest(com.tencent.angel.ml.utils.MathsTest)

Example 9 with DenseDoubleVector

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

the class L2LogLossTest 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);
    TAbstractVector[] xList = new TAbstractVector[2];
    xList[0] = denseDoubleVector1;
    xList[1] = denseDoubleVector2;
    double[] yList = new double[2];
    yList[0] = 0;
    yList[1] = 1;
    double test = l2LogLoss.loss(xList, yList, w, 2);
    assertEquals(0.736297, test, 0.00001);
}
Also used : DenseDoubleVector(com.tencent.angel.ml.math.vector.DenseDoubleVector) TAbstractVector(com.tencent.angel.ml.math.TAbstractVector) Test(org.junit.Test) MathsTest(com.tencent.angel.ml.utils.MathsTest)

Example 10 with DenseDoubleVector

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

the class SquareLossTest method testPredict.

@Test
public void testPredict() throws Exception {
    double[] data1 = { 1.0, 2.0, 3.0, 4.0 };
    DenseDoubleVector denseDoubleVector1 = new DenseDoubleVector(4, data1);
    double[] data2 = { 1.0, 2.0, 3.0, 4.0 };
    DenseDoubleVector denseDoubleVector2 = new DenseDoubleVector(4, data2);
    SquareL2Loss squareLoss = new SquareL2Loss();
    double test = squareLoss.predict(denseDoubleVector1, denseDoubleVector2);
    double dot = 0.0;
    for (int i = 0; i < data1.length; i++) dot += data1[i] * data2[i];
    assertEquals(dot, test, 0.00);
}
Also used : DenseDoubleVector(com.tencent.angel.ml.math.vector.DenseDoubleVector) SquareL2Loss(com.tencent.angel.ml.optimizer.sgd.loss.SquareL2Loss) Test(org.junit.Test)

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