In [1]:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
from ipywidgets import interact, FloatSlider, RadioButtons

amplitude_slider = FloatSlider(min=0.1, max=1.0, step=0.1, value=0.2)
color_buttons = RadioButtons(options=['blue', 'green', 'red'])
# decorate the plot function with an environment from the UIs:
@interact(amplitude=amplitude_slider, color=color_buttons)
def plot(amplitude, color):
    fig, ax = plt.subplots(figsize=(4, 3),
                       subplot_kw={'axisbg':'#EEEEEE',
                                   'axisbelow':True})

    ax.grid(color='w', linewidth=2, linestyle='solid')
    x = np.linspace(0, 10, 1000)
    ax.plot(x, amplitude * np.sin(x), color=color,
        lw=5, alpha=0.4)
    ax.set_xlim(0, 10)
    ax.set_ylim(-1.1, 1.1)



In [2]:
import numpy as np
import scipy.io
import scipy.optimize
from scipy import stats
import matplotlib.pyplot as plt
from matplotlib import gridspec
from ipywidgets import interact, FloatSlider, RadioButtons, IntSlider         #NEED THIS LINE (can use float numbers, predefined buttons or integers as well as many others for the widgets)
import pandas
import math
from sklearn.cross_validation import train_test_split
from sklearn import metrics
from sklearn.tree import DecisionTreeRegressor
from sklearn.ensemble import RandomForestRegressor
%matplotlib inline

def myround(x, base):
    return (float(base) * round(float(x)/float(base)))

params = {
    'lines.markersize' : 3,
    'axes.labelsize': 10,
    'font.size': 10,
    'legend.fontsize': 10,
    'xtick.labelsize': 10,
    'ytick.labelsize': 10,
    'text.usetex': False,
    
   }


#plp.rcParams.update(params)
plt.rcParams.update(params)
Ht2 = np.loadtxt('./data/MABr.1.Ht.txt',skiprows=0, dtype=np.float64)
Po2 = np.loadtxt('./data/MABr.1.Po.txt',skiprows=0, dtype=np.float64)
Ph2 = np.loadtxt('./data/MABr.1.Ph.txt',skiprows=0, dtype=np.float64)
Am2 = np.loadtxt('./data/MABr.1.Am.txt',skiprows=0, dtype=np.float64)
Pl2 = np.loadtxt('./data/MABr.1.Pl.txt',skiprows=0, dtype=np.float64)

# flatten the images
Ht2_flat = Ht2.flatten()
Po2_flat = Po2.flatten()
Ph2_flat = Ph2.flatten()
Am2_flat = Am2.flatten()
Pl2_flat = Pl2.flatten()

plt.show()
X = [Ht2_flat, Po2_flat, Ph2_flat, Am2_flat]
X = np.array(X).T
Y = np.array(Pl2_flat).T


Xtrain = np.array([Ht2_flat[0:31625], Po2_flat[0:31625], Ph2_flat[0:31625], Am2_flat[0:31625]]).T
Xtest = np.array([Ht2_flat[31625:], Po2_flat[31625:], Ph2_flat[31625:], Am2_flat[31625:]]).T
Ytrain = np.array(Pl2_flat[0:31625])
Ytest = np.array(Pl2_flat[31625:])

depth_slider = IntSlider(min=1, max=20, step=1, value=2) #define the slider (set a min and max value, the step size for integers, and the default open value)
@interact(Depth=depth_slider,continuous_update=False)    # allow it to be interactive and choose the variable the slider is changing. Tell it whether or not to continuously update or not

def plot(Depth):#,Xtrain,Xtest,Ytrain,Ytest,Ht2): #need this line as well for the variable to change..
    clf = DecisionTreeRegressor(max_depth=Depth)
    clf.fit(Xtrain, Ytrain)
    Ypred = clf.predict(Xtest)

    x = Ht2.shape[0]
    y = Ht2.shape[1]
    k=0
    merge = np.concatenate((Ytrain,Ypred))
    Pl_predict = np.zeros((x,y))
    for i in range(x):
        for j in range (y):
            Pl_predict[i,j] = merge[k]
            k = k + 1
        
    fig = plt.figure(figsize=(8,6))
    pl_ax = fig.add_subplot(121)
    pl_ax.imshow(Pl_predict, cmap='viridis')
    pl_ax.set_title('Photoluminescence')
    pl_ax.axis('off')
    pl_ax = fig.add_subplot(122)
    cax = pl_ax.imshow(Pl2, cmap='viridis')
    pl_ax.set_title('Photoluminescence')
    pl_ax.axis('off')

    fig.colorbar(cax)



