{"id":1036,"date":"2018-12-19T02:12:49","date_gmt":"2018-12-18T23:12:49","guid":{"rendered":"http:\/\/kusuaks7\/?p=641"},"modified":"2021-12-15T02:57:57","modified_gmt":"2021-12-15T02:57:57","slug":"physics-guided-neural-networks-pgnns","status":"publish","type":"post","link":"https:\/\/www.experfy.com\/blog\/ai-ml\/physics-guided-neural-networks-pgnns\/","title":{"rendered":"Physics-guided Neural Networks (PGNNs)"},"content":{"rendered":"<p><strong><em>Ready to learn Machine Learning? Browse<\/em><\/strong> <strong><em><a href=\"https:\/\/www.experfy.com\/training\/tracks\/machine-learning-training-certification\">Machine Learning Training and Certification courses<\/a> developed by industry thought leaders and Experfy in Harvard Innovation Lab.<\/em><\/strong><\/p>\n<section>\n<p id=\"6068\">Physics-based models are at the heart of today\u2019s technology and science. Over recent years, data-driven models started providing an alternative approach and outperformed physics-driven models in many tasks. Even so, they are data hungry, their inferences could be hard to explain and generalization remains to be a challenge. Combining data and physics could reveal the best of both\u00a0worlds.<\/p>\n<p id=\"35c8\">When machine learning algorithms are\u00a0<em>learning<\/em>, they are actually searching for a solution in the hypothesis space you defined by your choice of algorithm, architecture, and configuration. Hypothesis space could be quite large even for a fairly simple algorithm. Data is the only guide we use to look for a solution in this huge space. What if we can use our knowledge of the world \u2014 for example, physics\u2014 together with data to guide this search?<\/p>\n<p id=\"46de\">This is what Karpatne et al. explained in their paper\u00a0<a href=\"https:\/\/arxiv.org\/abs\/1710.11431\" target=\"_blank\" rel=\"noopener noreferrer\" data-href=\"https:\/\/arxiv.org\/abs\/1710.11431\" data->Physics-guided Neural Networks (PGNN): An Application in Lake Temperature Modeling<\/a><em>.\u00a0<\/em>In this post, I will explain why this idea is crucial and I will also describe how they did it by summarizing the paper.<\/p>\n<\/section>\n<section>\n<hr \/>\n<p id=\"32f5\">Imagine you have sent your alien \ud83d\udc7d friend (optimization algorithm) to a supermarket (hypothesis space) to buy your favorite cheese (solution). The only clue she has is the picture of the cheese (data) you gave her. Since she lacks the preconceptions we have about supermarkets she will have a hard time finding the cheese. She might wander around cosmetics, cleaning supplies before even reaching the food section.<\/p>\n<figure id=\"f96b\"><canvas width=\"75\" height=\"53\"><\/canvas><img decoding=\"async\" style=\"width: 640px; height: 457px;\" src=\"https:\/\/cdn-images-1.medium.com\/max\/640\/1*45uOn1-tl6CQ9zYD0dJUWw.jpeg\" data-src=\"https:\/\/cdn-images-1.medium.com\/max\/640\/1*45uOn1-tl6CQ9zYD0dJUWw.jpeg\" \/><\/figure>\n<p style=\"text-align: center;\">Finally reached the food section (courtesy of\u00a0<strong>Dominic L.\u00a0Garcia<\/strong>).<\/p>\n<p id=\"d8b1\">This is similar to how machine learning optimization algorithms like gradient descent look for a hypothesis. Data is the only guide. Ideally, this should work just fine but most of the time the data is noisy or not enough. Incorporating our knowledge into the optimization algorithms \u2014 search for the cheese in the food section, don\u2019t even look at the cosmetics \u2014 could alleviate these challenges. Let\u2019s see next, how we can actually do this.<\/p>\n<h4 id=\"dbeb\">How to guide an ML algorithm with\u00a0physics<\/h4>\n<p id=\"5c8e\">Now, let me summarize how the authors utilize physics to guide a machine learning model. They present two approaches for this: (1) using physics theory, they calculate additional features (feature engineering) to feed into the model along with the measurements and (2) they add a physical inconsistency term to the loss function in order to punish physically inconsistent predictions.<\/p>\n<p style=\"text-align: center;\"><img decoding=\"async\" style=\"width: 640px; height: 272px;\" src=\"https:\/\/cdn-images-1.medium.com\/max\/640\/1*1jjbnRIaEXd0W-o64HGHAQ.png\" data-src=\"https:\/\/cdn-images-1.medium.com\/max\/640\/1*1jjbnRIaEXd0W-o64HGHAQ.png\" \/><\/p>\n<p style=\"text-align: center;\">\u00a0(1) Feature engineering using a physics-based model<\/p>\n<p style=\"text-align: center;\"><img decoding=\"async\" style=\"text-align: center;\" src=\"https:\/\/cdn-images-1.medium.com\/max\/640\/1*uM2Qh4PFQLWLLI_KHbgaVw.png\" data-src=\"https:\/\/cdn-images-1.medium.com\/max\/640\/1*uM2Qh4PFQLWLLI_KHbgaVw.png\" \/><\/p>\n<p style=\"text-align: center;\">(2) Data + Physics driven loss\u00a0function<\/p>\n<p id=\"6d2f\">The first approach, feature engineering, is extensively used in machine learning. The second approach, however, is compelling. Very much like adding a regularization term to punish overfitting, they add a physical inconsistency term to the loss function. Hence, with this new term, the optimization algorithm should also take care of minimizing physically inconsistent results.<\/p>\n<p id=\"0302\">In the paper, Karpatne et al. combined these two approaches with a neural network and demonstrated an algorithm they call physics-guided neural network (PGNN). There are two main advantages PGNNs could provide:<\/p>\n<ul>\n<li id=\"d29c\"><a href=\"https:\/\/developers.google.com\/machine-learning\/crash-course\/generalization\/video-lecture\" target=\"_blank\" rel=\"noopener noreferrer\" data-href=\"https:\/\/developers.google.com\/machine-learning\/crash-course\/generalization\/video-lecture\" data-><strong>Achieving generalization<\/strong><\/a>\u00a0is a fundamental challenge in machine learning. Since physics models, mostly, do not depend on data, they might perform well on unseen data, even from a different distribution.<\/li>\n<li id=\"6e95\">Machine learning models are sometimes referred to as black-box models due to the fact that it is not always clear how a model reaches a specific decision. There is quite a lot of work going into\u00a0<a href=\"https:\/\/en.wikipedia.org\/wiki\/Explainable_Artificial_Intelligence\" target=\"_blank\" rel=\"noopener noreferrer\" data-href=\"https:\/\/en.wikipedia.org\/wiki\/Explainable_Artificial_Intelligence\" data-><strong>Explainable AI (XAI)<\/strong><\/a>\u00a0to improve model interpretability. PGNNs could provide a basis towards XAI as they present physically consistent and interpretable results.<\/li>\n<\/ul>\n<h4 id=\"ba01\">Application example: Lake temperature modeling<\/h4>\n<p id=\"b455\">In the paper, lake temperature modeling is given as an example to demonstrate the effectiveness of the PGNN. Water temperature controls the growth, survival, and reproduction of biological species living in the lake. Therefore accurate observations and predictions of temperature are crucial for understanding the changes occurring in the community. The task is to develop a model that can predict the water temperature as a function of depth and time, for a given lake. Now let\u2019s see how they applied (1) feature engineering and (2) loss function modification for this problem.<\/p>\n<p id=\"7889\">(1) For feature engineering, they used a model called the\u00a0<a href=\"http:\/\/aed.see.uwa.edu.au\/research\/models\/GLM\/\" target=\"_blank\" rel=\"noopener noreferrer\" data-href=\"http:\/\/aed.see.uwa.edu.au\/research\/models\/GLM\/\" data-><em>general lake model (GLM)<\/em><\/a>\u00a0to generate new features and feed them into the NN. It is a physics-based model that captures the processes governing the dynamics of temperature in a lake (heating due to sun, evaporation etc.).<\/p>\n<p id=\"9d44\">(2) Let\u2019s now see how they defined this physical inconsistency term. It is known that denser water sinks. The relationship between water temperature and its density is also known. Hence predictions should follow the fact that the deeper the point, the higher the predicted density. If for a pair of points, the model predicts higher density for the point closer to the surface, this is a physically inconsistent prediction.<\/p>\n<figure id=\"c5cb\"><canvas width=\"75\" height=\"46\"><\/canvas><img decoding=\"async\" src=\"https:\/\/cdn-images-1.medium.com\/max\/640\/1*dhsElli6-7gLivCvTF2FYQ.png\" data-src=\"https:\/\/cdn-images-1.medium.com\/max\/640\/1*dhsElli6-7gLivCvTF2FYQ.png\" \/><\/figure>\n<p id=\"68f4\">Now it is possible to incorporate this idea into the loss function. We would like to punish if \u03c1A&gt; \u03c1B and do nothing otherwise. Moreover, for a larger inconsistency, the punishment should be higher. This can be done easily by adding the value of the function\u00a0<em>max( \u03c1A- \u03c1B, 0)\u00a0<\/em>to the loss function. If \u03c1A&gt; \u03c1B (i.e. inconsistency), the function will give a positive value that will increase the value of the loss function (the function we are trying to minimize), otherwise it will give zero leaving the loss function unchanged.<\/p>\n<p id=\"f4a5\">At this point, two modifications are necessary to the function in order to use it properly. What is important is the average inconsistency of all the pairs, not one single pair. Therefore it is possible to sum\u00a0<em>max( \u03c1A- \u03c1B, 0)\u00a0<\/em>for all points and divide by the number of points. Also, it is critical to control the relative importance of minimizing physical inconsistency. This can be done by multiplying the average physical inconsistency with a hyperparameter (works like the regularization parameter).<\/p>\n<figure id=\"f812\"><canvas width=\"75\" height=\"6\"><\/canvas><img decoding=\"async\" src=\"https:\/\/cdn-images-1.medium.com\/max\/640\/1*h9uzkmhpPV-H8JWRfcF0fw.png\" data-src=\"https:\/\/cdn-images-1.medium.com\/max\/640\/1*h9uzkmhpPV-H8JWRfcF0fw.png\" \/><\/figure>\n<p style=\"text-align: center;\">\u00a0Physical inconsistency term of the loss\u00a0function<\/p>\n<h4 id=\"7ae6\">Results<\/h4>\n<p id=\"a91b\">Here are the results of 4 models. They are:<\/p>\n<ul>\n<li id=\"286a\"><strong>PHY:<\/strong>\u00a0General lake model (GLM).<\/li>\n<li id=\"3708\"><strong>NN:<\/strong>\u00a0A neural network.<\/li>\n<li id=\"dbe2\"><strong>PGNN0:<\/strong>\u00a0A neural network with feature engineering. Results of the GLM are fed into the NN as additional features.<\/li>\n<li id=\"f1ad\"><strong>PGNN:<\/strong>\u00a0NN with feature engineering and with the modified loss function.<\/li>\n<\/ul>\n<p id=\"7396\">And two metrics for evaluation:<\/p>\n<ul>\n<li id=\"dd3c\"><strong>RMSE:<\/strong>\u00a0Root mean square error.<\/li>\n<li id=\"7b2f\"><strong>Physical Inconsistency:<\/strong>\u00a0Fraction of time-steps where the model makes physically inconsistent predictions.<\/li>\n<\/ul>\n<p style=\"text-align: center;\"><img decoding=\"async\" src=\"https:\/\/cdn-images-1.medium.com\/max\/640\/1*13A4nRsBQALP8xGZeNf1_Q.png\" data-src=\"https:\/\/cdn-images-1.medium.com\/max\/640\/1*13A4nRsBQALP8xGZeNf1_Q.png\" \/><\/p>\n<p style=\"text-align: center;\">Results on Lake Mille\u00a0Lacs<\/p>\n<figure id=\"9f3e\"><canvas width=\"75\" height=\"56\"><\/canvas><img decoding=\"async\" src=\"https:\/\/cdn-images-1.medium.com\/max\/640\/1*Rab3FwDxRQjPwcsABYsMUw.png\" data-src=\"https:\/\/cdn-images-1.medium.com\/max\/640\/1*Rab3FwDxRQjPwcsABYsMUw.png\" \/><\/figure>\n<p style=\"text-align: center;\">\u00a0 \u00a0 \u00a0 \u00a0 Results on Lake\u00a0Mendota<\/p>\n<p id=\"34fc\">Comparing NN with the PHY we can conclude that NN gives more accurate predictions at the expense of physically inconsistent results. Comparing PGNN0 and PGNN we can see that physical inconsistency is eliminated mostly thanks to the modified loss function. Improved accuracy is mostly due to feature engineering with some contribution from the loss function.<\/p>\n<\/section>\n<section>\n<hr \/>\n<p id=\"3c36\"><strong>To sum things up<\/strong>, these first results show us that this new type of algorithm, PGNN, is very promising for providing accurate and physically consistent results. Moreover, incorporating our knowledge of the world into the loss function provides an elegant way to improve the generalization performance of machine learning models. This seemingly simple idea has the potential to fundamentally improve the way we conduct machine learning and scientific research.<\/p>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>When machine learning algorithms are&nbsp;learning, they are actually searching for a solution in the hypothesis space you defined by your choice of algorithm, architecture, and configuration. Hypothesis space could be quite large even for a fairly simple algorithm. Data is the only guide we use to look for a solution in this huge space. What if we can use our knowledge of the world\u200a&mdash;\u200afor example, physics&mdash; together with data to guide this search?<\/p>\n","protected":false},"author":384,"featured_media":3734,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"content-type":"","footnotes":""},"categories":[183],"tags":[92],"ppma_author":[2308],"class_list":["post-1036","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ai-ml","tag-machine-learning"],"authors":[{"term_id":2308,"user_id":384,"is_guest":0,"slug":"mehmet-alican-noyan","display_name":"Mehmet Noyan","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g","user_url":"","last_name":"Noyan","first_name":"Mehmet","job_title":"","description":"Mehmet Alican Noyan&nbsp;is Machine Learning Engineer at <a href=\"http:\/\/www.icfo.eu\/\">ICFO<\/a>, fast growing research institution that aims at advancing the limits of scientific and technological knowledge in optical sciences."}],"_links":{"self":[{"href":"https:\/\/www.experfy.com\/blog\/wp-json\/wp\/v2\/posts\/1036","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.experfy.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.experfy.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.experfy.com\/blog\/wp-json\/wp\/v2\/users\/384"}],"replies":[{"embeddable":true,"href":"https:\/\/www.experfy.com\/blog\/wp-json\/wp\/v2\/comments?post=1036"}],"version-history":[{"count":2,"href":"https:\/\/www.experfy.com\/blog\/wp-json\/wp\/v2\/posts\/1036\/revisions"}],"predecessor-version":[{"id":28357,"href":"https:\/\/www.experfy.com\/blog\/wp-json\/wp\/v2\/posts\/1036\/revisions\/28357"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.experfy.com\/blog\/wp-json\/wp\/v2\/media\/3734"}],"wp:attachment":[{"href":"https:\/\/www.experfy.com\/blog\/wp-json\/wp\/v2\/media?parent=1036"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.experfy.com\/blog\/wp-json\/wp\/v2\/categories?post=1036"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.experfy.com\/blog\/wp-json\/wp\/v2\/tags?post=1036"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.experfy.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=1036"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}