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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations