Thanks for all your help and sharing.
My question is in regards to the Stochastic Search. This technique is used to do approximations of data through a defined amount of circles over a, in general, mathematical calculation. Please see the following code, I tried to reduce it to its minimum. I expect to have this code set up as a lambda expression, the for loop, I would like to have the best performance of it. I have some intents but I'm not sure if I got the most of it.
package stochasticsearch;
import java.util.Random;
public class StochasticSearch {
public static double f(double x) {
return -(x - 1) * (x - 1) + 2;
}
public static void main(String[] args) {
final Random random = new Random();
double startPointX = 0;
double max = f(startPointX);
long begin = System.currentTimeMillis();
for (int a = 0; a < 1000000000; a++) {
double index = 2 * random.nextDouble();
if (f(index) > max) {
Max = f(index);
}
}
System.out.println("Elapsed time: " + (System.currentTimeMillis() - begin));
System.out.println("Maximum value y=f(x) is " + max);
}
}
Thanks, have a nice day.