BayesOpt
eval_branin.py
1 #!/usr/bin/env python
2 
3 # Imports
4 try:
5  import sys
6  import traceback
7  from math import sin, cos, pi
8 except ImportError, err:
9  print "ERROR: Cannot load module: %s" % (err)
10  sys.exit(2)
11 
12 def sqr(x):
13  return x*x
14 
15 def branin(x, y):
16  # sqr(y-(5.1/(4*sqr(M_PI)))*sqr(x)
17  # +5*x/M_PI-6)+10*(1-1/(8*M_PI))*cos(x)+10;
18  return sqr(y-(5.1/(4*sqr(pi)))*sqr(x)+5*x/pi-6)+10*(1-1/(8*pi))*cos(x)+10
19 #} end branin
20 
21 # main function implementation
22 def main(argv):
23  if len(argv) != 2:
24  print "ERROR: 2 arguments required"
25  return
26  y = branin(float(argv[0])*15-5,float(argv[1])*15)
27  f1=open("./results.txt", "w+")
28  f1.write("y="+str(y))
29 #}end main
30 
31 # Execution
32 try:
33  if __name__ == '__main__' :
34  main(sys.argv[1:])
35 except Exception, e:
36  tb = sys.exc_info()[2]
37  traceback.print_exception(e.__class__, e, tb)