From 19d8d839699374e0d81a247ffa8b46d07a0234b8 Mon Sep 17 00:00:00 2001 From: Tesshub Date: Thu, 14 Nov 2024 10:37:51 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=84tutorial=20update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...thon model of a green fa\303\247ade.ipynb" | 115 +++++++++++------- 1 file changed, 68 insertions(+), 47 deletions(-) diff --git "a/tutorials/SA and Identification example_Modelica & python model of a green fa\303\247ade.ipynb" "b/tutorials/SA and Identification example_Modelica & python model of a green fa\303\247ade.ipynb" index 4d59eed..73118d9 100644 --- "a/tutorials/SA and Identification example_Modelica & python model of a green fa\303\247ade.ipynb" +++ "b/tutorials/SA and Identification example_Modelica & python model of a green fa\303\247ade.ipynb" @@ -1,23 +1,11 @@ { "cells": [ { - "cell_type": "code", - "execution_count": null, - "id": "b28b6845", - "metadata": { - "ExecuteTime": { - "end_time": "2024-10-22T14:03:12.518536Z", - "start_time": "2024-10-22T14:02:46.050855Z" - } - }, - "outputs": [], + "cell_type": "markdown", + "id": "739e70ef-d053-40bb-af35-45359af6fa50", + "metadata": {}, "source": [ - "import pandas as pd\n", - "import numpy as np\n", - "import os\n", - "import plotly.express as px\n", - "from pathlib import Path\n", - "pd.options.mode.chained_assignment = None # default='warn'" + "This tutorial can be found and ran in the GITHUB libray corrAI: https://github.com/BuildingEnergySimulationTools/corrai" ] }, { @@ -37,43 +25,37 @@ "The aim of this tutorial is to provide a complete workflow for material physical properties identification of a reference wall using **Modelitool** (modelica simulator) and **CorrAI** models by following these steps:\n", "\n", "1. **Measurement import and verification**:\n", - " - We will import measurement dataframe into the notebook and check measumreent before selecting an analysis period.\n", + " - We will import measurement dataframe into the notebook and check measurement before selecting an analysis period.\n", " \n", - "2. **Model Creation/Import**:\n", + "2. **Model creation/import**:\n", " - We will either create a new mathematical model or impor model (FMU, openModelica).\n", "\n", - "3. **Loading Measurements**:\n", - " - We will load the necessary measurements or data that will be used for our sensitivity analysis and model id.f our model.\n", - "\n", - "4. **Performing Sensitivity Analysis**:\n", + "3. **Performing sensitivity analysis**:\n", " - Sensitivity analysis will be conducted to determine how different input variables affect the output of the model. This step helps in identifying the most influential parameters in the model.\n", "\n", - "5. **Model Identification**:\n", + "4. **Model identification**:\n", " - Using the results from the sensitivity analysis, we will identify the parameters that need to be adjusted to improve the model's accuracy. This involves fitting the model to the data and refining its parameters.\n", "\n", - "65. **Results Visualization and Interpretation**:\n", - " - Finally, we will visualize the results of our analysis and interpret the findings. This includes plotting the sensitivity indices and comparing the model's predictions with the liability of the model.\n", - "\n", "---" ] }, { "cell_type": "markdown", "id": "f5d604e7-343a-4370-8b53-0c4834bd251c", - "metadata": {}, + "metadata": { + "jp-MarkdownHeadingCollapsed": true + }, "source": [ - "# 1 Introduction\n" + "# Introduction" ] }, { "attachments": {}, "cell_type": "markdown", "id": "d7c01447", - "metadata": { - "jp-MarkdownHeadingCollapsed": true - }, + "metadata": {}, "source": [ - "## 1.1 Use case presentation\n", + "## Use case presentation\n", "\n", "A \"real-scale\" test bench is used. The **O3BET** (or in this example BEF test bench in Anglet, France) offers experimental conditions to evaluate building façade solutions. Heat exchanges in a cell are restricted on five of its faces, while the sixth face is dedicated to the tested solution. Internal temperature and humidity conditions can be controlled or monitored. External conditions, including temperatures and solar radiation, are measured.\n", "\n", @@ -98,11 +80,9 @@ "attachments": {}, "cell_type": "markdown", "id": "182f9b79-5f47-4998-baaa-59d0598525e7", - "metadata": { - "jp-MarkdownHeadingCollapsed": true - }, + "metadata": {}, "source": [ - "## 1.2 Identification framework\n", + "## Identification framework\n", "The following framework is proposed to identify the **REFERENCE** wall thermal conductivity, and provides:\n", "- Physical model description using Python\n", "- Sensitivity analysis to identify materials properties which have an influence on the discrepancy between model outputs and measured phenomenon\n", @@ -119,8 +99,30 @@ } }, "source": [ - "## 2.2 Load measurement file\n", - "First, let's load the reference cell measurement data on python that will be used as boundary conditions. Note that the data loaded here should be cleaned beforhand (see Tutorial **\"MeasuredDat example\"** if needed)" + "# 1. Measurement import and verification\n", + "\n", + "First, let's load some generic libraries (pandas, Path).\n", + "Then we can load the reference cell measurement data on python that will be used as boundary conditions. Note that the data loaded here should be cleaned beforhand (see Tutorial **\"MeasuredDat example\"** if needed)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b28b6845", + "metadata": { + "ExecuteTime": { + "end_time": "2024-10-22T14:03:12.518536Z", + "start_time": "2024-10-22T14:02:46.050855Z" + } + }, + "outputs": [], + "source": [ + "import pandas as pd\n", + "import numpy as np\n", + "import os\n", + "import plotly.express as px\n", + "from pathlib import Path\n", + "pd.options.mode.chained_assignment = None # default='warn'" ] }, { @@ -280,8 +282,7 @@ "id": "4b6c113a-ccdb-4fb5-a81d-fa75473028c7", "metadata": {}, "source": [ - "For this example we propose a resistance/capacity approach.\n", - " Based on electrical circuit analogy, each layer of the wall is modeled by two resistance and a capacity:\n", + "For this example we propose a resistance/capacity approach. Based on electrical circuit analogy, each layer of the wall is modeled by two resistances and a capacity:\n", "\n", "\n", "| Figure : RC model|\n", @@ -289,6 +290,7 @@ "| | \n", "\n", "\n", + "Note that it is recommended to start with a **very simple** model (e.g., one resistance, one capacity with only Text and Tint as boundary conditions) and gradually make it more complex as you identify parameters. For the sake of this tutorial, the proposed model is already a bit detailed.\n", "\n", "\n", "The following is a brief description of the thermal model:\n", @@ -600,6 +602,16 @@ ")" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "d9217031-ab41-4cdb-a53e-a3f7b438c9dd", + "metadata": {}, + "outputs": [], + "source": [ + "init_res_PYTH.head()" + ] + }, { "cell_type": "markdown", "id": "fd810131-bf4d-428f-9a4b-d44d109a923e", @@ -665,9 +677,13 @@ { "cell_type": "markdown", "id": "56c2c6a4-7060-435b-b472-8887eb7de5c3", - "metadata": {}, + "metadata": { + "jp-MarkdownHeadingCollapsed": true + }, "source": [ - "# 3. Sensitivity analysis" + "# 3. Sensitivity analysis\n", + "It is very important to know how our defined parameters have an influence on the model prediction. Therefore, we use a sensitivity analysis to \"rank\" the parameter by order of influence\n", + "on the model error. " ] }, { @@ -699,7 +715,8 @@ "- *y_i* is the observed value for the \\( i \\)-th observation,\n", "- *hat{y}_i* is the predicted value for the \\( i \\)-th observation.\n", "\n", - "The CV_RMSE measures the variation of the RMSE relative to the mean of the observed values. It provides a standardized measure of the error, which can be useful for comparing the performance of different models across different datasets.\n" + "The CV_RMSE measures the variation of the RMSE relative to the mean of the observed values. It provides a standardized measure of the error, which can be useful for comparing the performance of different models across different datasets.\n", + "Here, we can chose the error function as the CV_RMSE between measured temperature(s) and model prediction." ] }, { @@ -1221,7 +1238,9 @@ { "cell_type": "markdown", "id": "7d0c13f3-4a23-4731-adec-a2f57d55b35b", - "metadata": {}, + "metadata": { + "jp-MarkdownHeadingCollapsed": true + }, "source": [ "# 4. Identification\n", "Now, we proceed to finding optimal values for these parameters by minimizing the coefficient of variation of root mean square error (cv_rmse) between one or several measured nodes, and one or several relevant outputs of our model.\n", @@ -1239,7 +1258,9 @@ { "cell_type": "markdown", "id": "c924aad5-9fa3-4df4-ac19-251152251c92", - "metadata": {}, + "metadata": { + "jp-MarkdownHeadingCollapsed": true + }, "source": [ "## 4.1. Objective function\n", "In parameter optimization, we aim to adjust certain model parameters to minimize the difference between simulated and observed data. The objective function is a scalar function that quantifies this difference. In this case, the CV_RMSE (Coefficient of Variation of Root Mean Square Error) is used as a measure of how well the model output matches the reference measurements.\n", @@ -1780,7 +1801,7 @@ "id": "10743041-3b9b-496c-a12d-d6acc18a26a2", "metadata": {}, "source": [ - "For a bi-objective problem,and helping us chosing the best set of parameters value, wethen use the decomposition method called Augmented Scalarization Function (ASF), a well-known metric in the multi-objective optimization literature.\n", + "For a bi-objective problem,and helping us chosing the best set of parameters value, we can use the decomposition method called Augmented Scalarization Function (ASF), a well-known metric in the multi-objective optimization literature.\n", "Let us assume the are equally important by setting the weights to 0.5 and 0.5 and setting these" ] }, @@ -2241,7 +2262,7 @@ { "cell_type": "code", "execution_count": null, - "id": "20ac0fd8-03a8-4955-aa7b-3196bbd173c4", + "id": "e385c24d-22ff-46b1-9c5d-1c23de583326", "metadata": {}, "outputs": [], "source": []