In [5]:
###User specified parameters
inputs = [Ht2, Po2, Ph2, Am2]
x7x7 = [-3, -2, -1, 0, 1, 2, 3]
x5x5 = [-2, -1, 0, 1, 2]
x3x3 = [-1, 0, 1]
scores = [0.11, 0.108, 0.105]

stuff = [x3x3, x5x5, x7x7]
morestuff = ['3x3', '5x5', '7x7']
depths = 1
trees = 1

###Create training and testing arrays
x = Po2.shape[0]/2
x2 = Po2.shape[0]
y = Po2.shape[1]

fig = plt.figure(figsize=(10,10))  #### WHERE DOES HE PLUG IN THE DATA? (IMSHOW?)

for wes in range(3):
    pixelContext = stuff[wes]
    print(pixelContext)
    Pl_predict = np.load('%s.npy' %(morestuff[wes]))
    print(Pl_predict)
    if wes == 2:
        pl_ax.text(-130,-50,'Predictions (array, error)', size=30)#.set_position([.5, 1.2])
        pl_ax.text(-130,280, 'Larger feature vector, lower error $\longrightarrow$')
    pl_ax = fig.add_subplot(1,4,(wes+1))

    pl_ax.imshow(Pl_predict.T, cmap='viridis')
    #pl_ax.set_title('%s Feature Vector, score: %s' %(morestuff[wes],scores[wes]), size=24)
    #pl_ax.set_ylabel('$\longleftarrow$ Trees', size=30)
    #pl_ax.set_xlabel('Depth $\longrightarrow$', size=30)
    pl_ax.axes.get_xaxis().set_ticks([])
    pl_ax.axes.get_yaxis().set_ticks([])
    pl_ax.set_title('%s, %s' %(morestuff[wes],scores[wes]), size=24)
pl_ax2 = fig.add_subplot(1,4,4)

pl_ax2.set_title('Actual', size=30).set_position([.5, 1.1])
pl_ax2.imshow(Pl2[Pl2.shape[0]/2:,:].T, cmap='viridis')
pl_ax2.axes.get_xaxis().set_ticks([])
pl_ax2.axes.get_yaxis().set_ticks([])
fig.subplots_adjust(left=None, bottom=None, right=None, top=None,\
                    wspace=None, hspace=None)
fig.savefig(filename='vector_variation_small_multiple', bbox_inches='tight')


[-1, 0, 1]
[[ 0.82506654  0.82506654  0.82506654 ...,  0.25681795  0.40159931
   0.94527766]
 [ 0.87039755  0.81257592  0.82506654 ...,  0.30119988  0.31781255
   0.89100541]
 [ 0.92566733  0.7972584   0.82506654 ...,  0.31933057  0.28625636
   0.77883086]
 ..., 
 [ 0.82506654  0.77039379  0.78719036 ...,  0.48061624  0.39385823
   0.41222563]
 [ 0.82506654  0.82278013  0.81779563 ...,  0.55264523  0.48390851
   0.52448299]
 [ 0.91169985  1.05721516  0.95169887 ...,  0.61327787  0.56276789
   0.54957752]]
[-2, -1, 0, 1, 2]
[[ 0.81510585  0.82737715  0.83549423 ...,  0.38494496  0.34692825
   0.84747505]
 [ 0.829637    0.82517173  0.83549423 ...,  0.36802551  0.22395782
   1.04249592]
 [ 0.85975313  0.83246453  0.83549423 ...,  0.21303331  0.28368417
   1.14908353]
 ..., 
 [ 0.74675065  0.6902758   0.66858342 ...,  0.54575525  0.25447541
   0.82806944]
 [ 0.80960071  0.7112819   0.70705159 ...,  0.46349079  0.41393726
   0.47251732]
 [ 0.99979107  0.91082748  0.9017474  ...,  0.66582574  0.36795831
   0.36641786]]
[-3, -2, -1, 0, 1, 2, 3]
[[ 0.82659284  0.84034195  0.8408451  ...,  0.33735912  0.31974441
   0.53585238]
 [ 0.81632078  0.82646789  0.8408451  ...,  0.34448387  0.26063191
   0.62934531]
 [ 0.82810164  0.81428095  0.82307364 ...,  0.27963785  0.23722135
   0.69881945]
 ..., 
 [ 0.60505016  0.56929589  0.57285902 ...,  1.18563203  1.10408698
   0.52691698]
 [ 0.65344019  0.60643036  0.64913712 ...,  0.97614303  1.07126201
   0.53218629]
 [ 0.82472092  0.75652227  0.69972937 ...,  0.53094708  0.53160999
   0.51669455]]
C:\Users\Garrett\Miniconda3\lib\site-packages\ipykernel\__main__.py:40: VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future

In [ ]: