Esempio n. 1
0
  public static void jacobianPrint(
      FunctionNtoM func,
      FunctionNtoMxN jacobian,
      double param[],
      double tol,
      double differenceScale) {
    NumericalJacobianForward numerical = new NumericalJacobianForward(func, differenceScale);

    DenseMatrix64F found = new DenseMatrix64F(func.getNumOfOutputsM(), func.getNumOfInputsN());
    DenseMatrix64F expected = new DenseMatrix64F(func.getNumOfOutputsM(), func.getNumOfInputsN());

    jacobian.process(param, found.data);
    numerical.process(param, expected.data);

    System.out.println("FOUND:");
    found.print();
    System.out.println("-----------------------------");
    System.out.println("Numerical");
    expected.print();

    System.out.println("-----------------------------");
    System.out.println("Large Differences");
    for (int y = 0; y < found.numRows; y++) {
      for (int x = 0; x < found.numCols; x++) {
        double diff = Math.abs(found.get(y, x) - expected.get(y, x));
        if (diff > tol) {
          //					double e = expected.get(y,x);
          //					double f = found.get(y,x);
          System.out.print("1");
        } else System.out.print("0");
      }
      System.out.println();
    }
  }
Esempio n. 2
0
  public static boolean jacobian(
      FunctionNtoM func,
      FunctionNtoMxN jacobian,
      double param[],
      double tol,
      double differenceScale) {
    NumericalJacobianForward numerical = new NumericalJacobianForward(func, differenceScale);

    if (numerical.getNumOfOutputsM() != jacobian.getNumOfOutputsM())
      throw new RuntimeException(
          "M is not equal " + numerical.getNumOfOutputsM() + "  " + jacobian.getNumOfOutputsM());

    if (numerical.getNumOfInputsN() != jacobian.getNumOfInputsN())
      throw new RuntimeException(
          "N is not equal: " + numerical.getNumOfInputsN() + "  " + jacobian.getNumOfInputsN());

    DenseMatrix64F found = new DenseMatrix64F(func.getNumOfOutputsM(), func.getNumOfInputsN());
    DenseMatrix64F expected = new DenseMatrix64F(func.getNumOfOutputsM(), func.getNumOfInputsN());

    jacobian.process(param, found.data);
    numerical.process(param, expected.data);

    return MatrixFeatures.isIdentical(expected, found, tol);
  }