{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "0c23d22c-e832-4d47-b582-2ed849c69ed6",
   "metadata": {},
   "source": [
    "Making Predictions with GlassPy\n",
    "===============================\n",
    "\n",
    "**Author:** Daniel R. Cassar\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ce04b0b3-cb71-40d6-a89b-21a4e3e3fb13",
   "metadata": {},
   "source": [
    "## Introduction\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "28541db8-51b9-4d77-94a3-4756835b6307",
   "metadata": {},
   "source": [
    "GlassPy provides three prediction models: `GlassNet`, `VITRIFY`, and `ViscNet`.\n",
    "\n",
    "-   `GlassNet` is a multitask deep neural network that predicts 85 glass properties and the temperature dependence of viscosity.\n",
    "-   `VITRIFY` is a classification model that estimates the probability of a given composition forming a glass.\n",
    "-   `ViscNet` is a physics-informed deep neural network designed specifically to predict the temperature dependence of viscosity.\n",
    "\n",
    "All three models were trained on data from the SciGlass database.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c3f37fec-2274-4ddd-98cd-18ad4aec09d6",
   "metadata": {},
   "source": [
    "## GlassNet basic usage\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1975ef62-b106-4e44-a6ec-86b7c7215b95",
   "metadata": {},
   "source": [
    "Below is a minimal example of how to load and use the GlassNet model.\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "bff48059-9a35-4e6e-aa9f-1c40d91e4dc8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>T0</th>\n",
       "      <th>T1</th>\n",
       "      <th>T2</th>\n",
       "      <th>T3</th>\n",
       "      <th>T4</th>\n",
       "      <th>T5</th>\n",
       "      <th>T6</th>\n",
       "      <th>T7</th>\n",
       "      <th>T8</th>\n",
       "      <th>T9</th>\n",
       "      <th>...</th>\n",
       "      <th>Cp1673K</th>\n",
       "      <th>TMaxGrowthVelocity</th>\n",
       "      <th>MaxGrowthVelocity</th>\n",
       "      <th>CrystallizationPeak</th>\n",
       "      <th>CrystallizationOnset</th>\n",
       "      <th>SurfaceTensionAboveTg</th>\n",
       "      <th>SurfaceTension1173K</th>\n",
       "      <th>SurfaceTension1473K</th>\n",
       "      <th>SurfaceTension1573K</th>\n",
       "      <th>SurfaceTension1673K</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1593.806265</td>\n",
       "      <td>1275.016879</td>\n",
       "      <td>1178.333278</td>\n",
       "      <td>1064.154863</td>\n",
       "      <td>956.53547</td>\n",
       "      <td>893.408138</td>\n",
       "      <td>857.634124</td>\n",
       "      <td>820.458542</td>\n",
       "      <td>779.195534</td>\n",
       "      <td>755.95825</td>\n",
       "      <td>...</td>\n",
       "      <td>1697.079401</td>\n",
       "      <td>1021.145482</td>\n",
       "      <td>-6.457833</td>\n",
       "      <td>921.905306</td>\n",
       "      <td>785.092585</td>\n",
       "      <td>0.309702</td>\n",
       "      <td>0.299307</td>\n",
       "      <td>0.321067</td>\n",
       "      <td>0.314809</td>\n",
       "      <td>0.318151</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1 rows × 85 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            T0           T1           T2           T3         T4          T5  \\\n",
       "0  1593.806265  1275.016879  1178.333278  1064.154863  956.53547  893.408138   \n",
       "\n",
       "           T6          T7          T8         T9  ...      Cp1673K  \\\n",
       "0  857.634124  820.458542  779.195534  755.95825  ...  1697.079401   \n",
       "\n",
       "   TMaxGrowthVelocity  MaxGrowthVelocity  CrystallizationPeak  \\\n",
       "0         1021.145482          -6.457833           921.905306   \n",
       "\n",
       "   CrystallizationOnset  SurfaceTensionAboveTg  SurfaceTension1173K  \\\n",
       "0            785.092585               0.309702             0.299307   \n",
       "\n",
       "   SurfaceTension1473K  SurfaceTension1573K  SurfaceTension1673K  \n",
       "0             0.321067             0.314809             0.318151  \n",
       "\n",
       "[1 rows x 85 columns]"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from glasspy.predict import GlassNet\n",
    "\n",
    "model = GlassNet()\n",
    "composition = \"Li2O(SiO2)2\"\n",
    "predictions = model.predict(composition)\n",
    "\n",
    "predictions"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5be83565-7512-4835-8b8b-842dfbe8d639",
   "metadata": {},
   "source": [
    "A composition can also be defined using a dictionary.\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "4626187f-69aa-4269-9dd5-3b13527d62ca",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>T0</th>\n",
       "      <th>T1</th>\n",
       "      <th>T2</th>\n",
       "      <th>T3</th>\n",
       "      <th>T4</th>\n",
       "      <th>T5</th>\n",
       "      <th>T6</th>\n",
       "      <th>T7</th>\n",
       "      <th>T8</th>\n",
       "      <th>T9</th>\n",
       "      <th>...</th>\n",
       "      <th>Cp1673K</th>\n",
       "      <th>TMaxGrowthVelocity</th>\n",
       "      <th>MaxGrowthVelocity</th>\n",
       "      <th>CrystallizationPeak</th>\n",
       "      <th>CrystallizationOnset</th>\n",
       "      <th>SurfaceTensionAboveTg</th>\n",
       "      <th>SurfaceTension1173K</th>\n",
       "      <th>SurfaceTension1473K</th>\n",
       "      <th>SurfaceTension1573K</th>\n",
       "      <th>SurfaceTension1673K</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1593.806265</td>\n",
       "      <td>1275.016879</td>\n",
       "      <td>1178.333278</td>\n",
       "      <td>1064.154863</td>\n",
       "      <td>956.53547</td>\n",
       "      <td>893.408138</td>\n",
       "      <td>857.634124</td>\n",
       "      <td>820.458542</td>\n",
       "      <td>779.195534</td>\n",
       "      <td>755.95825</td>\n",
       "      <td>...</td>\n",
       "      <td>1697.079401</td>\n",
       "      <td>1021.145482</td>\n",
       "      <td>-6.457833</td>\n",
       "      <td>921.905306</td>\n",
       "      <td>785.092585</td>\n",
       "      <td>0.309702</td>\n",
       "      <td>0.299307</td>\n",
       "      <td>0.321067</td>\n",
       "      <td>0.314809</td>\n",
       "      <td>0.318151</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1 rows × 85 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            T0           T1           T2           T3         T4          T5  \\\n",
       "0  1593.806265  1275.016879  1178.333278  1064.154863  956.53547  893.408138   \n",
       "\n",
       "           T6          T7          T8         T9  ...      Cp1673K  \\\n",
       "0  857.634124  820.458542  779.195534  755.95825  ...  1697.079401   \n",
       "\n",
       "   TMaxGrowthVelocity  MaxGrowthVelocity  CrystallizationPeak  \\\n",
       "0         1021.145482          -6.457833           921.905306   \n",
       "\n",
       "   CrystallizationOnset  SurfaceTensionAboveTg  SurfaceTension1173K  \\\n",
       "0            785.092585               0.309702             0.299307   \n",
       "\n",
       "   SurfaceTension1473K  SurfaceTension1573K  SurfaceTension1673K  \n",
       "0             0.321067             0.314809             0.318151  \n",
       "\n",
       "[1 rows x 85 columns]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "composition = {\n",
    "    \"SiO2\": 2,\n",
    "    \"Li2O\": 1,\n",
    "}\n",
    "predictions = model.predict(composition)\n",
    "\n",
    "predictions"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ce635734-077b-499f-98ce-f803e2443c74",
   "metadata": {},
   "source": [
    "GlassNet also accepts `pandas` DataFrames as input. Note that each row represents a material and that only columns related to chemical composition can be present in the DataFrame.\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "24605d70-fd1a-4799-8098-f59fffda8f2e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Li2O</th>\n",
       "      <th>Na2O</th>\n",
       "      <th>SiO2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Li2O  Na2O  SiO2\n",
       "0     1     0     2\n",
       "1     0     1     2\n",
       "2     1     1     2"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "\n",
    "data = [\n",
    "    [1, 0, 2],\n",
    "    [0, 1, 2],\n",
    "    [1, 1, 2],\n",
    "]\n",
    "\n",
    "df = pd.DataFrame(data, columns=[\"Li2O\", \"Na2O\", \"SiO2\"])\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "f066f1de-dc5a-4d02-8e52-3f31a4a3b5c2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>T0</th>\n",
       "      <th>T1</th>\n",
       "      <th>T2</th>\n",
       "      <th>T3</th>\n",
       "      <th>T4</th>\n",
       "      <th>T5</th>\n",
       "      <th>T6</th>\n",
       "      <th>T7</th>\n",
       "      <th>T8</th>\n",
       "      <th>T9</th>\n",
       "      <th>...</th>\n",
       "      <th>Cp1673K</th>\n",
       "      <th>TMaxGrowthVelocity</th>\n",
       "      <th>MaxGrowthVelocity</th>\n",
       "      <th>CrystallizationPeak</th>\n",
       "      <th>CrystallizationOnset</th>\n",
       "      <th>SurfaceTensionAboveTg</th>\n",
       "      <th>SurfaceTension1173K</th>\n",
       "      <th>SurfaceTension1473K</th>\n",
       "      <th>SurfaceTension1573K</th>\n",
       "      <th>SurfaceTension1673K</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1593.806528</td>\n",
       "      <td>1275.016816</td>\n",
       "      <td>1178.333278</td>\n",
       "      <td>1064.154806</td>\n",
       "      <td>956.535427</td>\n",
       "      <td>893.408194</td>\n",
       "      <td>857.634073</td>\n",
       "      <td>820.458542</td>\n",
       "      <td>779.195490</td>\n",
       "      <td>755.958250</td>\n",
       "      <td>...</td>\n",
       "      <td>1697.079401</td>\n",
       "      <td>1021.145445</td>\n",
       "      <td>-6.457834</td>\n",
       "      <td>921.905265</td>\n",
       "      <td>785.092630</td>\n",
       "      <td>0.309702</td>\n",
       "      <td>0.299307</td>\n",
       "      <td>0.321067</td>\n",
       "      <td>0.314809</td>\n",
       "      <td>0.318151</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1681.328886</td>\n",
       "      <td>1513.411183</td>\n",
       "      <td>1279.021743</td>\n",
       "      <td>1123.006920</td>\n",
       "      <td>1035.724060</td>\n",
       "      <td>954.737548</td>\n",
       "      <td>912.160878</td>\n",
       "      <td>849.827548</td>\n",
       "      <td>809.466760</td>\n",
       "      <td>781.277537</td>\n",
       "      <td>...</td>\n",
       "      <td>1484.994346</td>\n",
       "      <td>1064.050420</td>\n",
       "      <td>-6.311865</td>\n",
       "      <td>958.442333</td>\n",
       "      <td>906.941741</td>\n",
       "      <td>0.273919</td>\n",
       "      <td>0.307567</td>\n",
       "      <td>0.289976</td>\n",
       "      <td>0.286678</td>\n",
       "      <td>0.271214</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1436.034344</td>\n",
       "      <td>1233.614128</td>\n",
       "      <td>1101.165226</td>\n",
       "      <td>979.065643</td>\n",
       "      <td>921.910459</td>\n",
       "      <td>852.842167</td>\n",
       "      <td>785.283328</td>\n",
       "      <td>760.537597</td>\n",
       "      <td>724.843873</td>\n",
       "      <td>694.542212</td>\n",
       "      <td>...</td>\n",
       "      <td>1746.768638</td>\n",
       "      <td>1077.191654</td>\n",
       "      <td>-5.137043</td>\n",
       "      <td>864.736441</td>\n",
       "      <td>822.109318</td>\n",
       "      <td>0.293868</td>\n",
       "      <td>0.303260</td>\n",
       "      <td>0.318162</td>\n",
       "      <td>0.318062</td>\n",
       "      <td>0.293783</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>3 rows × 85 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            T0           T1           T2           T3           T4  \\\n",
       "0  1593.806528  1275.016816  1178.333278  1064.154806   956.535427   \n",
       "1  1681.328886  1513.411183  1279.021743  1123.006920  1035.724060   \n",
       "2  1436.034344  1233.614128  1101.165226   979.065643   921.910459   \n",
       "\n",
       "           T5          T6          T7          T8          T9  ...  \\\n",
       "0  893.408194  857.634073  820.458542  779.195490  755.958250  ...   \n",
       "1  954.737548  912.160878  849.827548  809.466760  781.277537  ...   \n",
       "2  852.842167  785.283328  760.537597  724.843873  694.542212  ...   \n",
       "\n",
       "       Cp1673K  TMaxGrowthVelocity  MaxGrowthVelocity  CrystallizationPeak  \\\n",
       "0  1697.079401         1021.145445          -6.457834           921.905265   \n",
       "1  1484.994346         1064.050420          -6.311865           958.442333   \n",
       "2  1746.768638         1077.191654          -5.137043           864.736441   \n",
       "\n",
       "   CrystallizationOnset  SurfaceTensionAboveTg  SurfaceTension1173K  \\\n",
       "0            785.092630               0.309702             0.299307   \n",
       "1            906.941741               0.273919             0.307567   \n",
       "2            822.109318               0.293868             0.303260   \n",
       "\n",
       "   SurfaceTension1473K  SurfaceTension1573K  SurfaceTension1673K  \n",
       "0             0.321067             0.314809             0.318151  \n",
       "1             0.289976             0.286678             0.271214  \n",
       "2             0.318162             0.318062             0.293783  \n",
       "\n",
       "[3 rows x 85 columns]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "predictions = model.predict(df)\n",
    "\n",
    "predictions"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ac52eb2d-34b7-44fa-a650-b6dd71c08d9f",
   "metadata": {},
   "source": [
    "GlassNet can also predict viscosity and the MYEGA viscosity equation parameters.\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "6c57a4dd-c47f-43e1-b03d-6fc668c715ce",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([3.44358113, 4.38299768, 2.72127358])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "predictions = model.predict_log10_viscosity(\n",
    "    T=1000,\n",
    "    composition=df,\n",
    ")\n",
    "\n",
    "predictions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "62ad2524-2f0f-4800-a796-5d857aa5ccbb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>log10_eta_infinity (Pa.s)</th>\n",
       "      <th>Tg_MYEGA (K)</th>\n",
       "      <th>fragility</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>-1.170492</td>\n",
       "      <td>697.863611</td>\n",
       "      <td>43.210780</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>-1.693836</td>\n",
       "      <td>710.538762</td>\n",
       "      <td>35.963149</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>-1.442656</td>\n",
       "      <td>642.028248</td>\n",
       "      <td>40.812665</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   log10_eta_infinity (Pa.s)  Tg_MYEGA (K)  fragility\n",
       "0                  -1.170492    697.863611  43.210780\n",
       "1                  -1.693836    710.538762  35.963149\n",
       "2                  -1.442656    642.028248  40.812665"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "viscosity_parameters = model.viscosity_parameters(df)\n",
    "\n",
    "viscosity_parameters"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b4c23ca8-4fb1-4887-973c-2d4dd7b19d03",
   "metadata": {},
   "source": [
    "## VITRIFY basic usage\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "feb3ef23-27e5-4c34-8d3d-5b7c2f219e23",
   "metadata": {},
   "source": [
    "Below is a minimal example of how to load and use the VITRIFY model. Like GlassNet, VITRIFY accepts strings, dictionaries, and `pandas` DataFrames as input. It returns `1` if the composition is predicted to form a glass under typical laboratory conditions, or `0` otherwise.\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "a4289376-6811-4d93-bce5-b54abf6757dc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 1, 1], dtype=int64)"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from glasspy.predict import VITRIFY\n",
    "\n",
    "model = VITRIFY()\n",
    "predictions = model.predict(df)\n",
    "\n",
    "predictions"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6e8b0865-18b3-4f2e-a6ca-8b65eb54539c",
   "metadata": {},
   "source": [
    "You can also retrieve the probability that the composition will form a glass, as estimated by the model.\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "5869143c-d348-456d-81a0-52ed470939f4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.97386932, 0.99601597, 0.78571427])"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "probabilities = model.predict_proba_glass(df)\n",
    "\n",
    "probabilities"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "39ea8ecd-0738-412c-a677-c8d755a983ad",
   "metadata": {},
   "source": [
    "You can change the decision threshold for predicting that a composition forms a glass. The default value is 0.5 and this can be changed with the `thres` parameter. Increasing this threshold will make the model more strict on which compositions it predicts that forms a glass.\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "b225d14e-f42f-4227-ae74-9751957a863c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 1, 0])"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "predictions = model.predict(df, thres=0.8)\n",
    "\n",
    "predictions"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1e812114-2624-4d5d-8a24-b0e520c298af",
   "metadata": {},
   "source": [
    "Two models are available, one trained on chemical composition (`CHEM`, the default option) and other trained on physicoquemical features (`FEATENG`). You can easily change the models with the `model` parameter. Both support the decision threshold tuning.\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "116d59b2-0d38-47ac-a34f-b190930938d9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 1, 1], dtype=int64)"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model = VITRIFY(model=\"FEATENG\")\n",
    "predictions = model.predict(df)\n",
    "\n",
    "predictions"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f5ef73a3-7d2a-4f36-8b51-74d7d9418a97",
   "metadata": {},
   "source": [
    "## ViscNet basic usage\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9d2a78e4-72dc-4158-8208-d7e74ffc7f74",
   "metadata": {},
   "source": [
    "ViscNet is used similarly to GlassNet. However, since GlassNet outperforms ViscNet on viscosity prediction, using GlassNet is generally recommended for that task. The minimal example below demonstrates how to load and use ViscNet.\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "3b7fcd46-963c-4b1f-b8f5-62e2fa9987b4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([5.1978884, 5.6581335, 6.0721507], dtype=float32)"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from glasspy.predict import ViscNet\n",
    "\n",
    "model = ViscNet()\n",
    "log10_viscosity = model.predict(T=1000, composition=df)\n",
    "\n",
    "log10_viscosity"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "a345ef4b-4590-4e01-a1ba-4e4932beab48",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[34.436733 29.760376 34.16934 ]\n"
     ]
    }
   ],
   "source": [
    "fragility = model.predict_fragility(df)\n",
    "\n",
    "print(fragility)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "4626f97c-a1e6-4d99-8e6a-137c6ed9ff8f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[748.3823  739.4691  788.51385]\n"
     ]
    }
   ],
   "source": [
    "Tg = model.predict_Tg(df)\n",
    "\n",
    "print(Tg)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.14.9"
  },
  "org": null
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
