In [ ]:
%matplotlib inline
%load_ext autoreload
%autoreload 2

import numpy as np
import matplotlib.pyplot as plt

In [ ]:
from pymks.datasets import make_elastic_stress_random
sample_size = 200
grain_size = [(15, 2), (2, 15), (7, 7), (8, 3), (3, 9), (2, 2)]
n_samples = [sample_size] * 6
elastic_modulus = (410, 200)
poissons_ratio = (0.28, 0.3)
macro_strain = 0.001
size = (21, 21)

X, y =

In [ ]:
from pymks.tools import draw_microstructures
X_examples = X[::sample_size]

In [ ]:


In [ ]:
from pymks import MKSHomogenizationModel
from pymks import PrimitiveBasis

prim_basis = 
model =

In [ ]:
model.n_components = 40
model.fit

In [ ]:
from pymks.tools import draw_component_variance

In [ ]:
from sklearn.cross_validation import train_test_split

flat_shape = (X.shape[0],) + (np.prod(X.shape[1:]),)

In [ ]:
from sklearn.grid_search import GridSearchCV

params_to_tune = {'degree': np.arange(1, 4), 'n_components': np.arange(1, 8)}
fit_params = {'size': X[0].shape, 'periodic_axes': [0, 1]}
gs =

In [ ]:
from pymks.tools import draw_gridscores_matrix

draw_gridscores_matrix

In [ ]:
print('Order of Polynomial'), (gs.best_estimator_.degree)
print('Number of Components'), (gs.best_estimator_.n_components)
print('R-squared Value'), (gs.score(X_test, y_test))

In [ ]:
from pymks.tools import draw_gridscores

gs_deg_1 = [x for x in gs.grid_scores_ \
            if x.parameters['degree'] == 1][2:-1]
gs_deg_2 = [x for x in gs.grid_scores_ \
            if x.parameters['degree'] == 2][2:-1]
gs_deg_3 = [x for x in gs.grid_scores_ \
            if x.parameters['degree'] == 3][2:-1]

draw_gridscores([gs_deg_1,  gs_deg_2, gs_deg_3], 'n_components',
                data_labels=['1st Order', '2nd Order', '3rd Order'],
                colors=['#f46d43', '#1a9641', '#762a83'],
                param_label='Number of Components', score_label='R-Squared')

In [ ]:
model = gs.best_estimator_
model.fit(X, y, periodic_axes=[0, 1])

In [ ]:
test_sample_size = 20
n_samples = [test_sample_size] * 6
X_new, y_new =

In [ ]:
y_predict =

In [ ]:
from pymks.tools import draw_components

draw_components([model.reduced_fit_data[:, :2],
                 model.reduced_predict_data[:, :2]],
                ['Training Data', 'Testing Data'])

In [ ]:
from sklearn.metrics import r2_score
print('R-squared'), (model.score(X_new, y_new, periodic_axes=[0, 1]))

In [ ]:
# Goodness of fit graph

from pymks.tools import draw_goodness_of_fit

fit_data = 
pred_data = 
draw_goodness_of_fit(fit_data, pred_data, ['Training Data', 'Testing Data'])