Explicit 1D Benchmarks

This file demonstrates how to generate, plot, and output data for 1d benchmarks

Choose from:

Linear

  1. filip
  2. longley
  3. norris
  4. pontius
  5. wampler1
  6. wampler2
  7. wampler3
  8. wampler4
  9. wampler5

Nonlinear

  1. bennett5.tsv
  2. boxbod.tsv
  3. chwirut1.tsv
  4. chwirut2.tsv
  5. danwood.tsv
  6. eckerle4.tsv
  7. gauss1.tsv
  8. gauss2.tsv
  9. gauss3.tsv
  10. hahn1.tsv
  11. kirby2.tsv
  12. lanczos1.tsv
  13. lanczos2.tsv
  14. lanczos3.tsv
  15. mgh09.tsv
  16. mgh10.tsv
  17. mgh17.tsv
  18. misrala.tsv
  19. misralb.tsv
  20. misralc.tsv
  21. misrald.tsv
  22. nelson.tsv
  23. rat42.tsv
  24. rat43.tsv
  25. roszman1.tsv
  26. thurber.tsv

Imports


In [3]:
from pypge.benchmarks import explicit

import numpy as np
import pandas as pd

# visualization libraries
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

# plot the visuals in ipython
%matplotlib inline

Generate the data with noise


In [11]:
# Set your output directories
img_dir = "../img/benchmarks/nist-linear/"
data_dir = "../data/benchmarks/nist-linear/"

prob_name = "filip"

df = pd.read_csv(data_dir + prob_name + ".tsv", delim_whitespace=True, skipinitialspace=True)
df.plot()


Out[11]:
<matplotlib.axes._subplots.AxesSubplot at 0x10793fb90>

Plot inline and save image


In [ ]:
print prob['name'], prob['eqn']
print prob['xpts'].shape

fig = plt.figure()
fig.set_size_inches(16, 12)

plt.plot(prob['xpts'][0], prob['ypure'], 'r.')
plt.legend(loc='center left', bbox_to_anchor=(0.67, 0.12))

plt.title(prob['name'] + " Clean", fontsize=36)
plt.savefig(img_dir + prob['name'].lower() + "_clean.png", dpi=200)
# plt.show()

### You can only do one of 'savefig()' or 'show()'

fig = plt.figure()
fig.set_size_inches(16, 12)

plt.plot(prob['xpts'][0], prob['ypts'], 'b.')
plt.legend(loc='center left', bbox_to_anchor=(0.67, 0.12))

plt.title(prob['name'] + " Noisy", fontsize=36)
plt.savefig(img_dir + prob['name'].lower() + "_noisy.png", dpi=200)
# plt.show()

Output json and csv data


In [ ]:
data = np.array([prob['xpts'][0], prob['ypts']]).T
print data.shape

cols = [['x', 'out']]
out_data = cols + data.tolist()
import json
json_out = json.dumps( out_data, indent=4)
# print json_out

f_json = open(data_dir + prob['name'].lower() + ".json", 'w')
f_json.write(json_out)
f_json.close()

f_csv = open(data_dir + prob['name'].lower() + ".csv", 'w')
for row in out_data:
    line = ", ".join([str(col) for col in row]) + "\n"
    f_csv.write(line)
f_csv.close()

Output clean json and csv data


In [ ]:
data = np.array([prob['xpts'][0], prob['ypure']]).T
print data.shape

cols = [['x', 'out']]
out_data = cols + data.tolist()
import json
json_out = json.dumps( out_data, indent=4)
# print json_out

f_json = open(data_dir + prob['name'].lower() + "_clean.json", 'w')
f_json.write(json_out)
f_json.close()

f_csv = open(data_dir + prob['name'].lower() + "_clean.csv", 'w')
for row in out_data:
    line = ", ".join([str(col) for col in row]) + "\n"
    f_csv.write(line)
f_csv.close()