fuzzy-rules-generator/density_fuzzy.ipynb

957 lines
220 KiB
Plaintext
Raw Normal View History

2024-11-01 11:04:05 +04:00
{
"cells": [
{
"cell_type": "code",
"execution_count": 7,
"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>T</th>\n",
" <th>Al2O3</th>\n",
" <th>TiO2</th>\n",
" <th>Density</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>20</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>1.06250</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>25</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>1.05979</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>35</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>1.05404</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" T Al2O3 TiO2 Density\n",
"0 20 0.0 0.0 1.06250\n",
"1 25 0.0 0.0 1.05979\n",
"2 35 0.0 0.0 1.05404"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"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>T</th>\n",
" <th>Al2O3</th>\n",
" <th>TiO2</th>\n",
" <th>Density</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>30</td>\n",
" <td>0.00</td>\n",
" <td>0.0</td>\n",
" <td>1.05696</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>55</td>\n",
" <td>0.00</td>\n",
" <td>0.0</td>\n",
" <td>1.04158</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>25</td>\n",
" <td>0.05</td>\n",
" <td>0.0</td>\n",
" <td>1.08438</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" T Al2O3 TiO2 Density\n",
"0 30 0.00 0.0 1.05696\n",
"1 55 0.00 0.0 1.04158\n",
"2 25 0.05 0.0 1.08438"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import pandas as pd\n",
"\n",
"density_train = pd.read_csv(\"data/density_train.csv\", sep=\";\", decimal=\",\")\n",
"density_test = pd.read_csv(\"data/density_test.csv\", sep=\";\", decimal=\",\")\n",
"\n",
"display(density_train.head(3))\n",
"display(density_test.head(3))"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"c:\\Users\\user\\Projects\\python\\fuzzy\\.venv\\Lib\\site-packages\\skfuzzy\\control\\fuzzyvariable.py:125: UserWarning: FigureCanvasAgg is non-interactive, and thus cannot be shown\n",
" fig.show()\n"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAkAAAAGyCAYAAAAMKHu5AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAACJKUlEQVR4nOzdd1RU19rH8e/QQQFB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q8n+K3dZdyJa7ThCCCGKsPhH8bwf+D7n7p5jmd8yurp3VTuSXpLCqIC1rebCmw3KM3XrJaLvp6odRwghRBEUmRhJr+29uPfoHqs6rqJxmcZqR9JbUhgVgs+7euNgY8mo386j1cqQmhBCiMJzJu4MvXf0pph5MX7u8jNVS1VVO5Jek8KoENhaW/Dl67U4eu0ePx29rnYcIYQQRUTQjSA+2vURng6e/NjpR1yLu6odSe9JYVRImnk40qdJRWYFhhIZ/1DtOEIIIYzc2strGRo8lDZubVjRfgV2lnZqRzIIUhgVojGdquFiZ83w9WfRyJCaEEKIAqBVtMw/OZ+Zx2fSx7sPs1vOxtLMUu1YBkMKo0JkY2nO3DdqcyY6gW8PXlM7jhBCCCOToclgzMExrApZxeiGoxnRcASmJvKrPjfkbBWyhpVK0a95ZebtusKV2GS14wghhDASSRlJBOwJIOhGEHNbzaWXdy+1IxkkKYxUMLxDVdx
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAkYAAAGyCAYAAAABNgv+AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAACEXElEQVR4nO3dd1gUZ9fH8e/SRRFUmgUroIK9Ya8odpMn7UlsKZoEjb2XWBJr7LHHFBONiZpEY8WCYo+9oiAoChZAVJpI2533jzX4+qgJIDC7y/lcF1fiMjvz2wGWw9z3nFujKIqCEEIIIYTATO0AQgghhBCGQgojIYQQQognpDASQgghhHhCCiMhhBBCiCekMBJCCCGEeEIKIyGEEEKIJ6QwEkIIIYR4QgojIYQQQognpDASQgghhHii0BVGiqKQmJiINPwWQgghxP9StTA6ePAg3bp1o0yZMmg0GjZv3vyvzwkKCqJevXpYW1vj7u7O6tWrc3TMpKQk7O3tSUpKyl1oIYQQQpgs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ascRQghRSATeDKT/7v54OHjwY6cfcS3qqnYkgyeFUQFp5u5InyYVmBUQQkTcI7XjCCGEMHHrrqxjWNAw2ri1YWX7lRS3Kq52JKMghVEBGtupGi7FbRix4RxaGVITQgiRD3SKjvmn5jPzxEz6ePVhdsvZWJlbqR3LaEhhVIBsrSyY+1ZtzkbF8+2h62rHEUIIYWLStemMPTSW1cGrGdNwDCMbjsRMI7/qc0LOVgFrWLEk/ZpXYt7uq1yNSVI7jhBCCBORmJ6I/15/Am8GMrfVXHp59VI7klGSwkgFIzp
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAjcAAAGyCAYAAAAYveVYAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAACOp0lEQVR4nOzdd1RU19rH8e/QQQGxgSiKvQJ2FKyxd0yixphoEtOMsRsrYsMaNcbYEmNi7k1Tk4g19q5YYsHeCzawAipSZ94/5g03xEaZYU95PmvNijmcOec3wxx42HufvTU6nU6HEEIIIYSFsFEdQAghhBDCkKS4EUIIIYRFkeJGCCGEEBZFihshhBBCWBQpboQQQghhUaS4EUIIIYRFkeJGCCGEEBZFihshhBBCWBQpboQQQghhUayuuNHpdCQkJCATMwshhBCWSWlxs3PnTjp06IC3tzcajYaIiIiXPmf79u3UrFkTR0dHypUrx5IlS7J1zocPH+Lu7s7Dhw9zFloIIYQQJk1pcfP48WMCAgKYN29elva/fPky7dq1o2nTphw9epSBAwfy/vvvs2HDBiMnFUIIIYS50JjKwpkajYYVK1YQEhLy3H2GDx/O2rVrOXHiRMa2N954g7i4ONavX5+l8yQkJODu7k58fDxubm65jS2EEEKIPKDT6dBoNFna16zG3ERGRtK8efNM21q1akVkZORzn5OcnExCQkKmB8Cj5DSjZhV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H8t1o9h6fSVvsAxBzV7QrkW+qUhEu+rTiOEyVp2dhn7b+1nfNB4XB1cleWQ4sZANBoNU171IzVdy5iVJ1THEcI03b8Em8Kgdm8o+4r
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import numpy as np\n",
"from skfuzzy import control as ctrl\n",
"import skfuzzy as fuzz\n",
"\n",
"# temp = ctrl.Antecedent(np.arange(20, 70, 1), \"temp\")\n",
"# al = ctrl.Antecedent(np.arange(0, 0.3, 0.001), \"al\")\n",
"# ti = ctrl.Antecedent(np.arange(0, 0.3, 0.001), \"ti\")\n",
"# density = ctrl.Consequent(np.arange(1, 1.3, 0.00001), \"density\")\n",
"\n",
"temp = ctrl.Antecedent(density_train[\"T\"].sort_values().unique(), \"temp\")\n",
"al = ctrl.Antecedent(density_train[\"Al2O3\"].sort_values().unique(), \"al\")\n",
"ti = ctrl.Antecedent(density_train[\"TiO2\"].sort_values().unique(), \"ti\")\n",
"density = ctrl.Consequent(np.arange(1.03, 1.22, 0.0001), \"density\")\n",
"\n",
"temp.automf(3, variable_type=\"quant\")\n",
"temp.view()\n",
"al.automf(3, variable_type=\"quant\")\n",
"al.view()\n",
"ti.automf(3, variable_type=\"quant\")\n",
"ti.view()\n",
"density.automf(3, variable_type=\"quant\")\n",
"# density[\"low\"] = fuzz.trimf(density.universe, [1.03, 1.06, 1.09])\n",
"# density[\"average\"] = fuzz.trimf(density.universe, [1.06, 1.14, 1.18])\n",
"# density[\"high\"] = fuzz.trimf(density.universe, [1.09, 1.18, 1.22])\n",
"density.view()"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"rule11 = ctrl.Rule(\n",
" temp[\"low\"] & al[\"low\"] & ti[\"low\"],\n",
" density[\"low\"],\n",
")\n",
"rule12 = ctrl.Rule(\n",
" temp[\"average\"] & al[\"low\"] & ti[\"low\"],\n",
" density[\"low\"],\n",
")\n",
"rule13 = ctrl.Rule(\n",
" temp[\"high\"] & al[\"low\"] & ti[\"low\"],\n",
" density[\"low\"],\n",
")\n",
"\n",
"rule21 = ctrl.Rule(\n",
" temp[\"low\"] & al[\"average\"] & ti[\"low\"],\n",
" density[\"average\"],\n",
")\n",
"rule22 = ctrl.Rule(\n",
" temp[\"average\"] & al[\"average\"] & ti[\"low\"],\n",
" density[\"low\"],\n",
")\n",
"rule23 = ctrl.Rule(\n",
" temp[\"high\"] & al[\"average\"] & ti[\"low\"],\n",
" density[\"low\"],\n",
")\n",
"\n",
"rule31 = ctrl.Rule(\n",
" temp[\"low\"] & al[\"high\"] & ti[\"low\"],\n",
" density[\"high\"],\n",
")\n",
"rule32 = ctrl.Rule(\n",
" temp[\"low\"] & al[\"high\"] & ti[\"low\"],\n",
" density[\"high\"],\n",
")\n",
"rule33 = ctrl.Rule(\n",
" temp[\"high\"] & al[\"high\"] & ti[\"low\"],\n",
" density[\"average\"],\n",
")\n",
"\n",
"rule41 = ctrl.Rule(\n",
" temp[\"low\"] & al[\"low\"] & ti[\"average\"],\n",
" density[\"average\"],\n",
")\n",
"rule42 = ctrl.Rule(\n",
" temp[\"average\"] & al[\"low\"] & ti[\"average\"],\n",
" density[\"average\"],\n",
")\n",
"rule43 = ctrl.Rule(\n",
" temp[\"high\"] & al[\"low\"] & ti[\"average\"],\n",
" density[\"low\"],\n",
")\n",
"\n",
"rule51 = ctrl.Rule(\n",
" temp[\"low\"] & al[\"low\"] & ti[\"high\"],\n",
" density[\"high\"],\n",
")\n",
"rule52 = ctrl.Rule(\n",
" temp[\"average\"] & al[\"low\"] & ti[\"high\"],\n",
" density[\"high\"],\n",
")\n",
"rule53 = ctrl.Rule(\n",
" temp[\"high\"] & al[\"low\"] & ti[\"high\"],\n",
" density[\"average\"],\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[IF (temp[low] AND al[low]) AND ti[low] THEN density[low]\n",
" \tAND aggregation function : fmin\n",
" \tOR aggregation function : fmax,\n",
" IF (temp[average] AND al[low]) AND ti[low] THEN density[low]\n",
" \tAND aggregation function : fmin\n",
" \tOR aggregation function : fmax,\n",
" IF (temp[high] AND al[low]) AND ti[low] THEN density[low]\n",
" \tAND aggregation function : fmin\n",
" \tOR aggregation function : fmax,\n",
" IF (temp[low] AND al[average]) AND ti[low] THEN density[average]\n",
" \tAND aggregation function : fmin\n",
" \tOR aggregation function : fmax,\n",
" IF (temp[average] AND al[average]) AND ti[low] THEN density[low]\n",
" \tAND aggregation function : fmin\n",
" \tOR aggregation function : fmax,\n",
" IF (temp[high] AND al[average]) AND ti[low] THEN density[low]\n",
" \tAND aggregation function : fmin\n",
" \tOR aggregation function : fmax,\n",
" IF (temp[low] AND al[high]) AND ti[low] THEN density[high]\n",
" \tAND aggregation function : fmin\n",
" \tOR aggregation function : fmax,\n",
" IF (temp[low] AND al[high]) AND ti[low] THEN density[high]\n",
" \tAND aggregation function : fmin\n",
" \tOR aggregation function : fmax,\n",
" IF (temp[high] AND al[high]) AND ti[low] THEN density[average]\n",
" \tAND aggregation function : fmin\n",
" \tOR aggregation function : fmax,\n",
" IF (temp[low] AND al[low]) AND ti[average] THEN density[average]\n",
" \tAND aggregation function : fmin\n",
" \tOR aggregation function : fmax,\n",
" IF (temp[average] AND al[low]) AND ti[average] THEN density[average]\n",
" \tAND aggregation function : fmin\n",
" \tOR aggregation function : fmax,\n",
" IF (temp[high] AND al[low]) AND ti[average] THEN density[low]\n",
" \tAND aggregation function : fmin\n",
" \tOR aggregation function : fmax,\n",
" IF (temp[low] AND al[low]) AND ti[high] THEN density[high]\n",
" \tAND aggregation function : fmin\n",
" \tOR aggregation function : fmax,\n",
" IF (temp[average] AND al[low]) AND ti[high] THEN density[high]\n",
" \tAND aggregation function : fmin\n",
" \tOR aggregation function : fmax,\n",
" IF (temp[high] AND al[low]) AND ti[high] THEN density[average]\n",
" \tAND aggregation function : fmin\n",
" \tOR aggregation function : fmax]"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"fuzzy_rules = [\n",
" rule11,\n",
" rule12,\n",
" rule13,\n",
" rule21,\n",
" rule22,\n",
" rule23,\n",
" rule31,\n",
" rule32,\n",
" rule33,\n",
" rule41,\n",
" rule42,\n",
" rule43,\n",
" rule51,\n",
" rule52,\n",
" rule53,\n",
"]\n",
"\n",
"density_cntrl = ctrl.ControlSystem(fuzzy_rules)\n",
"\n",
"sim = ctrl.ControlSystemSimulation(density_cntrl)\n",
"\n",
"fuzzy_rules"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"=============\n",
" Antecedents \n",
"=============\n",
"Antecedent: temp = 20\n",
" - low : 1.0\n",
" - average : 0.0\n",
" - high : 0.0\n",
"Antecedent: al = 0.3\n",
" - low : 0.0\n",
" - average : 0.0\n",
" - high : 1.0\n",
"Antecedent: ti = 0.0\n",
" - low : 1.0\n",
" - average : 0.0\n",
" - high : 0.0\n",
"\n",
"=======\n",
" Rules \n",
"=======\n",
"RULE #0:\n",
" IF (temp[low] AND al[low]) AND ti[low] THEN density[low]\n",
"\tAND aggregation function : fmin\n",
"\tOR aggregation function : fmax\n",
"\n",
" Aggregation (IF-clause):\n",
" - temp[low] : 1.0\n",
" - al[low] : 0.0\n",
" - ti[low] : 1.0\n",
" (temp[low] AND al[low]) AND ti[low] = 0.0\n",
" Activation (THEN-clause):\n",
" density[low] : 0.0\n",
"\n",
"RULE #1:\n",
" IF (temp[average] AND al[low]) AND ti[low] THEN density[low]\n",
"\tAND aggregation function : fmin\n",
"\tOR aggregation function : fmax\n",
"\n",
" Aggregation (IF-clause):\n",
" - temp[average] : 0.0\n",
" - al[low] : 0.0\n",
" - ti[low] : 1.0\n",
" (temp[average] AND al[low]) AND ti[low] = 0.0\n",
" Activation (THEN-clause):\n",
" density[low] : 0.0\n",
"\n",
"RULE #2:\n",
" IF (temp[high] AND al[low]) AND ti[low] THEN density[low]\n",
"\tAND aggregation function : fmin\n",
"\tOR aggregation function : fmax\n",
"\n",
" Aggregation (IF-clause):\n",
" - temp[high] : 0.0\n",
" - al[low] : 0.0\n",
" - ti[low] : 1.0\n",
" (temp[high] AND al[low]) AND ti[low] = 0.0\n",
" Activation (THEN-clause):\n",
" density[low] : 0.0\n",
"\n",
"RULE #3:\n",
" IF (temp[low] AND al[average]) AND ti[low] THEN density[average]\n",
"\tAND aggregation function : fmin\n",
"\tOR aggregation function : fmax\n",
"\n",
" Aggregation (IF-clause):\n",
" - temp[low] : 1.0\n",
" - al[average] : 0.0\n",
" - ti[low] : 1.0\n",
" (temp[low] AND al[average]) AND ti[low] = 0.0\n",
" Activation (THEN-clause):\n",
" density[average] : 0.0\n",
"\n",
"RULE #4:\n",
" IF (temp[average] AND al[average]) AND ti[low] THEN density[low]\n",
"\tAND aggregation function : fmin\n",
"\tOR aggregation function : fmax\n",
"\n",
" Aggregation (IF-clause):\n",
" - temp[average] : 0.0\n",
" - al[average] : 0.0\n",
" - ti[low] : 1.0\n",
" (temp[average] AND al[average]) AND ti[low] = 0.0\n",
" Activation (THEN-clause):\n",
" density[low] : 0.0\n",
"\n",
"RULE #5:\n",
" IF (temp[high] AND al[average]) AND ti[low] THEN density[low]\n",
"\tAND aggregation function : fmin\n",
"\tOR aggregation function : fmax\n",
"\n",
" Aggregation (IF-clause):\n",
" - temp[high] : 0.0\n",
" - al[average] : 0.0\n",
" - ti[low] : 1.0\n",
" (temp[high] AND al[average]) AND ti[low] = 0.0\n",
" Activation (THEN-clause):\n",
" density[low] : 0.0\n",
"\n",
"RULE #6:\n",
" IF (temp[low] AND al[high]) AND ti[low] THEN density[high]\n",
"\tAND aggregation function : fmin\n",
"\tOR aggregation function : fmax\n",
"\n",
" Aggregation (IF-clause):\n",
" - temp[low] : 1.0\n",
" - al[high] : 1.0\n",
" - ti[low] : 1.0\n",
" (temp[low] AND al[high]) AND ti[low] = 1.0\n",
" Activation (THEN-clause):\n",
" density[high] : 1.0\n",
"\n",
"RULE #7:\n",
" IF (temp[low] AND al[high]) AND ti[low] THEN density[high]\n",
"\tAND aggregation function : fmin\n",
"\tOR aggregation function : fmax\n",
"\n",
" Aggregation (IF-clause):\n",
" - temp[low] : 1.0\n",
" - al[high] : 1.0\n",
" - ti[low] : 1.0\n",
" (temp[low] AND al[high]) AND ti[low] = 1.0\n",
" Activation (THEN-clause):\n",
" density[high] : 1.0\n",
"\n",
"RULE #8:\n",
" IF (temp[high] AND al[high]) AND ti[low] THEN density[average]\n",
"\tAND aggregation function : fmin\n",
"\tOR aggregation function : fmax\n",
"\n",
" Aggregation (IF-clause):\n",
" - temp[high] : 0.0\n",
" - al[high] : 1.0\n",
" - ti[low] : 1.0\n",
" (temp[high] AND al[high]) AND ti[low] = 0.0\n",
" Activation (THEN-clause):\n",
" density[average] : 0.0\n",
"\n",
"RULE #9:\n",
" IF (temp[low] AND al[low]) AND ti[average] THEN density[average]\n",
"\tAND aggregation function : fmin\n",
"\tOR aggregation function : fmax\n",
"\n",
" Aggregation (IF-clause):\n",
" - temp[low] : 1.0\n",
" - al[low] : 0.0\n",
" - ti[average] : 0.0\n",
" (temp[low] AND al[low]) AND ti[average] = 0.0\n",
" Activation (THEN-clause):\n",
" density[average] : 0.0\n",
"\n",
"RULE #10:\n",
" IF (temp[average] AND al[low]) AND ti[average] THEN density[average]\n",
"\tAND aggregation function : fmin\n",
"\tOR aggregation function : fmax\n",
"\n",
" Aggregation (IF-clause):\n",
" - temp[average] : 0.0\n",
" - al[low] : 0.0\n",
" - ti[average] : 0.0\n",
" (temp[average] AND al[low]) AND ti[average] = 0.0\n",
" Activation (THEN-clause):\n",
" density[average] : 0.0\n",
"\n",
"RULE #11:\n",
" IF (temp[high] AND al[low]) AND ti[average] THEN density[low]\n",
"\tAND aggregation function : fmin\n",
"\tOR aggregation function : fmax\n",
"\n",
" Aggregation (IF-clause):\n",
" - temp[high] : 0.0\n",
" - al[low] : 0.0\n",
" - ti[average] : 0.0\n",
" (temp[high] AND al[low]) AND ti[average] = 0.0\n",
" Activation (THEN-clause):\n",
" density[low] : 0.0\n",
"\n",
"RULE #12:\n",
" IF (temp[low] AND al[low]) AND ti[high] THEN density[high]\n",
"\tAND aggregation function : fmin\n",
"\tOR aggregation function : fmax\n",
"\n",
" Aggregation (IF-clause):\n",
" - temp[low] : 1.0\n",
" - al[low] : 0.0\n",
" - ti[high] : 0.0\n",
" (temp[low] AND al[low]) AND ti[high] = 0.0\n",
" Activation (THEN-clause):\n",
" density[high] : 0.0\n",
"\n",
"RULE #13:\n",
" IF (temp[average] AND al[low]) AND ti[high] THEN density[high]\n",
"\tAND aggregation function : fmin\n",
"\tOR aggregation function : fmax\n",
"\n",
" Aggregation (IF-clause):\n",
" - temp[average] : 0.0\n",
" - al[low] : 0.0\n",
" - ti[high] : 0.0\n",
" (temp[average] AND al[low]) AND ti[high] = 0.0\n",
" Activation (THEN-clause):\n",
" density[high] : 0.0\n",
"\n",
"RULE #14:\n",
" IF (temp[high] AND al[low]) AND ti[high] THEN density[average]\n",
"\tAND aggregation function : fmin\n",
"\tOR aggregation function : fmax\n",
"\n",
" Aggregation (IF-clause):\n",
" - temp[high] : 0.0\n",
" - al[low] : 0.0\n",
" - ti[high] : 0.0\n",
" (temp[high] AND al[low]) AND ti[high] = 0.0\n",
" Activation (THEN-clause):\n",
" density[average] : 0.0\n",
"\n",
"\n",
"==============================\n",
" Intermediaries and Conquests \n",
"==============================\n",
"Consequent: density = 1.1882499824468897\n",
" low:\n",
" Accumulate using accumulation_max : 0.0\n",
" average:\n",
" Accumulate using accumulation_max : 0.0\n",
" high:\n",
" Accumulate using accumulation_max : 1.0\n",
"\n"
]
},
{
"data": {
"text/plain": [
"np.float64(1.1882499824468897)"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"sim.input[\"temp\"] = 20\n",
"sim.input[\"al\"] = 0.3\n",
"sim.input[\"ti\"] = 0.0\n",
"sim.compute()\n",
"sim.print_state()\n",
"display(sim.output[\"density\"])"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"def fuzzy_pred(row):\n",
" sim.input[\"temp\"] = row[\"T\"]\n",
" sim.input[\"al\"] = row[\"Al2O3\"]\n",
" sim.input[\"ti\"] = row[\"TiO2\"]\n",
" sim.compute()\n",
" return sim.output[\"density\"]"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"ename": "KeyError",
"evalue": "'density'",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mKeyError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[1;32mIn[13], line 3\u001b[0m\n\u001b[0;32m 1\u001b[0m result_train \u001b[38;5;241m=\u001b[39m density_train\u001b[38;5;241m.\u001b[39mcopy()\n\u001b[1;32m----> 3\u001b[0m result_train[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mDensityPred\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;241m=\u001b[39m \u001b[43mresult_train\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mapply\u001b[49m\u001b[43m(\u001b[49m\u001b[43mfuzzy_pred\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43maxis\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[0;32m 5\u001b[0m result_train\u001b[38;5;241m.\u001b[39mhead(\u001b[38;5;241m15\u001b[39m)\n",
"File \u001b[1;32mc:\\Users\\user\\Projects\\python\\fuzzy\\.venv\\Lib\\site-packages\\pandas\\core\\frame.py:10374\u001b[0m, in \u001b[0;36mDataFrame.apply\u001b[1;34m(self, func, axis, raw, result_type, args, by_row, engine, engine_kwargs, **kwargs)\u001b[0m\n\u001b[0;32m 10360\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mpandas\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mcore\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mapply\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m frame_apply\n\u001b[0;32m 10362\u001b[0m op \u001b[38;5;241m=\u001b[39m frame_apply(\n\u001b[0;32m 10363\u001b[0m \u001b[38;5;28mself\u001b[39m,\n\u001b[0;32m 10364\u001b[0m func\u001b[38;5;241m=\u001b[39mfunc,\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 10372\u001b[0m kwargs\u001b[38;5;241m=\u001b[39mkwargs,\n\u001b[0;32m 10373\u001b[0m )\n\u001b[1;32m> 10374\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mop\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mapply\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241m.\u001b[39m__finalize__(\u001b[38;5;28mself\u001b[39m, method\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mapply\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
"File \u001b[1;32mc:\\Users\\user\\Projects\\python\\fuzzy\\.venv\\Lib\\site-packages\\pandas\\core\\apply.py:916\u001b[0m, in \u001b[0;36mFrameApply.apply\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 913\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mraw:\n\u001b[0;32m 914\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mapply_raw(engine\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mengine, engine_kwargs\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mengine_kwargs)\n\u001b[1;32m--> 916\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mapply_standard\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n",
"File \u001b[1;32mc:\\Users\\user\\Projects\\python\\fuzzy\\.venv\\Lib\\site-packages\\pandas\\core\\apply.py:1063\u001b[0m, in \u001b[0;36mFrameApply.apply_standard\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 1061\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mapply_standard\u001b[39m(\u001b[38;5;28mself\u001b[39m):\n\u001b[0;32m 1062\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mengine \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mpython\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n\u001b[1;32m-> 1063\u001b[0m results, res_index \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mapply_series_generator\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 1064\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m 1065\u001b[0m results, res_index \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mapply_series_numba()\n",
"File \u001b[1;32mc:\\Users\\user\\Projects\\python\\fuzzy\\.venv\\Lib\\site-packages\\pandas\\core\\apply.py:1081\u001b[0m, in \u001b[0;36mFrameApply.apply_series_generator\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 1078\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m option_context(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmode.chained_assignment\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;28;01mNone\u001b[39;00m):\n\u001b[0;32m 1079\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m i, v \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28menumerate\u001b[39m(series_gen):\n\u001b[0;32m 1080\u001b[0m \u001b[38;5;66;03m# ignore SettingWithCopy here in case the user mutates\u001b[39;00m\n\u001b[1;32m-> 1081\u001b[0m results[i] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mfunc\u001b[49m\u001b[43m(\u001b[49m\u001b[43mv\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 1082\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(results[i], ABCSeries):\n\u001b[0;32m 1083\u001b[0m \u001b[38;5;66;03m# If we have a view on v, we need to make a copy because\u001b[39;00m\n\u001b[0;32m 1084\u001b[0m \u001b[38;5;66;03m# series_generator will swap out the underlying data\u001b[39;00m\n\u001b[0;32m 1085\u001b[0m results[i] \u001b[38;5;241m=\u001b[39m results[i]\u001b[38;5;241m.\u001b[39mcopy(deep\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mFalse\u001b[39;00m)\n",
"Cell \u001b[1;32mIn[12], line 6\u001b[0m, in \u001b[0;36mfuzzy_pred\u001b[1;34m(row)\u001b[0m\n\u001b[0;32m 4\u001b[0m sim\u001b[38;5;241m.\u001b[39minput[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mti\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;241m=\u001b[39m row[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mTiO2\u001b[39m\u001b[38;5;124m\"\u001b[39m]\n\u001b[0;32m 5\u001b[0m sim\u001b[38;5;241m.\u001b[39mcompute()\n\u001b[1;32m----> 6\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43msim\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43moutput\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mdensity\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\n",
"\u001b[1;31mKeyError\u001b[0m: 'density'"
]
}
],
"source": [
"result_train = density_train.copy()\n",
"\n",
"result_train[\"DensityPred\"] = result_train.apply(fuzzy_pred, axis=1)\n",
"\n",
"result_train.head(15)"
]
},
{
"cell_type": "code",
"execution_count": 19,
"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>T</th>\n",
" <th>Al2O3</th>\n",
" <th>TiO2</th>\n",
" <th>Density</th>\n",
" <th>DensityPred</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>30</td>\n",
" <td>0.00</td>\n",
" <td>0.00</td>\n",
" <td>1.05696</td>\n",
" <td>1.060000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>55</td>\n",
" <td>0.00</td>\n",
" <td>0.00</td>\n",
" <td>1.04158</td>\n",
" <td>1.060000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>25</td>\n",
" <td>0.05</td>\n",
" <td>0.00</td>\n",
" <td>1.08438</td>\n",
" <td>1.096363</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>30</td>\n",
" <td>0.05</td>\n",
" <td>0.00</td>\n",
" <td>1.08112</td>\n",
" <td>1.097343</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>35</td>\n",
" <td>0.05</td>\n",
" <td>0.00</td>\n",
" <td>1.07781</td>\n",
" <td>1.097343</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>40</td>\n",
" <td>0.05</td>\n",
" <td>0.00</td>\n",
" <td>1.07446</td>\n",
" <td>1.088627</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>60</td>\n",
" <td>0.05</td>\n",
" <td>0.00</td>\n",
" <td>1.06053</td>\n",
" <td>1.060000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>35</td>\n",
" <td>0.30</td>\n",
" <td>0.00</td>\n",
" <td>1.17459</td>\n",
" <td>1.159583</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>65</td>\n",
" <td>0.30</td>\n",
" <td>0.00</td>\n",
" <td>1.14812</td>\n",
" <td>1.126222</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>45</td>\n",
" <td>0.00</td>\n",
" <td>0.05</td>\n",
" <td>1.07424</td>\n",
" <td>1.096363</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>50</td>\n",
" <td>0.00</td>\n",
" <td>0.05</td>\n",
" <td>1.07075</td>\n",
" <td>1.096363</td>\n",
" </tr>\n",
" <tr>\n",
" <th>11</th>\n",
" <td>55</td>\n",
" <td>0.00</td>\n",
" <td>0.05</td>\n",
" <td>1.06721</td>\n",
" <td>1.097343</td>\n",
" </tr>\n",
" <tr>\n",
" <th>12</th>\n",
" <td>20</td>\n",
" <td>0.00</td>\n",
" <td>0.30</td>\n",
" <td>1.22417</td>\n",
" <td>1.163333</td>\n",
" </tr>\n",
" <tr>\n",
" <th>13</th>\n",
" <td>30</td>\n",
" <td>0.00</td>\n",
" <td>0.30</td>\n",
" <td>1.21310</td>\n",
" <td>1.161428</td>\n",
" </tr>\n",
" <tr>\n",
" <th>14</th>\n",
" <td>40</td>\n",
" <td>0.00</td>\n",
" <td>0.30</td>\n",
" <td>1.20265</td>\n",
" <td>1.162778</td>\n",
" </tr>\n",
" <tr>\n",
" <th>15</th>\n",
" <td>60</td>\n",
" <td>0.00</td>\n",
" <td>0.30</td>\n",
" <td>1.18265</td>\n",
" <td>1.141253</td>\n",
" </tr>\n",
" <tr>\n",
" <th>16</th>\n",
" <td>70</td>\n",
" <td>0.00</td>\n",
" <td>0.30</td>\n",
" <td>1.17261</td>\n",
" <td>1.126667</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" T Al2O3 TiO2 Density DensityPred\n",
"0 30 0.00 0.00 1.05696 1.060000\n",
"1 55 0.00 0.00 1.04158 1.060000\n",
"2 25 0.05 0.00 1.08438 1.096363\n",
"3 30 0.05 0.00 1.08112 1.097343\n",
"4 35 0.05 0.00 1.07781 1.097343\n",
"5 40 0.05 0.00 1.07446 1.088627\n",
"6 60 0.05 0.00 1.06053 1.060000\n",
"7 35 0.30 0.00 1.17459 1.159583\n",
"8 65 0.30 0.00 1.14812 1.126222\n",
"9 45 0.00 0.05 1.07424 1.096363\n",
"10 50 0.00 0.05 1.07075 1.096363\n",
"11 55 0.00 0.05 1.06721 1.097343\n",
"12 20 0.00 0.30 1.22417 1.163333\n",
"13 30 0.00 0.30 1.21310 1.161428\n",
"14 40 0.00 0.30 1.20265 1.162778\n",
"15 60 0.00 0.30 1.18265 1.141253\n",
"16 70 0.00 0.30 1.17261 1.126667"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"result_test = density_test.copy()\n",
"\n",
"result_test[\"DensityPred\"] = result_test.apply(fuzzy_pred, axis=1)\n",
"\n",
"result_test"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'RMSE_train': 0.024131296333542294,\n",
" 'RMSE_test': 0.03056470202709202,\n",
" 'RMAE_test': 0.16058558998263095,\n",
" 'R2_test': 0.7532040538162098}"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import math\n",
"from sklearn import metrics\n",
"\n",
"\n",
"rmetrics = {}\n",
"rmetrics[\"RMSE_train\"] = math.sqrt(\n",
" metrics.mean_squared_error(result_train[\"Density\"], result_train[\"DensityPred\"])\n",
")\n",
"rmetrics[\"RMSE_test\"] = math.sqrt(\n",
" metrics.mean_squared_error(result_test[\"Density\"], result_test[\"DensityPred\"])\n",
")\n",
"rmetrics[\"RMAE_test\"] = math.sqrt(\n",
" metrics.mean_absolute_error(result_test[\"Density\"], result_test[\"DensityPred\"])\n",
")\n",
"rmetrics[\"R2_test\"] = metrics.r2_score(\n",
" result_test[\"Density\"], result_test[\"DensityPred\"]\n",
")\n",
"\n",
"rmetrics"
]
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"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.12.7"
}
},
"nbformat": 4,
"nbformat_minor": 2
}