{ "cells": [ { "cell_type": "markdown", "id": "2fad641c", "metadata": {}, "source": [ "[](https://colab.research.google.com/github/usnistgov/AFL-agent/blob/main/docs/source/how-to/autosas_model_selection.ipynb)\n", "\n", "# Do Model Selection with AutoSAS\n" ] }, { "cell_type": "markdown", "id": "ced056ca", "metadata": {}, "source": [ "## Google Colab Setup\n", "\n", "Only uncomment and run the next cell if you are running this notebook in Google Colab or if don't already have the AFL-agent package installed." ] }, { "cell_type": "code", "execution_count": null, "id": "5543936a", "metadata": {}, "outputs": [], "source": [ "# !pip install git+https://github.com/usnistgov/AFL-agent.git" ] }, { "cell_type": "markdown", "id": "607446da", "metadata": {}, "source": [ "## Getting Started\n", "\n", "First, let's import the necessary packages and load our example dataset:" ] }, { "cell_type": "code", "execution_count": 1, "id": "0a3a2890", "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "\n", "from AFL.double_agent import *\n", "from AFL.double_agent.AutoSAS import AutoSAS\n" ] }, { "cell_type": "markdown", "id": "c7496ebc", "metadata": {}, "source": [ "Next, let's load the example dataset. We'll subselect only part of the dataset to work with" ] }, { "cell_type": "code", "execution_count": 2, "id": "6a0749bd", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
<xarray.Dataset> Size: 49kB\n", "Dimensions: (sample: 30, q: 100)\n", "Coordinates:\n", " * q (q) float64 800B 0.001 0.001072 0.00115 ... 0.8697 0.9326 1.0\n", "Dimensions without coordinates: sample\n", "Data variables:\n", " I (sample, q) float64 24kB 5.465e+03 4.598e+03 ... 1.1 1.002\n", " dI (sample, q) float64 24kB 545.9 429.3 342.6 ... 0.09923 0.09923\n", " model (sample) object 240B 'surface_fractal' ... 'mass_fractal'
<xarray.Dataset> Size: 202kB\n", "Dimensions: (sample: 30, q: 100, models: 3,\n", " surface_fractal_params: 3,\n", " mass_fractal_params: 3, polymer_params: 3,\n", " fit_q_surface_fractal: 100,\n", " fit_q_mass_fractal: 100, fit_q_polymer: 100)\n", "Coordinates:\n", " * q (q) float64 800B 0.001 0.001072 ... 0.9326 1.0\n", " * models (models) <U15 180B 'surface_fractal' ... 'poly...\n", " * surface_fractal_params (surface_fractal_params) <U26 312B 'surface_fr...\n", " * mass_fractal_params (mass_fractal_params) <U23 276B 'mass_fractal_...\n", " * polymer_params (polymer_params) <U18 216B 'polymer_scale' ......\n", " * fit_q_surface_fractal (fit_q_surface_fractal) float64 800B 0.001 ......\n", " * fit_q_mass_fractal (fit_q_mass_fractal) float64 800B 0.001 ... 1.0\n", " * fit_q_polymer (fit_q_polymer) float64 800B 0.001 ... 1.0\n", "Dimensions without coordinates: sample\n", "Data variables: (12/18)\n", " I (sample, q) float64 24kB 5.465e+03 ... 1.002\n", " dI (sample, q) float64 24kB 545.9 429.3 ... 0.09923\n", " model (sample) object 240B 'surface_fractal' ... 'ma...\n", " sas_fit_sample (sample) int64 240B 0 1 2 3 4 ... 25 26 27 28 29\n", " fit_all_chisq (sample, models) float64 720B 1.023 ... 27.2\n", " probabilities (sample, models) float64 720B 0.01182 ... 0.00...\n", " ... ...\n", " fit_I_surface_fractal (sample, fit_q_surface_fractal) float64 24kB 5...\n", " residuals_surface_fractal (sample, fit_q_surface_fractal) float64 24kB -...\n", " fit_I_mass_fractal (sample, fit_q_mass_fractal) float64 24kB 956....\n", " residuals_mass_fractal (sample, fit_q_mass_fractal) float64 24kB -8.2...\n", " fit_I_polymer (sample, fit_q_polymer) float64 24kB 6.219 ......\n", " residuals_polymer (sample, fit_q_polymer) float64 24kB -10.0 ......
<xarray.Dataset> Size: 205kB\n", "Dimensions: (sample: 30, q: 100, models: 3,\n", " surface_fractal_params: 3,\n", " mass_fractal_params: 3, polymer_params: 3,\n", " fit_q_surface_fractal: 100,\n", " fit_q_mass_fractal: 100, fit_q_polymer: 100)\n", "Coordinates:\n", " * q (q) float64 800B 0.001 0.001072 ... 0.9326 1.0\n", " * models (models) <U15 180B 'surface_fractal' ... 'poly...\n", " * surface_fractal_params (surface_fractal_params) <U26 312B 'surface_fr...\n", " * mass_fractal_params (mass_fractal_params) <U23 276B 'mass_fractal_...\n", " * polymer_params (polymer_params) <U18 216B 'polymer_scale' ......\n", " * fit_q_surface_fractal (fit_q_surface_fractal) float64 800B 0.001 ......\n", " * fit_q_mass_fractal (fit_q_mass_fractal) float64 800B 0.001 ... 1.0\n", " * fit_q_polymer (fit_q_polymer) float64 800B 0.001 ... 1.0\n", "Dimensions without coordinates: sample\n", "Data variables: (12/21)\n", " I (sample, q) float64 24kB 5.465e+03 ... 1.002\n", " dI (sample, q) float64 24kB 545.9 429.3 ... 0.09923\n", " model (sample) object 240B 'surface_fractal' ... 'ma...\n", " sas_fit_sample (sample) int64 240B 0 1 2 3 4 ... 25 26 27 28 29\n", " fit_all_chisq (sample, models) float64 720B 1.023 ... 27.2\n", " probabilities (sample, models) float64 720B 0.01182 ... 0.00...\n", " ... ...\n", " residuals_mass_fractal (sample, fit_q_mass_fractal) float64 24kB -8.2...\n", " fit_I_polymer (sample, fit_q_polymer) float64 24kB 6.219 ......\n", " residuals_polymer (sample, fit_q_polymer) float64 24kB -10.0 ......\n", " BestChiSq_labels (sample) int64 240B 0 1 0 1 2 0 0 ... 2 1 2 1 2 1\n", " BestChiSq_ChiSq (sample) float64 240B 1.023 0.9502 ... 1.086\n", " BestChiSq_label_names (sample) <U15 2kB 'surface_fractal' ... 'mass_...