Package de.jungblut.math.dense

Examples of de.jungblut.math.dense.DenseDoubleMatrix.subtract()


  public CostGradientTuple evaluateCost(DoubleVector theta) {

    DoubleVector activation = SIGMOID.get().apply(x.multiplyVectorRow(theta));
    DenseDoubleMatrix hypo = new DenseDoubleMatrix(Arrays.asList(activation));
    double error = ERROR_FUNCTION.calculateError(y, hypo);
    DoubleMatrix loss = hypo.subtract(y);
    double j = error / m;
    DoubleVector gradient = xTransposed.multiplyVectorRow(loss.getRowVector(0))
        .divide(m);
    if (lambda != 0d) {
      DoubleVector reg = theta.multiply(lambda / m);
View Full Code Here


    DenseDoubleMatrix multiplyGPU = multiply(a, b);
    LOG.info("GPU took: " + (System.currentTimeMillis() - start) / 1000f + "s!");
    start = System.currentTimeMillis();
    DenseDoubleMatrix multiplyCPU = (DenseDoubleMatrix) a.multiply(b);
    LOG.info("CPU took: " + (System.currentTimeMillis() - start) / 1000f + "s!");
    LOG.info("Matrix difference: " + multiplyCPU.subtract(multiplyGPU).sum());
  }

}
View Full Code Here

    DenseDoubleMatrix mat = new DenseDoubleMatrix(new double[][] { { 2, 5 },
        { 5, 1 }, { 7, 25 } });
    DenseDoubleMatrix expected = new DenseDoubleMatrix(new double[][] {
        { 2, 4, 5, 25 }, { 5, 25, 1, 1 }, { 7, 49, 25, 625 } });
    DenseDoubleMatrix polys = MathUtils.createPolynomials(mat, 2);
    assertEquals(polys.subtract(expected).sum(), 0, 1E-5);
    assertEquals(mat, MathUtils.createPolynomials(mat, 1));
  }

  @Test
  public void testNumericalGradient() {
View Full Code Here

    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    DataInputStream in = new DataInputStream(bais);
    DoubleMatrix readMat = MatrixWritable.readDenseMatrix(in);

    assertEquals(0.0d, mat.subtract(readMat).sum(), 1e-4);

  }

  @Test
  public void testSparseSerDe() throws Exception {
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.