[MUSIC] Hi, I'm David Brough from the School of Computational Science and Engineering here in Georgia Tech. And in the previous lesson we showed you how to install PyMKS, now we're going to show you how to actually use PyMKS through your Materials Data Science and Informatics. So, a few things that we get out of this lesson. The first thing I'm going to do is show you how to use PyMKS to compute two point statistics or spatial correlations. And the other thing we going to do is use PyMKS to create a structure property homogenization linkage. So in the previous video we showed you how to download and install PyMKS. So now I'm going to show you how to actually run some of the examples and how to use the code. So I'm going to go back to my anaconda prompt. And you'll notice here in my downloads I already have all of the source files here, so we're going to go to this directory called Notebooks in the Command prompt. Once I'm in the Notebooks directory, I'm going to type jupyter notebook and that should open a browser for you. So you can see here it's opened this browser and it has a list of files here. And these are the same files that are in the notebook's directory. So first we're going to look at is this checkerboard example. So in previous lessons we talked about two point statistics and how they're used to quantify structure. And this is an example of how we're going to use PyMKS to compute the two point statistics. So I'm going to go through here and execute some of the cells. So the first thing we're doing is importing PyMKS, as well as a few other libraries that we need. These percent signs are unique for iPython and they're not usually used if you're running a normal script. But these import statements are important. Okay, we've imported, the libraries that we need. So now we'll just go ahead and make we're going to use this make checkerboard microstructure to make a microstructure for us to look at for this example. So here's an example of [INAUDIBLE]. Here's a plot so you can see here that the size of this microstructure is 168 by 168. This first index here is the sample number. So in PyMKS, everything is essentially one large array and so we have essentially one sample. It is 168 by 168, so each one of these tiles has multiple cells inside, or voxels. So now we're going to go ahead and compute the autocorrelations of this microstructure. So here you can see, from pymks.stats we import the autocorrelate function. We also import the PrimitiveBasis because we're looking at discreet stage. I only have black and white faces. So I'm going to set my PrimitiveBasis equal to two. And then here's the outer correlate functions. So I'm going to pass the microstructure which was X, this basis. And in this case we're going to compute the periodic statistics. So I'm going to say that the first and the second axis are periodic. So we go on and compute those. And then again the plots here we can look at the statistics. So you can see here again that we see somethings that we expect at the origin. We should get the volume fractions so it's 50% of the microstructure is black and the same thing for the white because we have a checker board. The 50% of the microstructure is white, the volume fraction is in the center. It's also periodic so you get this periodic structure, in your statistics. So again, here we can look at the volume fraction and now let's go ahead and look at how to compute the cross-correlation. We're going to use the cross-correlate function. So they've already made this basis, so I'm going to use that again and get x as the microstructure. And then computing the periodic statistics again for the first two axis and we can plot that. And here's again the plot of the cross-correlation. So this time we see that the origin is 0 0. There's nothing there. So no two states can live at the same location. And so now we're going to look at the difference if we compute all the spatial statistics without making them periodic. So now we're going to import this correlate function and again we're not passing any axis that are going to be periodic. So we're only passing the micro structure in the basis so if we run that, then here we can go and actually look at the micro structures. And it's got a nice diagram for us that shows the non-periodic statistics. So they look very similar in this case because of the checker board but in other cases they may look very different. So that's it for this so it shows you how to compute two point statistics using PyMKS. The final example I want to show you is how to create a structure property homogenization linkage. And for that one we're going to click on this homogenization stress example. And rather than execute all the individual cells, like I did last time, I'm going to click at this Cell here at the top, and I'm going to click Run All. That's going to execute the entire pipeline for us, and it'll go through and talk through the code and what we actually did while it runs. So here again we do the initial imports like we did last time. There's no change there. Now we're going to use this make_elastic_stress_random function. So this does require the SFE files installed that we talked about in the previous lesson if it's not installed it won't work. But you can everything else after we generate the data should be the exact same using your own data. So here I got some thing that I specified in terms of young modulus for son's ratio as well as we're just looking at 2D examples here in this case. So here when I get back I get this x is going to be the microstructure and y is going to be their effective stress of every micro structure. So here we printed out the shapes, so x is a micro structure so we have 1200 of them and their size 20 by 21. And then here we have 1200 effective stress values, so just to take a look at some of the microstructures we just essentially have a few different classes this is what they look like. So some are longated in different directions and some are more query x, so to do that what we're looking for and we would print of the few stress values. So we have a look and see what that looks like. So now, we're going to go ahead and import the MKSHomogenizationModel as well as the PrimitiveBasis. So again, today, I only have two states, black and white. So I'm going to have two states, and the maximum value is 1 in the microstructure. The min is zero, so I'm going to go ahead and make my homogenization model, by passing the basis. We're looking at periodic microstructures, so I'm going to set these axis as periodic, and these are the spatial coordinations that I'm going to look at. So, essentially, this is saying the auto correlation of black, and the auto correlation of white. So here we looked this is the default values for the marginalization model. So the marginalization model essentially takes in our data our microstructure and effective value it's going to compute two point statistics do PCA as well as regression for us. So, the default it has five principle components of user PCA and one first order polynomial models so essentially just linear regression by default. There are some nice tools that we can use for PyMKS with scikit-learn, so we can leverage the machine to linear library. So here, I'm just going to show you we fit the data. So we have x and y again. So x was our microstructures, y was our affected values. So we changed the number of components to 40, we fit the data, and you can see here. When you look at the percent of the variance captured you can see that we're capturing well over 90% within the first few components. Now we're going to go ahead and use GridSearchCV, which is a nice tool from scikit-learn. That allows us to explore possible options for the number of components, as well as the order of the polynomial that we use. So here's the code so I set here that I want to change the degree of the polynomial. We're going to search between one and three and I'm going to look at principle components we look through either two components all at to eleven in this case. So after, here we'll go ahead and we'll get the results back in this GS. And here we've plotted the results. So here on the left, we have the R-Squared value, so we're looking for something that's light in color over here and then here is a Standard Deviation. So essentially we want to find an order of polynomial and the number of components that is light here, so it has a high R-Squared value and a low Standard Deviation. So if you look at the best model that it found using grid search CV is a second order polynomial with 11 principal components. And it has an R-squared value of 0.99, so pretty darn good. So here's one more view of the same data. So this is the R-squared values for the number of components and the order of the polynomial and the shaded region is the extended deviation. So here again we're finding their best model is with two principle components. Excuse me, with 11 principle components in a second order polynomial regression. So now we go and use the best model that we got. We can search cv, we're going to go ahead and fit the data again, so we got our model calibrated here, I'm generating more data. This is used to validate our model. Now if we calibrated the model we want to predict a new value for effective stress. Essentially we're going to have our model we're going to use the predict method and we're going to pass our new microstructures and that should give us back our predicted effective stress values. So you go down here we're looking, we're using the draw_components_scatter function. This shows us the PCA scores for each of the microstructures here. So the green ones are the microstructures that we use to fit the model. The orange ones are the ones that we're going to actually predict the effective stress for. And so we fit the model and I'm going to jump down here to the end and just show you the goodness of fit so you can see if everything is on the line that means we have a good model. So essentially we didn't over predict or under predict any of the values, so in this case with our toy data, this is a great model. In fact, as you obviously, you usually don't get something quite as clean as this. But this example is a good way to show the functionality that we have PyMKS, and what you can use it for in terms of generating these models to create effective linkages. So these same notebooks that I just showed are also available on the PyMKS website to look at. So if you're going to go to pymks.org, and click on examples you can see here, this is homogenization, the effective stiffness here so this is basically the same example. Just we're looking at it on the website. There are multiple examples for localization, homogenization as well as just quantifying structure if you don't have a property you're looking for. But your set to see how your structure changes or compares with other within a data set, and as well some examples with two point statistics. So we should be able now with this lesson and the previous lesson you should be able to download and install PyMKS as well be able to use it to create a process structure property linkages. So in summary, I hope that you're able to use PyMKS. To create process structure property linkages as well as to explore the differences in structure and compute two points statistics, thank you. [MUSIC]