Random Search

Overview


Random Search is a brute method of finding the min/max of a function over a given space. It randomly selects points and evaluates the function on those points. In general, this is a poor metod of finding an optimum, however, it can be used to narrow the search space. For example, one may run a random search over the space, then select the top 5 points from the search, and run gradient descent on the points. This helps to speed up the gradient descent algorithm as well as providing a method of dealing with local optima.

Algorithm


The algorithm can easily be achieved with tools readily available on the davinci platform. The following uses the $range function to generate 100 randomly generated points and their values when inputted to a function f.


$range(100).map(i=>{
  let rand = Math.random();						
  return [rand, f(rand)]
});
					
The following algorithm uses the $list api to sort the results, and then to take the top 10.

$list($range(100)).map(i=>{
  let rand = Math.random();						
  return [rand, f(rand)]
}).sort(p=>p[1]).toArray()[0][0];
					
Try it!

Contents