This file demonstrates how to generate, plot, and output data for 1d benchmarks
Choose from:
Linear
Nonlinear
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
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]:
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()
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()
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()