code: public static double maximize(UnivariateFunction fn, double gridStart, double gridEnd,
        double gridStep, double relErr, double absErr, int maxIter, int maxEval) {
      Interval interval = gridSearch(fn, gridStart, gridEnd, gridStep);
      BrentOptimizer bo = new BrentOptimizer(relErr, absErr);
      UnivariatePointValuePair max = bo.optimize(
          new MaxIter(maxIter),
          new MaxEval(maxEval),
          new SearchInterval(interval.getInf(), interval.getSup()),
          new UnivariateObjectiveFunction(fn),
          GoalType.MAXIMIZE);
      return max.getPoint();
    }
docs: Maximizes a univariate function using a grid search followed by Brent's algorithm.
  
  @param fn the likelihood function to minimize
  @param gridStart the lower bound for the grid search
  @param gridEnd the upper bound for the grid search
  @param gridStep step size for the grid search
  @param relErr relative error tolerance for Brent's algorithm
  @param absErr absolute error tolerance for Brent's algorithm
  @param maxIter maximum # of iterations to perform in Brent's algorithm
  @param maxEval maximum # of Likelihood function evaluations in Brent's algorithm
  
  @return the value of the parameter that maximizes the function