%%javascript
Jupyter.keyboard_manager.command_shortcuts.remove_shortcut('up');
Jupyter.keyboard_manager.command_shortcuts.remove_shortcut('down');
from IPython import display
Imports ..
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
from mpl_toolkits.mplot3d import axes3d
import pandas as pd
from rotate import rotanimate
import matplotlib.animation as animation
import subprocess
from IPython.display import Image
from matplotlib import cm
from IPython.display import Video
from sklearn.linear_model import LinearRegression
from sklearn.preprocessing import scale
plt.style.use('seaborn-whitegrid')
plt.rcParams["figure.figsize"] = [10,6]
#import numpy as np
#import matplotlib.pyplot as plt
#from mpl_toolkits.mplot3d import Axes3D
from sklearn import decomposition
from sklearn import datasets
from sklearn.preprocessing import StandardScaler
from itertools import chain
import math
import seaborn as sns; sns.set() # styling
from functools import reduce
import functools
import operator
from numpy.polynomial import polynomial as P
from scipy.interpolate import CubicSpline
#### Defaults
sns.set_style("darkgrid", {"axes.facecolor": ".9"})
plt.rcParams.update({'font.size': 12})
import seaborn as sns; sns.set() # styling
Functions
def foldl(func, acc, xs):
return functools.reduce(func, xs, acc)
# tests
#print(foldl(operator.sub, 0, [1,2,3])) # -6
#print(foldl(operator.add, 'L', ['1','2','3'])) # 'L123'
def scanl_plus(data):
'''
returns list of successive reduced values from the list (see haskell foldl)
'''
return [0] + [sum(data[:(k+1)]) for (k,v) in enumerate(data)]
def make1D (data):
return np.array(list(map (lambda x : [x],data)))
def celsius_to_fahr(temp):
return 9/5 * temp + 32
def gen_answers_from_alphas(inputs, new_alphas):
return (np.matmul(inputs,new_alphas))
def polyfitx(x, y, degree):
results = {}
coeffs = np.polyfit(x, y, degree)
# Polynomial Coefficients
results['polynomial'] = coeffs.tolist()
# r-squared
p = np.poly1d(coeffs)
# fit values, and mean
yhat = p(x) # or [p(z) for z in x]
ybar = np.sum(y)/len(y) # or sum(y)/len(y)
ssreg = np.sum((yhat-ybar)**2) # or sum([ (yihat - ybar)**2 for yihat in yhat])
sstot = np.sum((y - ybar)**2) # or sum([ (yi - ybar)**2 for yi in y])
results['determination'] = ssreg / sstot
return results
def showECResults (title,ec_alphas, actual_alphas, principle_vals,ans, ans_scaler):
AxH2 = principle_vals.dot (ec_alphas)
new_nnAnsH2 = ans_scaler.inverse_transform (AxH2)
rH2 = np.corrcoef(ans,(new_nnAnsH2.reshape(-1,)))
rSq = (rH2[1,0])**2
print(rSq)
fig, ax = plt.subplots(1,2)
ax[0].plot(ans,new_nnAnsH,'o', color='green',marker=".", markersize=1);
ax[1].plot(ec_alphas, color='green',marker=".", markersize=10);
ax[1].plot(actual_alphas, ':o', color='orange',marker=".", markersize=12);
fig.suptitle(title)
plt.show()
def left_inverse (m ):
return (np.linalg.solve (m.T.dot(m), m.T))
# Two ways to compute this ..
# rsq = 1 - residual / sum((y - y.mean())**2)
#or
# rsq = 1 - residual / (n * y.var())
# https://stackoverflow.com/questions/3054191/converting-numpy-lstsq-residual-value-to-r2
def lstsq_rsq (output_from_lstsq, inputs, answers):
rsq_ = 1 - output_from_lstsq[1] / sum ((answers - answers.mean())**2)
return (rsq_[0])
def drawVector (origins,vectors):
vectors_np = np.array(vectors)
#origins = ([[0,0],[0,0]])
V = vectors_np
origins_t = zip(*origins)
fig, ax = plt.subplots()
fig.set_size_inches(8,8)
origins_l = np.array(list(map(lambda t: list(t),origins_t)))
q = ax.quiver(*origins_l, (list(V[:,0])), (list(V[:,1])), color=['r','b','g','r'], scale=1,units='xy')
ax.set_aspect('equal')
lim = 7
plt.xlim(-lim,lim)
plt.ylim(-lim,lim)
plt.title('Vector Tutorial',fontsize=10)
#plt.savefig('savedFig.png', bbox_inches='tight')
#print (type(q))
plt.show()
# Reduce Example
#reduce(lambda a,b: a+b, [1,2,3,4,5], 0)b
New Fitness Scaling Method
Selection Methods
Is Crossover Necessary?
v04d_hack_301_pareto - Up to date graphing functions. Simple pareto with two weights, smoothness and fit. No fitness scaling. No PSO. Reduces 301 cols to 50 by skipping uniformly. Fitness E. 10 steps per sec. Threading forkOS.
v04d_hack_301 - Old graphing functions. Full 301 fitness. No fitness scaling. No PSO. Fitness D. 1 step per sec. Threading forkOS.
v04d_hack - Old graphing functions. Fitness C. PSO polyVals. 30 steps per second (problematic?). Threading forkOS.
v04f_rank_poly - Old graphing fuctions. Fitness Scaling. PolyVals.
x = [1,2,3,4,5,6,7,8]
np.array_split(x,2)
[array([1, 2, 3, 4]), array([5, 6, 7, 8])]
Read No Noise Full File PSD Data
df=pd.read_csv('nonoise.txt', sep=' ',header=None, index_col=False)
noNoise = df.values
nnInputs = noNoise[:,0:301] # Do not include index 301 (from zero)
nnAnswers = noNoise[:,301]
df=pd.read_csv('withnoise.txt', sep=' ',header=None, index_col=False)
withNoise = df.values
wnInputs = withNoise[:,0:301] # Do not include index 301 (from zero)
wnAnswers = withNoise[:,301]
Read the Solution (Alphas)
df=pd.read_csv('solution.txt', sep=' ',header=None, index_col=False)
solution_alphas = df.values
#alphasT = np.transpose(alphas)
ans1D = make1D (nnAnswers) # Why did I have to do this?
fCases = np.append (nnInputs,ans1D,axis=1)
ansN1D = make1D (wnAnswers) # Why did I have to do this?
fCasesN = np.append (wnInputs,ansN1D,axis=1)
# Separate the Scaler since we have to unscale later
nnAnswers_scaler = StandardScaler()
nnAnswers_scaled = nnAnswers_scaler.fit_transform(make1D(nnAnswers)) # Returns scaled data
wnAnswers_scaler = StandardScaler()
wnAnswers_scaled = wnAnswers_scaler.fit_transform(make1D(wnAnswers)) # Returns scaled data
# Here we don't need to unscale later
nnInputs_scaler = StandardScaler()
nnInput_scaled = nnInputs_scaler.fit_transform(nnInputs) # Returns scaled data
wnInputs_scaler = StandardScaler()
wnInputs_scaled = wnInputs_scaler.fit_transform(wnInputs) # Returns scaled data
fcases_scaler = StandardScaler()
fcases_scaled = fcases_scaler.fit_transform(fCases) # Returns scaled data
fcasesN_scaler = StandardScaler()
fcasesN_scaled = fcasesN_scaler.fit_transform(fCasesN) # Returns scaled data
# # Restrict to 20 Cols of PCA to match Haskell
# pca = decomposition.PCA(n_components=20) # Creates PCA object
# #pca = decomposition.PCA() # Creates PCA object
# principle_vals = pca.fit_transform(ins_scaled) # Returns values in PCA space
# vr = scanl_plus ( pca.explained_variance_ratio_ ) # make it cumulative (TPP)
# nnPCAs = pca.components_
# #print("Variance Ratios =>\n", vr,"\n")
# principle_vals.shape
# nnPCAs.shape
# pcaN = decomposition.PCA(n_components=20) # Creates PCA object
# principle_valsN = pcaN.fit_transform(insN_scaled) # Return values in PCA space
# vrN = scanl_plus ( pcaN.explained_variance_ratio_ ) # make it cumulative (TPP)
# wnPCAs = pcaN.components_
# print("Variance Ratios =>\n", vr,"\n")
toy_ins = np.array([[1, 4, 3],
[4, 6, 2],
[3, 5, 4],
[2, 2, 1],
[6, 6, 1]])
good_ans = np.array([18, 22, 25, 9, 21])
#theInputs = toy_ins
#theAnswers = good_ans
theInputs = nnInput_scaled
theAnswers = nnAnswers_scaled
print(type(theInputs))
print(type(theAnswers))
<class 'numpy.ndarray'> <class 'numpy.ndarray'>
toy_pca = decomposition.PCA(n_components=20) # Creates PCA object
toy_princ_vals = toy_pca.fit_transform(theInputs) # Returns values in PCA space
toy_vr = scanl_plus ( toy_pca.explained_variance_ratio_ ) # make it cumulative (TPP)
toy_pcas = toy_pca.components_
print(toy_princ_vals.shape)
print(toy_pcas.shape)
print(toy_vr)
print ("PCA Comoponents -> ", toy_pcas)
fileLoc = "/home/poliquin/projects/haskell/spectral_gloss/v04f_rank_poly/princ_vals.txt"
np.savetxt(fileLoc, toy_pcas, delimiter=" ")
#toy_princ_vals
(2696, 20) (20, 301) [0, 0.6451305526885969, 0.8787441855101644, 0.969589930346075, 0.9819021285116154, 0.9900781178484294, 0.9944059631086525, 0.9970722530205748, 0.9981092875973703, 0.9988144335897361, 0.9992615141113722, 0.9995618209466858, 0.9997226786785737, 0.9998232231028523, 0.9998876794241796, 0.9999267586743797, 0.9999483384695654, 0.9999609739943436, 0.9999691794925978, 0.9999752360910276, 0.9999798750098277] PCA Comoponents -> [[ 0.05417707 0.05426636 0.05436478 ... 0.05305204 0.05293906 0.05285003] [-0.04666828 -0.04730076 -0.04797522 ... 0.06354007 0.06343562 0.06331325] [-0.07145471 -0.07178997 -0.07210116 ... -0.05442511 -0.05428631 -0.05416527] ... [ 0.13707347 0.09589262 0.05664363 ... -0.01824525 -0.00740694 -0.01540639] [-0.02340342 -0.02643498 -0.02058622 ... 0.14581786 0.23709236 0.25801936] [ 0.12231762 0.07705105 0.03527201 ... 0.11695219 0.13035027 0.14630297]]
good_ans_scaler = StandardScaler()
#good_ans_scaled = good_ans_scaler.fit_transform(make1D(theAnswers)) # Returns scaled data
good_ans_scaled = good_ans_scaler.fit_transform(theAnswers) # Returns scaled data
good_ans_scaled
array([[-0.09891512], [-0.992661 ], [ 0.22974179], ..., [ 1.12491251], [ 0.74211336], [ 0.45913732]])
These are required to get the alphas back into real space
col_means = np.array(list(map (lambda i: np.mean (theInputs[:,i]), range(0,len(theInputs[0]),1))))
print("Column means -> ", col_means)
Column means -> [ 9.85034672e-17 -1.31447771e-16 -1.72957593e-16 -4.57925817e-17 -1.12010632e-17 4.48042526e-17 1.25188353e-17 1.64721517e-16 1.02127341e-16 -1.80534783e-16 -1.18928935e-16 1.66368732e-16 6.78652650e-17 -4.94164551e-17 -1.05421771e-17 -1.65380403e-16 -1.75263694e-16 1.77240352e-16 9.22440495e-17 3.01110933e-16 6.25941765e-17 -6.58886068e-17 -4.80986830e-17 -3.03087591e-17 -2.22703491e-16 -9.02673913e-17 9.22440495e-18 -1.00809568e-16 7.05008093e-17 2.44776174e-16 1.01139011e-16 2.26986250e-16 1.01468454e-16 -3.13959211e-16 1.02786227e-16 1.14316733e-16 -2.24021263e-17 7.24774675e-17 -7.51130118e-17 9.05968344e-17 1.80534783e-16 1.05421771e-17 9.86681887e-17 -9.88329102e-19 -5.66642019e-17 -1.48249365e-17 -1.41660505e-16 2.09196327e-16 -1.55167669e-16 -2.05901896e-17 -1.42319391e-16 4.20039868e-17 7.67602269e-17 1.23376416e-16 -1.41660505e-16 2.94851515e-17 -6.62180498e-17 1.58132656e-16 3.42620755e-17 5.83114170e-17 -1.83664491e-16 -3.68976198e-17 -1.78887567e-16 1.73287036e-16 2.15455744e-16 2.67178301e-16 -9.29029356e-17 1.12010632e-16 3.95331641e-17 2.04254681e-17 1.27165011e-16 0.00000000e+00 8.10429864e-17 3.95331641e-18 2.04254681e-17 -2.52353364e-16 -3.03087591e-17 -1.97665820e-17 -1.35730530e-16 2.76732149e-17 -1.19917264e-16 5.33697715e-17 9.22440495e-18 -1.62085973e-16 1.18599492e-16 8.76318470e-17 -2.96498731e-17 -8.89496192e-17 7.84074421e-17 -1.42978277e-16 -2.04254681e-17 -1.37048302e-16 -1.50226024e-16 1.25847239e-16 2.96498731e-17 7.64307839e-17 9.88329102e-17 2.37198984e-17 -2.63554427e-17 9.61973659e-17 1.90418074e-16 1.64721517e-16 4.28275944e-17 -7.77485560e-17 -1.44296049e-16 8.03841003e-17 1.31777214e-18 1.62744859e-16 1.04762885e-16 -1.29141669e-16 4.87575690e-17 -3.42620755e-17 -1.16622834e-16 -2.50376706e-17 3.95331641e-18 -1.87782529e-16 -3.18900857e-16 8.82907331e-17 1.41660505e-16 3.49209616e-17 4.87575690e-17 -1.58791542e-16 -3.29443034e-18 -2.33245668e-16 3.95331641e-17 -5.86408601e-17 -8.56551888e-18 -2.17432402e-17 -6.78652650e-17 1.80534783e-16 -1.12010632e-16 4.87575690e-17 -3.88742780e-17 7.64307839e-17 -6.58886068e-18 -5.66642019e-17 1.93053618e-16 -2.10843542e-17 -1.18599492e-16 1.60109315e-16 -9.88329102e-17 6.39119486e-17 -3.42620755e-17 1.12669518e-16 8.82907331e-17 1.83170327e-16 -1.20576150e-16 2.56306680e-16 -1.38366074e-17 2.50376706e-17 -1.61427087e-16 -6.52297207e-17 -4.21687084e-17 -9.42207077e-17 -5.40286576e-17 3.22854173e-17 -1.64721517e-17 6.58886068e-19 -6.85241511e-17 9.22440495e-17 7.70896700e-17 -9.22440495e-17 6.98419232e-17 -1.59450428e-16 -6.98419232e-17 -2.24021263e-17 -2.37198984e-17 -1.71310378e-17 6.58886068e-18 8.63140749e-17 -1.72628150e-16 -3.62387337e-17 -1.46931593e-16 1.27165011e-16 -2.24021263e-17 -3.22854173e-17 -2.28633466e-16 1.84488099e-17 -7.11596953e-17 -8.10429864e-17 -6.85241511e-17 -2.08866884e-16 -6.45708347e-17 -4.74397969e-17 -1.05751214e-16 -2.06231339e-16 2.37198984e-17 -1.40013289e-16 1.50226024e-16 -1.00150682e-16 -1.94371390e-17 7.34657966e-17 -4.80986830e-17 7.57718978e-17 -2.15455744e-16 1.71310378e-17 1.23870581e-16 1.26506125e-16 6.58886068e-17 -3.95331641e-18 -1.71310378e-17 5.86408601e-17 -1.68015947e-16 2.10843542e-17 2.20726833e-16 1.14646176e-16 4.41453666e-17 -1.35071644e-16 -1.70651492e-16 -1.58132656e-17 9.48795938e-17 1.36389416e-16 1.54838226e-16 -6.12764043e-17 -1.44954935e-17 1.62744859e-16 7.24774675e-18 -1.06739543e-16 1.77899238e-17 -5.66642019e-17 1.52861568e-16 -6.72063789e-17 1.58132656e-17 -1.71310378e-17 -5.66642019e-17 -5.07342272e-17 -6.72063789e-17 8.03841003e-17 -3.09676452e-17 7.24774675e-17 -2.63554427e-16 8.56551888e-17 2.37198984e-17 -8.30196446e-17 1.08057315e-16 0.00000000e+00 -1.44954935e-16 9.22440495e-17 3.68976198e-17 -6.58886068e-18 1.44954935e-17 1.05421771e-16 -6.06175183e-17 3.55798477e-17 -6.72063789e-17 9.61973659e-17 -6.58886068e-17 1.44954935e-16 -5.53464297e-17 -2.63554427e-18 -1.06739543e-16 -1.84488099e-16 5.13931133e-17 3.68976198e-17 -7.90663282e-18 -9.48795938e-17 8.30196446e-17 3.95331641e-18 -7.64307839e-17 -2.41152301e-16 8.56551888e-17 8.82907331e-17 -1.06739543e-16 -3.68976198e-17 1.46272707e-16 2.37198984e-16 1.29141669e-16 1.97665820e-17 -1.58132656e-16 -2.24021263e-16 0.00000000e+00 2.50376706e-17 -1.13328404e-16 2.95180958e-16 5.27108854e-18 1.31777214e-17 2.37198984e-17 5.66642019e-17 -2.10843542e-17 2.37198984e-17 2.63554427e-17 -1.31777214e-18 -1.51543796e-16 2.37198984e-17 -4.25640400e-16 -1.52861568e-16 1.10692859e-16 -7.90663282e-18 -1.18599492e-17 2.26656807e-16 -4.08509362e-17 9.75151381e-17 -3.68976198e-17 1.33094986e-16 -5.27108854e-18 -1.97665820e-17 1.69992606e-16 3.68976198e-17 1.02786227e-16 -2.31927896e-16 -5.53464297e-17]
#print (toy_princ_vals.shape)
#print (good_ans_scaled.shape)
pca_l_sq_scaled = np.linalg.lstsq(toy_princ_vals,good_ans_scaled,rcond=None)
print ("PCA Alphas (outs scaled) = ",pca_l_sq_scaled[0],"\n")
pca_l_sq_scaled
PCA Alphas (outs scaled) = [[ 6.78170269e-02] [-1.01594231e-02] [ 6.03470821e-02] [-8.73015346e-04] [-4.44310097e-03] [ 2.06643293e-03] [-1.92712148e-03] [ 5.46940716e-03] [-5.55982885e-03] [ 1.45246442e-03] [-1.60921457e-03] [-3.31126529e-03] [ 2.09471966e-03] [-9.25254756e-05] [-1.00536558e-03] [-8.66158366e-04] [ 9.82543760e-04] [ 1.18738206e-03] [-4.63167325e-05] [ 1.03544498e-03]]
(array([[ 6.78170269e-02], [-1.01594231e-02], [ 6.03470821e-02], [-8.73015346e-04], [-4.44310097e-03], [ 2.06643293e-03], [-1.92712148e-03], [ 5.46940716e-03], [-5.55982885e-03], [ 1.45246442e-03], [-1.60921457e-03], [-3.31126529e-03], [ 2.09471966e-03], [-9.25254756e-05], [-1.00536558e-03], [-8.66158366e-04], [ 9.82543760e-04], [ 1.18738206e-03], [-4.63167325e-05], [ 1.03544498e-03]]), array([3.63361183e-06]), 20, array([723.54741585, 435.40386836, 271.51603737, 99.95648835, 81.45417511, 59.26237522, 46.51541248, 29.00947106, 23.92118626, 19.04741597, 15.61082303, 11.42520923, 9.0327957 , 7.23229196, 5.63139905, 4.1847243 , 3.20213645, 2.58045132, 2.21695859, 1.94022268]))
lstsq_rsq (pca_l_sq_scaled,toy_princ_vals,good_ans_scaled )
0.9999999986522211
print(good_ans_scaler.scale_)
print(good_ans_scaler.mean_)
print(good_ans_scaler.var_)
good_ans_scaler_scale = good_ans_scaler.scale_
[1.] [-2.74096604e-16] [1.]
# Flatten the PCA space Alphas (lstsq puts them in arrays)
print(pca_l_sq_scaled[0])
theAlphas = list(chain(*pca_l_sq_scaled[0]))
print(theAlphas)
real_alphas = toy_pca.inverse_transform(theAlphas)
# unscale ..
unscaled_real_alphas = (real_alphas - col_means) * good_ans_scaler_scale
[[ 6.78170269e-02] [-1.01594231e-02] [ 6.03470821e-02] [-8.73015346e-04] [-4.44310097e-03] [ 2.06643293e-03] [-1.92712148e-03] [ 5.46940716e-03] [-5.55982885e-03] [ 1.45246442e-03] [-1.60921457e-03] [-3.31126529e-03] [ 2.09471966e-03] [-9.25254756e-05] [-1.00536558e-03] [-8.66158366e-04] [ 9.82543760e-04] [ 1.18738206e-03] [-4.63167325e-05] [ 1.03544498e-03]] [0.06781702690833816, -0.010159423113796674, 0.06034708208694862, -0.000873015345645118, -0.004443100966043903, 0.002066432930260635, -0.001927121479514913, 0.005469407164784872, -0.005559828848051578, 0.0014524644155808476, -0.0016092145653626572, -0.003311265290781823, 0.002094719662176753, -9.252547564826967e-05, -0.0010053655812420112, -0.000866158365849512, 0.0009825437596887017, 0.0011873820581651767, -4.6316732485720504e-05, 0.0010354449829850713]
plt.plot(unscaled_real_alphas*1e2, ':o', color='orange',marker=".", markersize=5)
plt.plot(solution_alphas, ':o', color='green',marker=".", markersize=5)
[<matplotlib.lines.Line2D at 0x7f06e34aa880>]
ec_poly_rank01 = [0.8449558038279152,0.3132323191294367,-3.170415724563437,1.196680832431206,-3.4090217730428867,1.2159916999473972,2.449045012147218,-1.3410438248372558,2.0011437805053585,1.6435425161047663,1.079507139889698,-0.9662912417532618,-0.681489063622115,2.0348960776593583,1.3357098116970163,2.8531162916810406,1.74191157403334,0.9367496821294496,2.86493257456703,1.2199986399684761]
ec_poly_rank01 = [0.8449558038279152,0.3132323191294367,-3.170415724563437,1.196680832431206,-3.4090217730428867,1.2159916999473972,2.449045012147218,-1.3410438248372558,2.0011437805053585,1.6435425161047663,1.079507139889698,-0.9662912417532618,-0.681489063622115,2.0348960776593583,1.3357098116970163,2.8531162916810406,1.74191157403334,0.9367496821294496,2.86493257456703,1.2199986399684761]
ec_poly_rank02 = [-2.2903971252789237,-0.8490632737961835,2.262458982671257,-0.8069591047539595,0.6894203536153004,-0.6171083535123605,-0.9023723456124368,0.3406312610317968,0.8556792419677984,-2.5549244352205362,-3.1233535688870315,-1.6796339414159907,-1.4048001853600092,-1.1537072537286406,0.30381222797926943,0.6489631524030987,1.8269325952337965,0.7779829786153122,2.3360175243516745,-1.2792054280372775]
ec_poly_rank03 = [-3.000580693731758,-1.616919310739846,-3.1196855808825683,-2.4178548774090958,2.4910666989554096,-0.9295743298745123,-0.24251282962350726,-0.49168554087123306,0.5982905385341685,-1.8290045970351996,2.027666805794077,-0.7321177791364367,-1.960655832837145,-0.8355711436154789,-2.5553485363600683,2.316377283440344,-3.0630638230793665,-1.1361804486825684,3.2294903418242438,-1.7716819050231118]
ec_poly_rank04 = [-2.118979075660875,-0.8181113501129376,0.45554965516158097,1.6939636406876686,1.722423753355394,-1.4146365525151103,2.937505194384543,-1.344293717862398,-2.7868557404477223,-1.6777532735072358]
ec_poly_rank05 = [-2.118970836618096,-0.8071114992800736,0.45555406358168316,1.6940247484427933,1.7224635030504603,-1.4146349077108737,2.9374563509262654,-1.344293717862398,-2.786849022383858,-1.6777535541722342]
ec_poly_rank06 = [ 1901.9694717555956, 976.084773231719, 420.7889559374729, 120.18740602516412, -16.228005496389024, -56.51649761011385, -49.225954138942264, -26.330498594068036, -6.168069023205003, 3.622007141155014, 3.1614382334843607, -2.604606493038448, -6.845071714786641, -3.780590885943122, 8.378938913241605, 24.496782128191462, 29.571789881746923, -4.199174874092952, -120.35881220642845, -381.1269600497172, ]
ec_poly_rank07 = [ -620.8833339342359, 10.4010617478322, -107.07872071111768, -90.68448506686305, 3.7908545251129118, 45.252630810276045, 20.299450645279368, -17.744346973419646, -28.23960558298023, -13.394604806299975, 0.13714013833633024, -4.7604732757323625, -18.684882496390642, -18.58720285529115, 2.3322805952293457, 18.797086430940848, 0.252798675740205, -27.857788774341877, 19.258801459742337, -6.389566345166293, -1530.2382315795187, ]
ec_poly_rank08 = [ -68581.93942645036, -83.33060277040215, -8673.470932210192, -10644.228362761613, -3037.4960218097713, 3657.9151125096682, 5128.1875202519595, 3165.520461454146, 945.5274638742906, -7.87150587146006, -22.621350734913406, 58.01819207977177, -1.547882143783182, 116.92989414102252, 363.45627007839596, -160.0191808346556, -1948.7541295149047, -2626.121590030612, 1897.4501064666247, 169.8595487890511, -92283.92921908444, ]
ec_poly_rank09 = [ 752.7761822760516, -22.64864066062456, 140.18817813964256, 113.23278825031595, -8.929920108105227, -54.183344855346824, -15.220848737049742, 30.315215656663877, 30.204841568974313, -4.382350313775963, -29.199124859047387, -17.732877110509786, 13.884218536725637, 26.215537618886362, 2.081875416413935, -26.030947170669506, -9.057127017093961, 31.508579317993128, -17.280549765868603, 3.1524291704794325, 1886.4815636058465, ]
ec_poly_rank10 = [ 71623.98561467548, 52.63942587598647, 8808.475445559092, 12233.275892326066, 6247.8835843556135, 402.3421380698238, -1416.7796839894752, -738.0150882757755, -21.269295480669268, -99.39144110500537, -375.5157698265052, -240.71858267581496, 75.68362407336534, -3.9001922388836874e-2, -194.77893687520483, 867.9266889439069, 3660.651305178472, 4594.320808335531, -1744.8056190104821, 854.133089124423, 124668.86619416502, ]
ec_poly_rank11 = [ -261049.19034145496, -53105.039911091655, -276.7216730821912, 5825.047798711957, 3003.7359899862004, 859.27536101944, 131.8902316227554, 5.935989043226144, 1.0798802819318018e-2, -0.41668433218953316, -3.9076141688590346e-2, 1.0006650241320992e-2, 4.088012359922541e-2, -9.906451598767335, -53.08542726847258, -31.39168137336123, 544.6858784051209, 2365.430285334152, 3797.555464552106, -8027.533070493025, ]
ec_poly_rank12 = [ 3318.471243624394, 1441.5320171988342, 408.43826544916004, -63.70992292184629, -194.46682579704895, -147.2210532469899, -36.3755131319243, 65.4726232961448, 120.35195579143185, 117.73688951233387, 67.3676694193956, -7.929585326725207, -79.42284696729236, -119.65414474752623, -109.61953051863848, -45.949044339866845, 51.913319919490334, 134.52964897803892, 115.28814454025452, -136.77684230555204, ]
ec_poly_rank13 = [ -4366.2672718183585, -1913.4244599412034, -573.4471857655572, 30.866268576884448, 191.4812535542364, 124.85075259468873, -18.360617553223975, -143.55260646035686, -202.46532965668632, -183.45526827104328, -101.77126867084536, 10.16945789817042, 112.50533567221477, 167.65442472971398, 150.03842135157691, 55.80665838146285, -87.4398944139516, -210.92462998470498, -194.97130363728277, 140.71996732564847, ]
ec_poly_rank14 = [ 1902.1276822865698, -50.67484169868943, 363.05702674733243, 283.3612082637628, -34.5140160851205, -148.74429859711879, -44.89591150081032, 74.12133196436521, 73.47899861050064, -16.37587501936798, -79.26185658662877, -45.79449493631218, 41.29866479861926, 77.02826881574802, 13.197693378614925, -67.79271773707704, -34.85651860350963, 67.22933179051317, -46.126783764135254, 4.400121411972903, ]
#theInputs = toy_ins
#theAnswers = good_ans
theInputs = nnInput_scaled
theAnswers = nnAnswers_scaled
ecAlphas = np.array(ec_poly_rank14)
#print(type(theInputs))
#print(type(theAnswers))
ecAlphas.shape
(20,)
Note: Here is how to do an (inverse_transform)[https://stackoverflow.com/questions/32750915/pca-inverse-transform-manually)
data_reduced = np.dot(data - pca.mean_, pca.components_.T)
data_original = np.dot(data_reduced, pca.components_) + pca.mean_
Note that the length of the fitness case inputs is 20, and the range of x's is
$\ \ \ \ \ 0.0 < x < 3.0$
# def calcValue (ind, anX):
# return ( foldl (lambda power_value, b,:
# (power_value[0]+1,(power_value[1]+b*anX**power_value[0])),
# (0.0,0.0), ind) )[1]
# def polyVals (ecVals,theLen):
# # return list( map (\x -> calcValue ecVals x) [0.0,maxXValue/(fromIntegral len)..maxXValue])
# return list(map (lambda x : calcValue (ecVals,x),np.arange(0,3, 3/theLen)))
# def dot (theAs, theBs):
# return ( sum (list (map (lambda a,b : a*b, theAs, theBs))))
# ecAlphas = polyVals(ecPolys,10)
toy_pca = decomposition.PCA(n_components=20) # Creates PCA object
toy_princ_vals = toy_pca.fit_transform(theInputs) # Returns values in PCA space
toy_vr = scanl_plus ( toy_pca.explained_variance_ratio_ ) # make it cumulative (TPP)
toy_pcas = toy_pca.components_
# print ("PCA Comoponents -> ", toy_pcas)
# fileLoc = "/home/poliquin/projects/haskell/spectral_gloss/v04f_rank_poly/princ_vals.txt"
# np.savetxt(fileLoc, toy_pcas, delimiter=" ")
print(toy_princ_vals.shape)
print(toy_pcas.shape)
print(toy_vr)
toy_princ_vals
(2696, 20) (20, 301) [0, 0.6451305526885978, 0.8787441855101644, 0.9695899303460751, 0.9819021285116155, 0.9900781178484295, 0.9944059631086526, 0.9970722530205749, 0.9981092875973704, 0.9988144335897362, 0.9992615141113723, 0.9995618209466859, 0.9997226786785738, 0.9998232231028524, 0.9998876794241797, 0.9999267586743799, 0.9999483384695655, 0.9999609739943437, 0.9999691794925979, 0.9999752360910277, 0.9999798750098278]
array([[-3.23476764e+00, -5.12165867e+00, 1.25500298e+00, ..., 7.51627005e-02, -3.32100741e-02, -1.08073340e-02], [-8.68377900e+00, 1.04906671e+01, -5.06496140e+00, ..., -2.72652174e-01, 7.27964704e-02, 3.49044013e-01], [ 3.23035325e+00, -7.81672539e-01, 1.16987125e-01, ..., -1.66845463e-01, -1.32087549e-02, -1.55179524e-02], ..., [ 1.56874553e+01, -1.48383271e+01, -1.46261156e+00, ..., -6.12433881e-02, -5.73434678e-03, 1.77302931e-02], [ 3.52793088e+00, 5.19658359e+00, 9.11698704e+00, ..., -3.74485037e-02, -2.68046055e-02, 3.56070551e-02], [ 6.37373617e+00, -1.89114411e+01, -2.58412094e+00, ..., 1.44590025e-02, -4.18638496e-02, 9.33403665e-04]])
good_ans_scaler = StandardScaler()
#good_ans_scaled = good_ans_scaler.fit_transform(make1D(theAnswers)) # Returns scaled data
good_ans_scaled = good_ans_scaler.fit_transform(theAnswers) # Returns scaled data
good_ans_scaled
array([[-0.09891512], [-0.992661 ], [ 0.22974179], ..., [ 1.12491251], [ 0.74211336], [ 0.45913732]])
These are required to get the alphas back into real space
col_means = np.array(list(map (lambda i: np.mean (theInputs[:,i]), range(0,len(theInputs[0]),1))))
#print("Column means -> ", col_means)
print(good_ans_scaler.scale_)
print(good_ans_scaler.mean_)
print(good_ans_scaler.var_)
good_ans_scaler_scale = good_ans_scaler.scale_
[1.] [-2.74096604e-16] [1.]
# Flatten the PCA space Alphas (lstsq puts them in arrays)
#print(pca_l_sq_scaled[0])
#theAlphas = list(chain(*pca_l_sq_scaled[0]))
#print(theAlphas)
real_alphas = toy_pca.inverse_transform(ecAlphas)
# unscale ..
unscaled_real_alphas = (real_alphas - col_means) * good_ans_scaler_scale
fig = plt.figure()
ax1 = fig.add_axes([0.1, 0.5, 0.8, 0.4])
ax2 = fig.add_axes([0.1, 0.1, 0.8, 0.4])
ax1.plot((unscaled_real_alphas*1)-1800, ':o', color='orange',marker=".", markersize=5)
ax2.plot(solution_alphas*5e3, ':o', color='green',marker=".", markersize=5)
[<matplotlib.lines.Line2D at 0x7f06e33c7e20>]
# Flatten the PCA space Alphas (lstsq puts them in arrays)
#print(pca_l_sq_scaled[0])
#theAlphas = list(chain(*pca_l_sq_scaled[0]))
#print(theAlphas)
real_alphas = toy_pca.inverse_transform(ecAlphas)
# unscale ..
unscaled_real_alphas = (real_alphas - col_means) * good_ans_scaler_scale
ec_301_rank01 = [ -8055426.915451925, -7384411.293149285, -6758498.978475503, -6175151.495988338, -5631950.790746583, -5126594.454645077, -4656891.10759733, -4220755.9296018155, -3816206.3398034703, -3441357.81873616, -3094419.870005229, -2773692.117741973, -2477560.536233168, -2204493.8081995533, -1953039.8082668586, -1721822.208241797, -1509537.2008732758, -1314950.3388461345, -1136893.4858208369, -974261.8763977339, -826011.2819488553, -691155.279323697, -568762.6194980355, -457954.6932965249, -357903.09138076036, -267827.25575447513, -186992.22009671814, -114706.43629224815, -50319.68458584075, 6778.935156106478, 57162.93353739146, 101370.28548296468, 139905.21020050225, 173239.87955061434, 201816.0570711094, 226046.66984888833, 246317.3153819725, 262987.70552391704, 276393.04955336504, 286845.37836274534, 294634.81171218335, 300030.770447458, 303283.1355344045, 304623.3557164222, 304265.50555680116, 302407.29558332474, 299231.0362090957, 294904.55706074246, 289582.0833030956, 283405.0705080404, 276502.99957461, 268994.1331674074, 260986.2351011748, 252577.25406074806, 243855.97300772538, 234902.62558794452, 225789.4808173135, 216581.39728762387, 207336.34809874618, 198105.91768900506, 188935.77170159272, 179866.10099156687, 170932.04084530045, 162164.0664522129, 153588.36563717647, 145227.18983118454, 137099.18422766693, 129219.69804223925, 121601.07576467186, 114252.93026345775, 107182.39857553554, 100394.38118648028, 93891.76557980888, 87675.63480794488, 81745.46181185225, 76099.29019136426, 70733.90210380498, 65644.9739446145, 60827.220440342615, 56274.52776155986, 51980.07624095057, 47936.45326008427, 44135.756847111756, 40569.69050689134, 37229.64978481187, 34106.80104583887, 31192.15293106172, 28476.620935255472, 25951.085530689306, 23606.444244602157, 21433.658080426445, 19423.792655960497, 17568.054415267707, 15857.822255107678, 14284.67489117662, 12840.414274344235, 11517.085352417693, 10306.992458733033, 9202.712595064811, 8197.105862950562, 7283.323284541433, 6454.8122415079915, 5705.31974834566, 5028.8937646305385, 4419.8827393686315, 3872.933569553018, 3382.9881443888885, 2945.2786363595746, 2555.3216903816956, 2208.911652728654, 1902.1129721829568, 1631.2518970031674, 1392.907582755113, 1183.90271785313, 1001.2937657798133, 842.3609153961119, 704.597823511704, 585.7012269524915, 483.560494731978, 396.24718460020324, 322.0046622020308, 259.2378353199279, 206.50305019912233, 162.49819174920432, 126.05302448002809, 96.11980635521331, 71.76420332778449, 52.15652815360901, 36.563323153408895, 24.33930290732812, 14.919669411448682, 7.812808997356878, 2.5933773079822444, -1.1042241704393132, -3.591979105180124, -5.133996309550153, -5.95186238328893, -6.229612647250772, -6.118327828065672, -5.740365578573318, -5.193237376703327, -4.553142635005958, -3.8781729811209127, -3.2112006420026216, -2.5824656875952643, -2.011877568764947, -1.5110469255463748, -1.0850640510426532, -0.7340406795255942, -0.4544319303159146, -0.24015528777404532, -8.352343809867348e-2, 2.3992378492277627e-2, 9.115210033898427e-2, 0.12647361122862463, 0.13788092536274021, 0.1324586872888036, 0.11629846980988677, 9.442300612783967e-2, 7.077520693434644e-2, 4.825958294470747e-2, 2.882451257527158e-2, 1.3574657201195418e-2, 2.9037268007060944e-3, -3.361269100626602e-3, -5.812192322872127e-3, -5.315298004026481e-3, -2.876044948389405e-3, 4.8186845158520043e-4, 3.819307880191865e-3, 6.363410230250982e-3, 7.566247268141145e-3, 7.139472655163146e-3, 5.0649315795244995e-3, 1.582137463037714e-3, -2.845587700902569e-3, -7.583659742281027e-3, -1.1894007636540421e-2, -1.501386258302079e-2, -1.6240645005090447e-2, -1.5017395570339587e-2, -1.1012626755118082e-2, -4.187976292406117e-3, 5.153371058566171e-3, 1.6344855702464058e-2, 2.8368908282635757e-2, 3.991124523629221e-2, 4.9464867228288134e-2, 5.549145789983723e-2, 5.664768974635251e-2, 5.2083631760283966e-2, 4.182001384439307e-2, 2.7210530022442184e-2, 1.1494650251861591e-2, 4.455532806619358e-4, 3.1167845927642947e-3, 3.269007815609796e-2, 0.10742545253034748, 0.2517131950101864, 0.49722567597930056, 0.8841650836345437, 1.4626011308122737, 2.2938905549143302, 3.4521678029934115, 5.025893661020692, 7.119445743326553, 9.854731699282702, 13.372802713583813, 17.835441368094482, 23.426694191256235, 30.354315239602894, 38.851082829116095, 49.17594705607096, 61.61496101177393, 76.48194359729426, 94.11881657702929, 114.89555296783816, 139.20966803762252, 167.4851780777366, 200.1709457115756, 237.73832380122195, 280.6780030092308, 329.49596075761474, 384.7084016949381, 446.8355718292704, 516.3943202036754, 593.8892733760176, 679.802479010285, 774.5813655864312, 878.6248555840479, 992.2674594860989, 1115.7611675765775, 1249.2549457643784, 1392.771630549061, 1546.182006746541, 1709.1758397082776, 1881.2296214902626, 2061.570777752183, 2249.1380690866913, 2442.5379069877, 2639.996290759428, 2839.3060573383027, 3037.769121242181, 3232.1333666696155, 3418.5238381402773, 3592.3678599900422, 3748.3136985051824, 3880.1423634931357, 3980.6721286370725, 4041.6553320614953, 4053.6670001414, 4005.984818710788, 3886.459956463188, 3681.3782254804087, 3375.3110434704813, 2950.9556414353906, 2388.963939118885, 1667.7594886969773, 763.3418647637957, -350.92214427228595, -1704.5212117401686, -3330.0367075759464, -5263.395209440017, -7544.137032121423, -10215.701542938092, -13325.730057073139, -16926.387133590037, -21074.701120247144, -25832.924823189656, -31268.917206144768, -37456.5470528849, -44476.119556461614, -52414.82682905717, -61367.22335725589, -71435.72745910716, -82731.14983154682, -95373.25030956755, -109491.32399198349, -125224.81792273352, -142723.97955141292, -162150.53823211428, -183678.42105571844, -207494.5043474919, -233799.40219923246, -262808.293443273, -294751.788514398, -329876.8376851566, -368447.68220018526, -410746.8498759827, -457076.1967741024, -507757.99659797415, -563136.0795065332, -623577.0220815005, -689471.3902295848, -761235.0368460161, -839310.4561117061, -924168.1963429647, -1016308.3333600879, -1116262.006389277, -1224593.0185612543, -1341899.5041196174, ]
ec_301_rank02 = [ -1.1482960990572736e7, -1.0578830480752083e7, -9734884.412655322, -8947696.028878575, -8214004.969535729, -7530710.470488827, -6894864.790238891, -6303666.859388051, -5754456.14670444, -5244706.735940576, -4772021.607673329, -4334127.120549681, -3928867.6864368413, -3554200.634088129, -3208191.256047454, -2889008.0336249457, -2594918.0348846973, -2324282.4806922763, -2075552.4739750552, -1847264.8874521877, -1638038.4051934388, -1446569.7134669572, -1271629.8364355338, -1112060.6123588737, -966771.3060560102, -834735.3534771111, -714987.2343276975, -606619.4687806265, -508779.7344021433, -420668.09950789314, -341534.3692529899, -270675.5408470916, -207433.36437093324, -151192.00575494271, -101375.80856340125, -57447.15130913842, -18904.397103971438, 14720.067470979238, 43861.707313323604, 68925.63052764811, 90288.29982073525, 108299.16637667139, 123282.22895215529, 135537.52086094796, 145342.52744625945, 152953.53657093088, 158606.9245875404, 162520.38018401683, 164894.06843498917, 165911.737324907, 165741.76894594275, 164538.17751180622, 162441.55626786398, 159579.97531834748, 156069.83233294627, 152016.65803769793, 147515.87833880843, 142653.53487283783, 137506.96572257346, 132145.44798485955, 126630.80382466351, 121017.97159870951, 115355.54358210253, 109686.27178248006, 104047.54327836356, 98471.82647151274, 92987.08959722264, 87617.19279161474, 82382.25497106562, 77298.99673596784, 72381.06046902556, 67639.3087572354, 63082.10222658603, 58715.557839312365, 54543.78866525753, 50569.12610151128, 46792.325478002516, 43212.75595111232, 39828.57555263249, 36636.89222751362, 33633.91166081581, 30815.072662082533, 28175.170843994223, 25708.471301614303, 23408.81096880272, 21269.691299432954, 19284.36189289715, 17445.895656008874, 15747.256066805126, 14181.357079896885, 12741.116187912345, 11419.501129205675, 10209.570708359257, 9104.51017307707, 8097.661568840194, 7182.5494711641895, 6352.902474449041, 5602.670796237896, 4926.0403361885665, 4317.44351020228, 3771.567161937116, 3283.3578363480256, 2848.02468293154, 2461.04024000052, 2118.1393355622317, 1815.316325211528, 1548.8208728691677, 1315.1524661835053, 1111.0538449610285, 933.5035080875105, 779.7074520363625, 647.0902822237381, 533.2858271507625, 436.1273744615195, 353.6376377307517, 284.0185529672972, 225.64099446767239, 177.03449076859582, 136.87701301723806, 103.98490009321831, 77.30297726648551, 55.89491804984366, 38.93389219365685, 25.693536462808808, 15.539278921953045, 7.920041924083567, 2.3603438391296807, -1.5471852367414929, -4.148862994511393, -5.736582954288463, -6.554008113082138, -6.802330726038462, -6.645601888793674, -6.215637428488619, -5.61650916113629, -4.9286328438143725, -4.212466151931963, -3.511831754961338, -2.856882058899549, -2.2667234406974837, -1.751718829333466, -1.3154883004813847, -0.9566279571971675, -0.6701677780893645, -0.44878933741675947, -0.28382434883575425, -0.1660548664697476, -8.633570395927999e-2, -3.605921454247286e-2, -7.482023377496468e-3, 6.067372380294262e-3, 1.0082009427100195e-2, 8.853636085877139e-3, 5.517413088238645e-3, 2.1489559153658445e-3, -1.0032325254665092e-4, -8.424147736173938e-4, -2.780403178149975e-4, 9.815938432064925e-4, 2.087647975484597e-3, 2.1134775114679694e-3, 1.951661646190234e-4, -4.352156082587928e-3, -1.194578725145603e-2, -2.267697583641836e-2, -3.628345785544745e-2, -5.215272732908991e-2, -6.935456388035313e-2, -8.670020874114256e-2, -0.10282452116046562, -0.1162864714024051, -0.12568244456515573, -0.12976605171343894, -0.12756748166259171, -0.11850488855079763, -0.10247990745351732, -7.994913309841441e-2, -5.196329559718736e-2, -2.016593238994297e-2, 1.3256402334697614e-2, 4.567992025744419e-2, 7.421227635189886e-2, 9.593020924565945e-2, 0.10819115975759058, 0.10902260133221561, 9.759129558279006e-2, 7.475291628628986e-2, 4.368045557904098e-2, 1.0567526413830089e-2, -1.4599904809210409e-2, -1.7212692502020573e-2, 2.2838897726106387e-2, 0.13207318958803055, 0.34433588891037625, 0.7017057321044479, 1.2553585730995431, 2.066356657866401, 3.206324638604687, 4.757968308848987, 6.815386085795252, 9.484116916697115, 12.88086153186158, 17.13280679721897, 22.37647532428548, 28.75601446421163, 36.420830335147635, 45.522463597991546, 56.210594294350535, 68.62805318187054, 82.90470663561132, 99.15007131949172, 117.44450345863868, 137.82879565137497, 160.29200173820925, 184.75729728417681, 211.06566971985762, 238.95721811500175, 268.04982791654743, 297.8149707595685, 327.55036364496016, 356.3492053610919, 383.0656909978762, 406.27648775034237, 424.23783692447574, 434.8379281304719, 435.5441720672559, 423.34497805673976, 394.68562156653485, 345.3977653553044, 270.6221755751921, 164.7241511605917, 21.201161111383307, -167.4178401685506, -409.68197450074535, -715.3374594836497, -1095.4566936086183, -1562.578042038942, -2130.8569863845173, -2816.2293308272733, -3636.5871867740525, -4611.968488844015, -5764.760826447958, -7119.920407496826, -8705.207003897267, -10551.435762462965, -12692.746799702392, -15166.893534647452, -18015.55075047231, -21284.643413129084, -25024.697313607106, -29291.21263971485, -34145.06162349995, -39652.91145157141, -45887.67366768278, -52928.98133998176, -60863.69530934476, -69786.44088020215, -79800.1763612341, -91016.79491028318, -103557.76118580766, -117554.78435618969, -133150.52906822955, -150499.36602721672, -169768.1638930662, -191137.12425017628, -214800.6614628864, -240968.32928373083, -269865.79613807116, -301735.8710661984, -336839.5823625917, -375457.3110117577, -417889.98108092457, -464460.30929186614, -515514.116057282, -571421.7003314727, -632579.2806905239, -699410.5051238937, -772368.0320871437, -851935.1854346201, -938627.6859211678, -1032995.4620334657, -1135624.5429842856, -1247139.0367769802, -1368203.1963227189, -1499523.5766695002, -1641851.2864797383, -1795984.3369722865, -1962770.091625108, -2143107.820016471, -2337951.3592655514, -2548311.8866175683, -2775260.8068043217, -3019932.757897898, -3283528.7394637098, -3567319.3669087924, -3872648.2560122972, -4200935.541717687, -4553681.5353599815, -4932470.524596755, -5338974.720408257, -5774958.355630177, ]
ec_301_rank03 = [ -6.909929251878461e7, -6.4595707632203795e7, -6.035743329071801e7, -5.637051608248943e7, -5.26216475222513e7, -4.909813838855829e7, -4.5787893915786095e7, -4.267938981800398e7, -3.976164912230375e7, -3.702421978962472e7, -3.44571531015622e7, -3.205098279209077e7, -2.9796704903569262e7, -2.7685758346825786e7, -2.5710006145545118e7, -2.3861717345599525e7, -2.213354957037696e7, -2.0518532203566946e7, -1.9010050181265738e7, -1.7601828375657044e7, -1.6287916552914467e7, -1.5062674888354866e7, -1.392076002225025e7, -1.2857111640077628e7, -1.186693956135365e7, -1.0945711321561066e7, -1.008914023203068e7, -9293173.902991774, -8553983.215349333, -7867951.727085374, -7231665.500516007, -6641903.336964223, -6095627.405732204, -5589974.254574953, -5122246.189190212, -4689903.009547614, -4290554.091182705, -3921950.799879492, -3581979.2284577843, -3268653.244669559, -2980107.839491417, -2714592.7653783103, -2470466.4543168666, -2246190.2057850785, -2040322.6349887934, -1851514.3720043923, -1678503.0027112977, -1520108.2426477002, -1375227.335167866, -1242830.6655200545, -1121957.5826999915, -1011712.4211665684, -911260.7147335111, -819825.5951736361, -736684.3682907671, -661165.2604285927, -592644.3285956885, -530542.5275916951, -474322.92772121663, -423488.0768794959, -377577.50098732184, -336165.33694198343, -298858.09243648406, -265292.527180639, -235133.65023522807, -208072.82834401794, -183826.00031833292, -162131.99269489248, -142750.93204998513, -125462.74951166478, -110065.77316664398, -96375.40420992997, -84222.87283305131, -73454.06999100551, -63928.451328850686, -55518.00968622246, -48106.31273201333, -41587.602412053275, -35865.95301991699, -30854.484824999337, -26474.630312786325, -22655.45020984765, -19332.99658053195, -16449.72039369602, -13953.921066091647, -11799.235594305812, -9944.164989447501, -8351.63582813799, -6988.594829833072, -5825.634464129424, -4836.647682522813, -3998.50995713785, -3290.7868942779082, -2695.4657732931446, -2196.70944127558, -1780.6310715060247, -1435.0883684398623, -1149.4958743699003, -914.6541027869264, -722.5942909143496, -566.4376289647997, -440.2678863959133, -339.01641587208985, -258.35857381098356, -194.6206523501465, -144.6964713528206, -105.97283072465038, -76.26307287729276, -53.74805269279176, -36.92385785642651, -24.555665977770495, -15.637166552180231, -9.355015570109144, -5.057828501776416, -2.2292535120578836, -0.4647011372620207, 0.5486606760375698, 1.0490062674706027, 1.2143774133085057, 1.174936852384292, 1.023226851125393, 0.8226847104762848, 0.6146438114054216, 0.42402690212807886, 0.2639178068809248, 0.1391785408022981, 4.926090595182023e-2, -9.655022508765647e-3, -4.307857570747898e-2, -5.7079697513295995e-2, -5.7524228535494305e-2, -4.9595932664528254e-2, -3.753901340742728e-2, -2.4564959538118446e-2, -1.287670411101868e-2, -3.7713199274714577e-3, 2.2101496481477367e-3, 5.110570799818919e-3, 5.381380478402616e-3, 3.718059285183065e-3, 9.161011795601487e-4, -2.2465282584575724e-3, -5.0975369912538366e-3, -7.12866333855234e-3, -8.025843704872903e-3, -7.674298554859753e-3, -6.142711340081154e-3, -3.651343995309904e-3, -5.292453356212955e-4, 2.8342925493713192e-3, 6.039147738440443e-3, 8.72027196660303e-3, 1.0586393929285978e-2, 1.1448666675145927e-2, 1.1237340545502777e-2, 1.0005540735853897e-2, 7.920244351598566e-3, 5.241543553177312e-3, 2.29220678257894e-3, -5.796331191532665e-4, -3.0411691079160574e-3, -4.815020749223971e-3, -5.714540386727946e-3, -5.670159431741159e-3, -4.742969407722143e-3, -3.1224543479646443e-3, -1.1064174573005177e-3, 9.372821378231983e-4, 2.6255049592371284e-3, 3.626848601481675e-3, 3.733470312350405e-3, 2.926496186157042e-3, 1.4193587166743012e-3, -3.417353704167369e-4, -1.7468872830237357e-3, -2.194485423767274e-3, -1.4069225403050202e-3, 6.074561726884653e-5, 6.0722308620229753e-5, -6.227733177706682e-3, -2.7778562886903425e-2, -7.969141319625123e-2, -0.18576191696069233, -0.3817697532194218, -0.7196201126772332, -1.272491034124601, -2.141157163313849, -3.461679863817915, -5.414674321315912, -8.236386370828779, -12.231835282921404, -17.790303712047297, -25.403482480291643, -35.68660588501966, -49.4029428216147, -67.49204024484365, -91.10214839667402, -121.62729184683297, -160.7494867673047, -210.4866430355538, -273.2467297757985, -351.88882484538266, -449.7917125964764, -570.9307400342043, -719.9636892931305, -902.3264742070643, -1124.3395206946404, -1393.3257447673186, -1717.7410982296356, -2107.3187106258956, -2573.2277167353523, -3128.24792197151, -3786.961523442697, -4565.963172222848, -5484.08973260571, -6562.671166814632, -7825.804048856057, -9300.649288980114, -11017.75573058838, -13011.41136444921, -15320.023990787704, -17986.53324825182, -21058.85601996153, -24590.367320865702, -28640.41886750452, -33274.89763104523, -38566.82677716899, -44597.0115020779, -51454.73238260679, -59238.488970206214, -68056.79647345367, -78029.03849179031, -89286.37888441543, -101972.73598274002, -116245.82248254758, -132278.2544830766, -150258.73327466953, -170393.30361446447, -192906.69237088462, -218043.7315624526, -246070.869964752, -277277.77761123376, -311979.04766905244, -350516.000330263, -393258.5935215576, -440607.445402307, -492995.9737910436, -550892.657834729, -614803.4274132118, -685274.1859532628, -762893.4725125147, -848295.2691835457, -942161.960062343, -1045227.4482234033, -1158280.437345909, -1282167.8848417522, -1417798.6335467377, -1566147.2292510478, -1728257.931564187, -1905248.9258329924, -2098316.7440591375, -2308740.902994715, -2537888.767831222, -2787220.650138367, -3058295.148954928, -3352774.744184105, -3672431.6517008482, -4019153.949838153, -4394951.987183696, -4801965.081887289, -5242468.522953397, -5718880.884271856, -6233771.662423327, -6789869.249584744, -7390069.253153375, -8037443.17400667, -8735247.455618633, -9486932.91656212, -1.0296154579240153e7, -1.1166781908008516e7, -1.2102909470175808e7, -1.3108868033696886e7, -1.4189236115710046e7, -1.5348851996408815e7, -1.6592826213084254e7, -1.792655454952506e7, -1.935573153631868e7, -2.0886364477959096e7, -2.2524788023033995e7, -2.4277679294137247e7, -2.6152073594531454e7, -2.8155380708969574e7, -3.029540181647496e7, -3.2580347033274766e7, -3.501885360448373e7, -3.762000476354262e7, -4.0393349278829485e7, -4.334892170728063e7, -4.6497263375284456e7, -4.984944410754196e7, -5.341708472502578e7, ]
ec_301 = ec_301_rank03
fig = plt.figure()
ax1 = fig.add_axes([0.1, 0.5, 0.8, 0.4])
ax2 = fig.add_axes([0.1, 0.1, 0.8, 0.4])
ax1.plot(ec_301, ':o', color='orange',marker=".", markersize=5)
ax2.plot(solution_alphas, ':o', color='green',marker=".", markersize=5)
[<matplotlib.lines.Line2D at 0x7f06e32beeb0>]
vals = [47,
31,
7,
17,
48,
48,
12,
12,
49,
49,
45,
45,
30,
30,
45,
45,
34,
34,
43,
43,
45,
49,
45,
30,
49,
32,
30,
35,
32,
48,
35,
49,
48,
37,
47,
49,
27,
37,
42,
47,
41,
27,
40,
42,
23,
41,
9,
21,
40,
23,
49,
9,
49,
21,
6,
48,
49,
46,
49,
38,
6,
32,
48,
34,
46,
38,
38,
44,
32,
24,
34,
37,
47,
38,
48,
44,
15,
43,
24,
40,
37,
48,
47,
44,
48,
11,
15,
46,
43,
41,
40,
48,
44,
11,
46,
41,
]
plt.hist (vals,10)
(array([ 5., 4., 3., 4., 4., 5., 10., 12., 14., 35.]), array([ 6. , 10.3, 14.6, 18.9, 23.2, 27.5, 31.8, 36.1, 40.4, 44.7, 49. ]), <BarContainer object of 10 artists>)
vals2 = [46,
0,
11,
16,
49,
37,
47,
47,
8,
8,
36,
36,
42,
42,
25,
25,
49,
49,
22,
22,
37,
37,
44,
44,
24,
24,
37,
22,
37,
40,
22,
39,
40,
36,
39,
26,
36,
30,
26,
14,
28,
30,
22,
14,
10,
28,
21,
22,
29,
7,
10,
13,
8,
21,
45,
10,
29,
39,
7,
32,
13,
18,
8,
40,
45,
24,
10,
37,
49,
39,
18,
32,
37,
18,
37,
40,
2,
37,
24,
40,
37,
24,
49,
5,
18,
43,
37,
37,
2,
37,
40,
24,
5,
43,]
plt.hist(vals2,10)
(array([ 3., 8., 9., 5., 14., 8., 4., 21., 12., 10.]), array([ 0. , 4.9, 9.8, 14.7, 19.6, 24.5, 29.4, 34.3, 39.2, 44.1, 49. ]), <BarContainer object of 10 artists>)
a1 = [3.691766719870376,-0.45324900807013624,-0.6328292749187538,-2.4535591603731506,-2.3727872551809885,-1.9460216714302947,4.5952277749396475e-3,0.8325415193018809,1.027536028016753,2.7377092570830164,1.5899359750092992,0.6684960875681845,-0.15622141479450996,-2.9682333783614756,-5.3155913592340385,1.8235720358087686,-0.7542570389962948,-1.3472992949259823,-2.22681085587215,-4.1508377463665305,-3.917334748357891,-1.7501534041098994,-1.23296127019783,0.15912149007148518,1.0304571857764917,-4.619730466267905,-4.305964363892311,-4.116905387153439,-3.225765438531903,-0.4046531430717525,1.2838787279733133,0.7028396876989982,3.183751092660421e-2,-0.2769715072483617,-2.5906480967923593,-2.8697339882728676,-3.38249581408716,-5.481526607314231,3.012566052899944,0.8495701568955267,-1.285452013627972,-3.1917379080585233,2.7863646310937042,2.063854665277214,1.6607207350368633,1.072015865250422,1.0015850769579413,0.3489883700457623,-0.5216945944609553,-0.5979082456440877,-2.7046078033658496]
a2 = [5.119576327976686,3.389858601260996,-0.29735043223280005,-24.358205173234346,-5.942067049088909,-13.525236952691815,-21.458897445056135,22.112901418860663,12.28542424688947,6.318260898503328,5.574494383956134,2.79530166904775,-6.162601017545893,-7.765652505387489,-2.0996858355638324,27.923971020576996,20.586288978416757,19.84180537891801,13.729877615353406,8.688029943624134,-9.792200960672211,1.2247827592050353,3.274861381248855,7.234205393497277,7.2936795793691225,12.263104538631577,12.974969284096245,13.557519374896238,15.10856753210703,15.323757991709195,-7.622829446309562,4.636864392584174,5.210385190177541,6.401898634471012,6.922911165467717,8.425519738599167,9.186516404116185,-18.24551641441196,-3.396039024387502,3.0668297715255974,5.9622422692115995,8.220889253340014,10.345407690569552,23.025790562010084,-19.397854938589422,-14.727857896643895,-13.406877717625878,-6.7194634567314235,4.304418937513685,6.756200871788217,7.957623152606171]
a3 = [-2.7104365773573202,-1.848637147901614,2.5403914824687694,3.771377769119905,-0.3613288936750335,-1.3592290693214542,-2.2652158972631256,2.43293455861744,1.4679925196784498,1.0236207551060987,-0.10816785361743136,-0.5087255061714702,-1.5544889076368846,-1.580788680335209,2.184179400024669,2.0633586726673396,-2.4814652311731233,2.6458840898618727,2.5083952723605254,2.0596313842356206,1.836976434977101,1.6318394735208575,3.8987219290173254,0.7874033177070401,-2.5828977027148436,2.9269420293210686,2.9176369343789137,-3.3726466974031677,1.0544140264251995,4.398701409031363,-1.4246131368343398,1.1187252096628515,1.5674103340159533,2.9071670053327985,3.1466688525465005,-2.461319582830882,-1.5247684263928345,1.0988918667494454,2.7219860360631833,-1.6143198808257877,-0.30481759117918106,0.3755997636249161,0.6070348240760972,-2.7102188216555296,-2.5615084965960317,1.823708397708172,-0.6849838518311357,-0.29694219865173,0.7438229221410806,2.031019119929322,2.237876562166073]
a4 = [-2.7104365773573202,-1.163285572719956,2.105543025556544,3.771377769119905,0.5714729259503932,-1.3592290693214542,-2.608584580901142,2.43293455861744,1.6172524158926722,1.0236207551060987,-0.10816785361743136,-0.7522161276766719,1.5674103340159533,-1.9546568601138397,2.184179400024669,2.0831030054108157,-1.5744936701454124,2.6458840898618727,2.5083952723605254,2.0596313842356206,1.6491118661941004,1.6318394735208575,3.8987219290173254,0.5099012906500029,-1.580788680335209,3.0784495998992667,2.9176369343789137,-3.3726466974031677,2.9071670053327985,5.370886827195094,-1.4516636543305195,-0.6313335478092625,-1.258054859831411,1.955609877932364,3.1466688525465005,-2.2652158972631256,0.6070348240760972,1.4689263112947626,2.767912407711239,-1.6143198808257877,-0.3585260114443922,0.3755997636249161,2.0633586726673396,-2.5828977027148436,-2.5615084965960317,-2.4814652311731233,-0.6849838518311357,-0.29694219865173,0.6937921349909545,1.681834817290608,3.049286229047923]
a5 = [-2.255460093442913,-1.4246131368343398,-0.30481759117918106,3.771377769119905,-0.3613288936750335,-1.3592290693214542,-2.2652158972631256,2.43293455861744,1.10231906111375,1.0236207551060987,-0.10816785361743136,-0.30214411551698905,-1.5544889076368846,-1.6978381132695326,2.184179400024669,2.0633586726673396,0.26648777900010145,2.6458840898618727,2.5083952723605254,2.125434019227187,1.836976434977101,2.9176369343789137,1.6318394735208575,-2.4814652311731233,-2.5828977027148436,2.9269420293210686,2.8623392908554384,-2.7927928045384727,1.955609877932364,4.398701409031363,0.6110152746561872,1.4746839470962154,1.5674103340159533,2.9071670053327985,3.1466688525465005,-2.461319582830882,-1.5247684263928345,-1.440943195346969,2.5465233107226304,-1.6143198808257877,2.5403914824687694,0.3755997636249161,1.823708397708172,-2.7102188216555296,-2.5615084965960317,0.6070348240760972,-0.6849838518311357,-0.5087255061714702,0.7438229221410806,2.031019119929322,2.237876562166073]
a6 = [-1.4323721185907048,-0.6543048015720982,-0.30481759117918106,2.881381407006314,-0.22441244101500502,1.955609877932364,-2.2652158972631256,2.43293455861744,2.9071670053327985,1.0236207551060987,-0.10816785361743136,-0.30214411551698905,-1.5544889076368846,-2.516261301796894,2.5403914824687694,2.0633586726673396,0.26648777900010145,2.1432931564255417,2.5083952723605254,-1.4896117955516452,1.5446394420862442,2.9176369343789137,1.6318394735208575,2.9269420293210686,-2.5828977027148436,-2.4814652311731233,2.574698339139731,-2.7927928045384727,1.10231906111375,3.0291126314217425,0.6110152746561872,1.4746839470962154,1.5674103340159533,0.31409007401198874,1.8887540209461617,-2.297633613929693,-1.5247684263928345,2.4631496843189087,2.5465233107226304,1.823708397708172,2.184179400024669,-1.3592290693214542,0.6070348240760972,-2.7102188216555296,-2.5615084965960317,-1.6143198808257877,-0.6849838518311357,-0.5087255061714702,1.004116292889437,2.031019119929322,2.237876562166073]
testD = [3.691766719870376,-0.45324900807013624,-0.6328292749187538,-2.4535591603731506,-2.3727872551809885,-1.9460216714302947,4.5952277749396475e-3,0.8325415193018809,1.027536028016753,2.7377092570830164,1.5899359750092992,0.6684960875681845,-0.15622141479450996,-2.9682333783614756,-5.3155913592340385,1.8235720358087686,-0.7542570389962948,-1.3472992949259823,-2.22681085587215,-4.1508377463665305,-3.917334748357891,-1.7501534041098994,-1.23296127019783,0.15912149007148518,1.0304571857764917,-4.619730466267905,-4.305964363892311,-4.116905387153439,-3.225765438531903,-0.4046531430717525,1.2838787279733133,0.7028396876989982,3.183751092660421e-2,-0.2769715072483617,-2.5906480967923593,-2.8697339882728676,-3.38249581408716,-5.481526607314231,3.012566052899944,0.8495701568955267,-1.285452013627972,-3.1917379080585233,2.7863646310937042,2.063854665277214,1.6607207350368633,1.072015865250422,1.0015850769579413,0.3489883700457623,-0.5216945944609553,-0.5979082456440877,-2.7046078033658496]
plt.plot(testD,':o', color='green',marker=".", markersize=5)
[<matplotlib.lines.Line2D at 0x7f06e31e5640>]
#import numpy as np
#import matplotlib.pyplot as plt
#plt.style.use('seaborn-poster')
x = [0, 1, 2]
y = [1, 3, 2]
# use bc_type = 'natural' adds the constraints as we described above
f = CubicSpline(x,y, bc_type='natural')
x_new = np.linspace(0, 2, 100)
y_new = f(x_new)
plt.figure(figsize = (10,8))
plt.plot(x_new, y_new, 'b')
plt.plot(x, y, 'ro')
plt.title('Cubic Spline Interpolation')
plt.xlabel('x')
plt.ylabel('y')
plt.show()
yIn = [3.691766719870376,-0.45324900807013624,-0.6328292749187538,-2.4535591603731506,-2.3727872551809885,-1.9460216714302947,4.5952277749396475e-3,0.8325415193018809,1.027536028016753,2.7377092570830164,1.5899359750092992,0.6684960875681845,-0.15622141479450996,-2.9682333783614756,-5.3155913592340385,1.8235720358087686,-0.7542570389962948,-1.3472992949259823,-2.22681085587215,-4.1508377463665305,-3.917334748357891,-1.7501534041098994,-1.23296127019783,0.15912149007148518,1.0304571857764917,-4.619730466267905,-4.305964363892311,-4.116905387153439,-3.225765438531903,-0.4046531430717525,1.2838787279733133,0.7028396876989982,3.183751092660421e-2,-0.2769715072483617,-2.5906480967923593,-2.8697339882728676,-3.38249581408716,-5.481526607314231,3.012566052899944,0.8495701568955267,-1.285452013627972,-3.1917379080585233,2.7863646310937042,2.063854665277214,1.6607207350368633,1.072015865250422,1.0015850769579413,0.3489883700457623,-0.5216945944609553,-0.5979082456440877,-2.7046078033658496]
y = yIn[::5]
x = np.linspace(-3,3,11)
print (len(x))
print (len(y))
# use bc_type = 'natural' adds the constraints as we described above
f = CubicSpline(x, y, bc_type='natural')
x_new = np.linspace(-3,3,100)
y_new = f(x_new)
plt.figure(figsize = (10,8))
plt.plot(x_new, y_new, 'b')
plt.plot(x, y, 'ro')
plt.plot (x, y, ':o',color='orange')
plt.title('Cubic Spline Interpolation')
plt.xlabel('x')
plt.ylabel('y')
plt.show()
11 11
x = [0, 1, 2]
y = [1, 3, 2]
# Generated by Haskell
coef = [[1.0,2.5,-5.551e-16,-0.50],[-7.5495e-15,5.5,-3.0,0.500]]
xa = np.linspace (0,1,100)
xb = np.linspace (1,2,100)
f1d = list(map (lambda xp : 1 + 2.5*xp - 0.5*xp**3,xa))
f2d = list(map (lambda xp : 0 + 5.5*xp -3.0*xp**2 + 0.5*xp**3,xb))
#f1e = list(map (lambda xp : -0.5 + 0*xp + 2.5*xp**2 + 1.0*xp**3,xa))
#f2e = list(map (lambda xp : 0.5 - 3.0*xp + 5.5*xp**2 + 0.0*xp**3,xb))
plt.plot (f1d+f2d)
[<matplotlib.lines.Line2D at 0x7f06e30de250>]
# [(0,1),(1,3),(2,2),(3,3)]
# From Haskell
c = [[1.0000000000000033,2.9333333333333282,4.440892098500626e-15,-0.9333333333333398],
[-1.6000000000000087,10.733333333333388,-7.800000000000053,1.6666666666666796],
[17.60000000000015,-18.06666666666686,6.600000000000078,-0.7333333333333434]]
xa = np.linspace (0,1,100)
xb = np.linspace (1,2,100)
xc = np.linspace (2,3,100)
f1d = list(map (lambda xp : c[0][0] + c[0][1]*xp + c[0][2]*xp**2 + c[0][3]*xp**3,xa))
f2d = list(map (lambda xp : c[1][0] + c[1][1]*xp + c[1][2]*xp**2 + c[1][3]*xp**3,xb))
f3d = list(map (lambda xp : c[2][0] + c[2][1]*xp + c[2][2]*xp**2 + c[2][3]*xp**3,xc))
# f1d = list(map (lambda xp : c[0][3] + c[0][2]*xp + c[0][1]*xp**2 + c[0][0]*xp**3,xa))
# f2d = list(map (lambda xp : c[1][3] + c[1][2]*xp + c[1][1]*xp**2 + c[1][0]*xp**3,xb))
# f3d = list(map (lambda xp : c[2][3] + c[2][2]*xp + c[2][1]*xp**2 + c[2][0]*xp**3,xc))
plt.plot (f1d+f2d+f3d)
#plt.plot ([0,100,200,300],[1,3,3,1],'ro')
[<matplotlib.lines.Line2D at 0x7f06e3033c40>]
display.Image("/home/poliquin/projects/haskell/jayai02/jup_plot/v03/cspline_web_calc01.png",width=600,height=300)
c = [[0.9999999999999994,2.750000000000003,2.220446049250313e-16,-0.7500000000000011],[-0.5000000000000115,7.250000000000012,-4.5000000000000036,0.7500000000000004]]
xa = np.linspace (0,1,100)
xb = np.linspace (1,2,100)
f1d = list(map (lambda xp : c[0][0] + c[0][1]*xp + c[0][2]*xp**2 + c[0][3]*xp**3,xa))
f2d = list(map (lambda xp : c[1][0] + c[1][1]*xp + c[1][2]*xp**2 + c[1][3]*xp**3,xb))
# f1d = list(map (lambda xp : c[0][3] + c[0][2]*xp + c[0][1]*xp**2 + c[0][0]*xp**3,xa))
# f2d = list(map (lambda xp : c[1][3] + c[1][2]*xp + c[1][1]*xp**2 + c[1][0]*xp**3,xb))
# f3d = list(map (lambda xp : c[2][3] + c[2][2]*xp + c[2][1]*xp**2 + c[2][0]*xp**3,xc))
plt.plot (f1d+f2d)
#plt.plot ([0,100,200,300],[1,3,3,1],'ro')
[<matplotlib.lines.Line2D at 0x7f06e3009b20>]
c0 = [[5.000000000000245,-4.792863896083825,3.915756607852927e-13,-20.820030784273072],
[1.6271550129487422,28.93558597443294,-112.42816623505523,104.10015392134437],
[61.558194598593616,-270.7196119537839,386.99716364530633,-173.35836267885642],
[-197.4440251571947,592.6211205655104,-572.2703169316873,181.92588938669655],
[498.8324084349582,-1148.0699634148677,878.305586385296,-221.01186153468765],
[-991.742878283198,1833.0806100214477,-1109.1281292389167,220.64007527069305],
[913.1805401403936,-1341.791754017871,654.6898507829285,-105.99288399261171],
[-236.4722160560117,300.5693262627075,-127.38685411258632,18.14627551461289],
[64.55271920077064,-75.7118428082681,29.396966333652983,-3.629255102920226]]
c1 = [[0.6809008024547628,-5.352471023282419,3.7925218521195347e-13,24.32996800428968],[2.546619923378176,-24.009662232515016,62.190637364109165,-44.770740178053224],[-22.295600065556137,100.20143771215652,-144.8278625436774,70.23953754849492],[114.95984030053329,-357.3166968414753,363.52562029369045,-118.03953016904872],[-273.9029471653472,614.8402718232228,-446.6051869268906,106.99680517000165],[380.98111006026977,-694.9278426280114,426.5735560405987,-87.04291548944056],[-650.9115628718789,1024.8932789255696,-528.8826226002797,89.89341388850005],[759.7797862279035,-990.3800769312636,430.7713563791651,-62.432614520935715],[-700.3019831739266,834.7221348210246,-329.68789851762165,43.18672643695139],[589.8670408308051,-598.7990029620133,201.24585621683758,-22.36065069075972]]
c2 = [[0.3697510140897484,-2.382471912348456,2.988165270778609e-13,11.258057763153081],[1.1264349086274366,-9.949310857724797,25.222796484588237,-16.767271664166643],[-11.731723767831587,54.34148252457029,-81.92852581923725,42.76124072684749],[89.4360748596659,-282.8845129004218,292.7670246529756,-96.01488907767573],[-229.3913784313862,514.184120327206,-371.4568363700471,88.49173898427506],[296.79700892348274,-538.1926543825318,330.12768010311135,-67.4159313430936],[-482.91529037920066,761.3278444552734,-391.8281525845583,66.2795932286972],[465.53161249204646,-593.5963025036519,253.37382215778743,-36.133418635167246],[-396.9570201904919,484.514488349521,-195.839007364368,26.257252131798815],[488.2588258527212,-499.05867392071747,168.44734903201712,-18.716372114668562]]
c = [[0.3697510140897484,-2.382471912348456,2.988165270778609e-13,11.258057763153081],[1.1264349086274366,-9.949310857724797,25.222796484588237,-16.767271664166643],[-11.731723767831587,54.34148252457029,-81.92852581923725,42.76124072684749],[89.4360748596659,-282.8845129004218,292.7670246529756,-96.01488907767573],[-229.3913784313862,514.184120327206,-371.4568363700471,88.49173898427506],[296.79700892348274,-538.1926543825318,330.12768010311135,-67.4159313430936],[-482.91529037920066,761.3278444552734,-391.8281525845583,66.2795932286972],[465.53161249204646,-593.5963025036519,253.37382215778743,-36.133418635167246],[-396.9570201904919,484.514488349521,-195.839007364368,26.257252131798815],[488.2588258527212,-499.05867392071747,168.44734903201712,-18.716372114668562]]
print (len (c))
plen = 5
d = 0.3
xa = np.linspace ( 0, d,plen)
xb = np.linspace ( d,2*d,plen)
xc = np.linspace (2*d,3*d,plen)
xd = np.linspace (3*d,4*d,plen)
xe = np.linspace (4*d,5*d,plen)
xf = np.linspace (5*d,6*d,plen)
xg = np.linspace (6*d,7*d,plen)
xh = np.linspace (7*d,8*d,plen)
xi = np.linspace (8*d,9*d,plen)
#xj = np.linspace (9*d,2,100)
print(xa)
print(xb)
f1d = list(map (lambda xp : c[0][0] + c[0][1]*xp + c[0][2]*xp**2 + c[0][3]*xp**3,xa))
f2d = list(map (lambda xp : c[1][0] + c[1][1]*xp + c[1][2]*xp**2 + c[1][3]*xp**3,xb))
f3d = list(map (lambda xp : c[2][0] + c[2][1]*xp + c[2][2]*xp**2 + c[2][3]*xp**3,xc))
f4d = list(map (lambda xp : c[3][0] + c[3][1]*xp + c[3][2]*xp**2 + c[3][3]*xp**3,xd))
f5d = list(map (lambda xp : c[4][0] + c[4][1]*xp + c[4][2]*xp**2 + c[4][3]*xp**3,xe))
f6d = list(map (lambda xp : c[5][0] + c[5][1]*xp + c[5][2]*xp**2 + c[5][3]*xp**3,xf))
f7d = list(map (lambda xp : c[6][0] + c[6][1]*xp + c[6][2]*xp**2 + c[6][3]*xp**3,xg))
f8d = list(map (lambda xp : c[7][0] + c[7][1]*xp + c[7][2]*xp**2 + c[7][3]*xp**3,xh))
f9d = list(map (lambda xp : c[8][0] + c[8][1]*xp + c[8][2]*xp**2 + c[8][3]*xp**3,xi))
#f10d = list(map (lambda xp : c[9][0] + c[9][1]*xp + c[9][2]*xp**2 + c[9][3]*xp**3,xj))
# Haskell Computation ..
haskellSol0 = [5.000000000000245,4.707931039585815,4.388879319274968,4.0158620791712885,3.561896559378359,2.99999999999976,2.99999999999995,2.3301724010356857,1.6603448020713962,1.1254310025891439,0.8603448020709905,0.9999999999990088,1.0000000000005898,1.6193793562711605,2.553741472438176,3.578413910469891,4.468724232334324,4.9999999999999005,4.999999999999744,5.024310173880679,4.700689308176038,4.264913355530808,3.952758268590401,3.9999999999997726,4.000000000002785,4.555379948208554,5.41950129485997,6.305932667408456,6.928242693305947,7.000000000001933,7.0,6.330170033295872,5.1093055123935756,3.6233559748422977,2.1582709581939525,0.9999999999995453,1.000000000002501,0.36393991861154973,0.18327665557058026,0.3206434332247454,0.6386734739202211,1.0000000000015916,0.9999999999983231,1.2940702922659852,1.5175878653328425,1.6940702922657351,1.8470351461317023,1.9999999999976694,1.9999999999991758,2.1717789123186932,2.3623718830917326,2.5670753977049188,2.7811859415448765,2.999999999998195]
haskellSol1 = [5.000000000000245,4.707931039585815,4.388879319274968,4.0158620791712885,3.561896559378359,2.99999999999976,2.99999999999995,2.3301724010356857,1.6603448020713962,1.1254310025891439,0.8603448020709905,0.9999999999990088,1.0000000000005898,1.6193793562711605,2.553741472438176,3.578413910469891,4.468724232334324,4.9999999999999005,4.999999999999744,5.024310173880679,4.700689308176038,4.264913355530808,3.952758268590401,3.9999999999997726,4.000000000002785,4.555379948208554,5.41950129485997,6.305932667408456,6.928242693305947,7.000000000001933,7.0,6.330170033295872,5.1093055123935756,3.6233559748422977,2.1582709581939525,0.9999999999995453,1.000000000002501,0.36393991861154973,0.18327665557058026,0.3206434332247454,0.6386734739202211,1.0000000000015916,0.9999999999983231,1.2940702922659852,1.5175878653328425,1.6940702922657351,1.8470351461317023,1.9999999999976694,1.9999999999991758,2.1717789123186932,2.3623718830917326,2.5670753977049188,2.7811859415448765,2.999999999998195]
haskellSol = [5.000000000000245,4.631751757306844,4.210802811690759,3.6844524602292945,2.99999999999976,2.99999999999995,2.1574454310023485,1.3675915649273875,0.8939419163884725,0.9999999999990088,1.0000000000005898,1.8322165186832322,3.0688309285979614,4.271029874213795,4.999999999999872,4.999999999999744,4.966813494265466,4.482084720680746,4.006313586755368,3.9999999999998863,4.000000000002785,4.753654504257327,5.877830188681628,6.813090778766423,7.000000000001933,7.0,6.065443488715914,4.381594524601496,2.506948298186444,0.9999999999995453,1.000000000002501,0.2814465408828255,0.22079171291363764,0.5497410284892794,1.0000000000015916,0.9999999999983231,1.355645347759861,1.610238623749268,1.8097125878631743,1.9999999999975557,1.9999999999991758,2.2178470680715208,2.4632537920816304,2.7270336200503067,2.999999999998195]
print (len(haskellSol))
ans_xx = (f1d+f2d+f3d+f4d+f5d+f6d+f7d+f8d+f9d) #+f10)
plt.plot (f1d+f2d+f3d+f4d+f5d+f6d+f7d+f8d+f9d) #+f10)
plt.plot ([0,plen,2*plen,3*plen,4*plen,5*plen,6*plen,7*plen,8*plen],
[f1d[0],f2d[0],f3d[0],f4d[0],f5d[0],f6d[0],f7d[0],f8d[0],f9d[0]], ':o', color = "orange")
plt.plot (haskellSol, 'o', color = "green")
10 [0. 0.075 0.15 0.225 0.3 ] [0.3 0.375 0.45 0.525 0.6 ] 45
[<matplotlib.lines.Line2D at 0x7f06e2ccbc70>]
allS = [5.000000000000245,4.707931039585815,4.388879319274968,4.0158620791712885,3.561896559378359,2.99999999999976,2.99999999999995,2.3301724010356857,1.6603448020713962,1.1254310025891439,0.8603448020709905,0.9999999999990088,1.0000000000005898,1.6193793562711605,2.553741472438176,3.578413910469891,4.468724232334324,4.9999999999999005,4.999999999999744,5.024310173880679,4.700689308176038,4.264913355530808,3.952758268590401,3.9999999999997726,4.000000000002785,4.555379948208554,5.41950129485997,6.305932667408456,6.928242693305947,7.000000000001933,7.0,6.330170033295872,5.1093055123935756,3.6233559748422977,2.1582709581939525,0.9999999999995453,1.000000000002501,0.36393991861154973,0.18327665557058026,0.3206434332247454,0.6386734739202211,1.0000000000015916,0.9999999999983231,1.2940702922659852,1.5175878653328425,1.6940702922657351,1.8470351461317023,1.9999999999976694,1.9999999999991758,2.1717789123186932,2.3623718830917326,2.5670753977049188,2.7811859415448765,2.999999999998195]
plt.plot (allS, ':o', color = "green")
[<matplotlib.lines.Line2D at 0x7f06e2cfe970>]
fig = plt.figure()
ax1 = fig.add_axes([0.1, 0.5, 0.8, 0.4])
ax2 = fig.add_axes([0.1, 0.1, 0.8, 0.4])
ax1.plot(ec_301, ':o', color='orange',marker=".", markersize=5)
ax2.plot(solution_alphas, ':o', color='green',marker=".", markersize=5)
[<matplotlib.lines.Line2D at 0x7f06e2bebd90>]
# populationSize = 50 :: Int
# individualLen = 51::Int --101 :: Int -- polynomial order plus one
# alterPopFraction = 0.3 :: Double
# alterEltFraction = 0.05 :: Double --0.03 :: Double
# maxXValue = 3.0 :: Double
# generationCount = 1000 --00
# randSeed = 12323::Int -- 1111::Int --4455::Int -- 34567::Int --23456::Int --12345::Int --4391 --3221 --1111 -- 3121 --12345 --21311 --123 -- 12345 -- 1234
# maxValue = 1000 :: Double
# noiseLevel = 0.0 --0.007 :: Double -- about 2 percent
# stepsPerSec = 10 :: Float
# smoothWeight = 0.95
# accuracyWeight = 0.05
# maxInflections = (fromIntegral individualLen)/2.0::Double
# 10 coefs
# 9 xRanges
xr = [[0.0, 0.075, 0.15 ,0.225, 0.30],
[0.3, 0.375, 0.45 ,0.525, 0.60],
[0.6, 0.675, 0.75 ,0.825, 0.90],
[0.90, 0.975, 1.05 ,1.125, 1.20],
[1.20, 1.275, 1.35 ,1.425, 1.50],
[1.50, 1.575, 1.65 ,1.725, 1.80],
[1.80, 1.875, 1.95 ,2.025, 2.1],
[2.1, 2.175, 2.25 ,2.325, 2.4],
[2.40, 2.475, 2.55 ,2.625, 2.70]]
splineCoefs =\
[[0.6809008024547628,-5.352471023282419,3.7925218521195347e-13,24.32996800428968],[2.546619923378176,-24.009662232515016,62.190637364109165,-44.770740178053224],[-22.295600065556137,100.20143771215652,-144.8278625436774,70.23953754849492],[114.95984030053329,-357.3166968414753,363.52562029369045,-118.03953016904872],[-273.9029471653472,614.8402718232228,-446.6051869268906,106.99680517000165],[380.98111006026977,-694.9278426280114,426.5735560405987,-87.04291548944056],[-650.9115628718789,1024.8932789255696,-528.8826226002797,89.89341388850005],[759.7797862279035,-990.3800769312636,430.7713563791651,-62.432614520935715],[-700.3019831739266,834.7221348210246,-329.68789851762165,43.18672643695139],[589.8670408308051,-598.7990029620133,201.24585621683758,-22.36065069075972]]
#splinePairs =
#[SplinePair 0.0 0.6809008024544488,SplinePair 0.3 (-0.26793136841378823),SplinePair 0.6 0.8589721564887725,SplinePair 0.8999999999999999 1.7797480878585252,SplinePair 1.1999999999999997 5.684389181561089,SplinePair 1.4999999999999996 4.61000743273847,SplinePair 1.7999999999999994 4.5750317669719545,SplinePair 2.099999999999999 1.4948632259813541,SplinePair 2.399999999999999 1.042151199446214,SplinePair 2.699999999999999 6.733710789057884e-2,SplinePair 2.9999999999999987 0.9451692457892924]
#ecVals =
subsample_sol = np.array(solution_alphas[::6])
plt.plot(ans_xx,':o', color = "orange",markersize = 4)
plt.plot(subsample_sol*5.5, ':o',markersize = 4)
plt.plot ([0,plen,2*plen,3*plen,4*plen,5*plen,6*plen,7*plen,8*plen],
[f1d[0],f2d[0],f3d[0],f4d[0],f5d[0],f6d[0],f7d[0],f8d[0],f9d[0]], 'o', color = "red")
[<matplotlib.lines.Line2D at 0x7f06e2be47f0>]
subsample_sol = np.array(solution_alphas[::6])
fig9, ax9 = plt.subplots()
ax9.set_title ("EC vs Actual No Noise Response Curve")
ax9.plot(ans_xx,':o', color = "orange",markersize = 4,label="EC Sol")
ax9.plot(subsample_sol*5.5, ':o',markersize = 4, label = "Known Sol")
ax9.plot ([0,plen,2*plen,3*plen,4*plen,5*plen,6*plen,7*plen,8*plen],
[f1d[0],f2d[0],f3d[0],f4d[0],f5d[0],f6d[0],f7d[0],f8d[0],f9d[0]], 'o', color = "red", label = "EC Spline Pos")
ax9.legend()
#ax9.set_xlabel(r'$\Delta_i$', fontsize=15)
#ax9.set_ylabel(r'$\Delta_{i+1}$', fontsize=15)
#ax9.set_title('Volume and percent change')
ax9.set_xlabel( 'Pseudo Wavelength')
Text(0.5, 0, 'Pseudo Wavelength')
#Best guy -> 4.048659455579973e-6
bg = [0.2583382302328207,3.626041084001584e-2,0.5291385308389235,2.079623468591992,5.612860764140267,4.861354570987686,4.446104216252994,1.8184185557752086,0.7506778314830624,0.6619122409600563,4.782497499368079,-0.8572901144021609,2.4120847842264306,1.6007629547156865,-2.541755035400462,-0.3630980491894617,1.9885551235507388,2.008774557026396,-2.3135494581621487,0.43935452862606295,-0.3901394865074467,1.82177367643736,2.444557126525101,1.7617824456563094,-0.5433466523411205,2.375950982010881,5.5312969639141674e-2,-1.1734537460501537,-2.5906372946275584,2.2109796084366473,0.7908345512011739,0.6998828237977799,0.5504121114614919,3.1899329575202997,-0.25217225437093255,-0.7307755227414765,-0.8558348305189797,-1.877731697736756,-0.5991766044199482,-1.3977960126592597,-1.64219357729717,-1.3863214252990776,-0.15947863630994102,-0.17907537356308373,-1.1212682125929474,0.7818632983379034,-2.9955903395968813,-1.1368226344314984,1.4419737912305768,1.4381573104096055,-2.363030620619389]
# 5.5 hrs approx
plt.plot(solution_alphas, ':o', color='green',marker=".", markersize=5)
[<matplotlib.lines.Line2D at 0x7f06e2b13b20>]
# Stitch together
m2x = np.array(list(map (lambda x : [x],wnAnswers))) # Why did I have to do this?
print(m2x.shape)
raw301sN = np.append (wnInputs,m2x,axis=1)
print(fCases.shape)
print (wnInputs.shape)
(2696, 1) (2696, 302) (2696, 301)
# Scale
from sklearn import preprocessing
scaler301N = preprocessing.StandardScaler().fit(raw301sN)
scaled_301sN = scaler301N.transform(raw301sN)
scaled_301sN
array([[-0.16998473, -0.17147829, -0.17198631, ..., -0.42975773, -0.42743939, -0.09254587], [-0.85175612, -0.86374345, -0.87265059, ..., 1.20272339, 1.19750062, -0.98752192], [ 0.56246442, 0.59140529, 0.61835959, ..., -0.30589648, -0.3115256 , 0.24478691], ..., [ 1.732621 , 1.73598262, 1.74201102, ..., -0.24932618, -0.25943941, 1.10721124], [-0.71342013, -0.71819731, -0.72305177, ..., -0.01202794, -0.01612902, 0.76201013], [ 0.93092287, 0.9681667 , 1.00254087, ..., -0.96420591, -0.97060905, 0.45121197]])
# Write it out ..
np.savetxt("fcases_301sN.txt", scaled_301sN, delimiter=" ")
!pwd
/home/poliquin/projects/haskell/jayai02/jup_plot/v03
!cp /home/poliquin/projects/haskell/jayai02/jup_plot/v03/fcases_301sN.txt /home/poliquin/projects/haskell/spectral_gloss/v04d_hack_301_pareto_splines/v03
# No Noise Linear Algebra Solution
m,c,d,e = np.linalg.lstsq(nnInputs,nnAnswers,rcond=None)
plt.plot(solution_alphas,'--' ,markersize=3,color="orange")
plt.plot(m,'o',markersize=0.5)
[<matplotlib.lines.Line2D at 0x7f06e08eaaf0>]
# With Noise, Subsampled Linear Algebra Solution
# Subsample
wn_sub_inputs = list(map (lambda x: x[::20],wnInputs)) # every 20th
sub_solution = solution_alphas[::20] # every 20th
mn,cn,dn,en = np.linalg.lstsq(wn_sub_inputs,wnAnswers,rcond=None)
plt.plot(sub_solution*20,'-0' ,markersize=4,color="orange",label="Subsampled Real Solution")
plt.plot(mn,'-o',markersize=3,label='Subsampled Linear Algebra Solution')
plt.title ("Subsampled (301 -> 15) with Noisy Data Solution Comparison ")
plt.xlabel("Pseudo Wavelength")
plt.legend()
<matplotlib.legend.Legend at 0x7f06da7b99a0>
# With Noise, Subsampled Linear Algebra Solution
# Subsample
wn_sub_inputs = list(map (lambda x: x[::6],wnInputs)) # every 6th
sub_solution = solution_alphas[::6] # every 6th
mn,cn,dn,en = np.linalg.lstsq(wn_sub_inputs,wnAnswers,rcond=None)
plt.plot(sub_solution*20,'-0' ,markersize=4,color="orange",label="Subsampled Real Solution")
plt.plot(mn,'-o',markersize=3,label='Subsampled Linear Algebra Solution')
plt.title ("Subsampled (301 -> 51) with Noisy Data Solution Comparison ")
plt.xlabel("Pseudo Wavelength")
plt.legend()
<matplotlib.legend.Legend at 0x7f06da65f190>
#fig, ax = plt.subplots(5, 2, sharex='col', sharey='row')
fig, ax = plt.subplots(7, 2, figsize = (12,40),constrained_layout=True,)
#plt.subplots_adjust(wspace = 0.1, hspace = 0.6)
# axes are in a two-dimensional array, indexed by [row, col]
for i in range(7):
for j in range(2):
skip = ((i+1) + j) * 6
wn_sub_inputs = list(map (lambda x: x[::skip],wnInputs))
sub_solution = solution_alphas[::skip]
mn,cn,dn,en = np.linalg.lstsq(wn_sub_inputs,wnAnswers,rcond=None)
max_sol = max(sub_solution)
max_inputs = max(mn)
ax[i, j].plot(mn,'-o',markersize=3,label='Subsampled Linear Algebra Solution')
ax[i, j].plot(sub_solution*(max_inputs/max_sol),'-0' ,markersize=4,color="orange",label="Subsampled Real Solution")
ax[i, j].set_title("Approximate bSubsample Points -> " +
str(math.trunc(301/skip)))
fig.suptitle ("Real Solution vs Linear Algebra Least Sq Using Subsamples")
#fig
# wn_sub_inputs = list(map (lambda x: x[::6],wnInputs)) # every 6th
# sub_solution = solution_alphas[::6] # every 6th
# mn,cn,dn,en = np.linalg.lstsq(wn_sub_inputs,wnAnswers,rcond=None)
# plt.plot(sub_solution*20,'-0' ,markersize=4,color="orange",label="Subsampled Real Solution")
# plt.plot(mn,'-o',markersize=3,label='Subsampled Linear Algebra Solution')
# plt.title ("Subsampled (301 -> 51) with Noisy Data Solution Comparison ")
# plt.xlabel("Pseudo Wavelength")
# plt.legend()
# ax9.set_title ("EC vs Actual No Noise Response Curve")
# ax9.plot(ans_xx,':o', color = "orange",markersize = 4,label="EC Sol")
# ax9.plot(subsample_sol*5.5, ':o',markersize = 4, label = "Known Sol")
# ax9.plot ([0,plen,2*plen,3*plen,4*plen,5*plen,6*plen,7*plen,8*plen],
# [f1d[0],f2d[0],f3d[0],f4d[0],f5d[0],f6d[0],f7d[0],f8d[0],f9d[0]], 'o', color = "red", label = "EC Spline Pos")
# ax9.legend()
# #ax9.set_xlabel(r'$\Delta_i$', fontsize=15)
# #ax9.set_ylabel(r'$\Delta_{i+1}$', fontsize=15)
# #ax9.set_title('Volume and percent change')
# ax9.set_xlabel( 'Pseudo Wavelength')