Results of my master's thesis
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
2.0KB

  1. #!/usr/bin/python
  2. import sys
  3. from optparse import OptionParser
  4. import numpy as np
  5. import scipy.spatial
  6. from grid import simple_random_grid, exact_func
  7. import baker
  8. def rms(errors):
  9. r = 0.0
  10. for i in errors:
  11. r += np.power(i, 2)
  12. r = np.sqrt(r / len(errors))
  13. return r
  14. if __name__ == '__main__':
  15. parser = OptionParser()
  16. parser.add_option("-o", "--output-file", dest="output", type='str', default = '/tmp/for_qhull.txt', help = "qhull output file")
  17. parser.add_option("-e", "--extra-points", dest="extra", type='int', default = 3, help = "how many extra points")
  18. parser.add_option("-s", "--source-total", dest="source_total", type='int', default = 100, help = "total number of source points")
  19. parser.add_option("-d", "--destination-total",dest="destination_total",type='int', default = 100, help = "total number of destination points")
  20. parser.add_option("-v", "--verbose", action = 'store_true', default = False, help = "verbosity")
  21. (options, args) = parser.parse_args()
  22. print >> sys.stderr, options
  23. mesh_source = simple_random_grid(options.source_total)
  24. tree = scipy.spatial.KDTree(mesh_source.points)
  25. mesh_dest = simple_random_grid(options.destination_total)
  26. open(options.output, 'w').write(mesh_source.for_qhull())
  27. print >> sys.stderr, "wrote output to %s" % options.output
  28. errors = []
  29. success = 0
  30. for x in mesh_dest.points:
  31. lin, error, final = baker.run_baker(x, mesh_source, tree, options.extra, options.verbose)
  32. exact = exact_func(x[0], x[1])
  33. if np.abs(exact - final) < np.abs(exact - lin):
  34. success += 1
  35. if options.verbose:
  36. print "current point : %s" % x
  37. print "exact : %0.4f" % exact
  38. print "qlin : %0.4f" % lin
  39. print "q_final : %0.4f" % final
  40. print "qlinerr : %0.4f" % (exact - lin,)
  41. print "q_final_err : %0.4f" % (exact - final,)
  42. cur_error = np.abs(final - exact)
  43. errors.append(cur_error)
  44. print rms(errors)
  45. print "%s of %s won" % (success, options.destination_total)