I have a bivariate function like

$ f(x,y) = \frac{1}{x^3 \sqrt{\pi}}. e^{\frac{2-x}{x^2}} . y^3 . e^{3.y \over 3-y} $

and I want to find its global maximum over a range of $ x \in [0, 200] \text{, and } y \in [300,50000] $

What kind of algorithms I can use to find the global maximum. I want to have keywords for searching and finding materials.

Are there any java library which I can use to solve these kind of problems?

  • $\begingroup$ Welcome! Note that algorithms are ontopic here, but Java libraries are not. $\endgroup$
    – Raphael
    Jul 18, 2012 at 1:36

2 Answers 2


The most basic algorithm is probably gradient gescent which can also be used for maximization. It uses the gradient of the function to optimize and (starting from an initial point) "goes" into the most promising direction. For maximization this is the direction of the gradient. Look at the examples on Wikipedia. That should give you an idea how it works. Note that in is pure variant, it always gets stuck in local optima. I don't know if there is a Java library for this. I programmed it myself some time ago, but this code is very specific to the task.

Another thing to look at is the Nelder-Mead method. It is also susceptible to local minima and requires a smooth function. It is implemented in Flanagan's Java Scientific Library. Basically you have to extend MaximizationFunction and implement the function

public double function(double[] param)

which contains your function above. This method evaluates your function given the parameters param (in your case two values: x and y) and returns the function value.

Then you can use the whole program like this:

//Create instance of Maximisation
Maximization max = new Maximization();

// Create instace of class holding function to be maximised
YourFunction funct = new YourFunction();

// initial estimates (your initial x and y)
double[] start = {100.0, 3000.0};

// initial step sizes (take a good guess)
double[] step = new double[start.length];
Arrays.fill(step, 100);

// convergence tolerance
double ftol = 0.0001;

// maximal number of iterations
int maxIter = 5000;

// Nelder and Mead maximisation procedure
max.nelderMead(funct, start, step, ftol, maxIter);

// result of maximization
double result = max.getMaximum()

Since your variables have restrictions, you should add some constraints via the addConstraint method of Maximization.

  • $\begingroup$ I see. I edited the answer to have more flow (imho). Still, it's not a particularly good answer: what are (dis)advantages of the methods? Why should I implement/use the more complicated Nelder-Mead? Are there ways to extend either method to multimodel functions? Note that the function $f$ the OP proposes seems to be neither unimodal nor continuous. $\endgroup$
    – Raphael
    Jul 18, 2012 at 9:42
  • $\begingroup$ let us continue this discussion in chat $\endgroup$
    – Raphael
    Jul 18, 2012 at 9:47

You can try using a optimization algorithm like Particle Swarm Optimization or Genetic Algorithms. Matlab has a professional toolbox for GA and there are many written in Java.

Or you can try using this: https://github.com/madflame991/gloptat. (It's in Java) (Function optimization like this was the topic of my bachelor's thesis)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.