示例#1
0
  /**
   * Get the covariance matrix of unbound estimated parameters.
   *
   * @param problem estimation problem
   * @return covariance matrix
   * @exception EstimationException if the covariance matrix cannot be computed (singular problem)
   */
  public double[][] getCovariances(EstimationProblem problem) throws EstimationException {

    // set up the jacobian
    updateJacobian();

    // compute transpose(J).J, avoiding building big intermediate matrices
    final int n = problem.getMeasurements().length;
    final int m = problem.getUnboundParameters().length;
    final int max = m * n;
    double[][] jTj = new double[m][m];
    for (int i = 0; i < m; ++i) {
      for (int j = i; j < m; ++j) {
        double sum = 0;
        for (int k = 0; k < max; k += m) {
          sum += jacobian[k + i] * jacobian[k + j];
        }
        jTj[i][j] = sum;
        jTj[j][i] = sum;
      }
    }

    try {
      // compute the covariances matrix
      RealMatrix inverse =
          new LUDecompositionImpl(MatrixUtils.createRealMatrix(jTj)).getSolver().getInverse();
      return inverse.getData();
    } catch (InvalidMatrixException ime) {
      throw new EstimationException("unable to compute covariances: singular problem");
    }
  }