{"id":1047,"date":"2023-10-24T09:44:48","date_gmt":"2023-10-24T09:44:48","guid":{"rendered":"https:\/\/uneedtalk.com\/config\/tredword\/?page_id=1047"},"modified":"2023-12-01T13:13:07","modified_gmt":"2023-12-01T13:13:07","slug":"5-1-monte-carlo-method","status":"publish","type":"page","link":"https:\/\/radi-cal.org\/method\/5-1-monte-carlo-method\/","title":{"rendered":"5.1. Monte Carlo method"},"content":{"rendered":"<div class=\"row\"  id=\"row-554686092\">\n<div class=\"col small-12 large-12\"  ><div class=\"col-inner\"  >\n<h1>5.1. Monte Carlo method<\/h1>\n<h2>5.1.1. Overview<\/h2>\n<p>Monte-Carlo (MC) methods is a rather general term used for a variety of methods for different purposes. The methods share the approach that random numbers (samples) and the laws of probability theory are used to solve problems. The problems that are solved with MC methods in many fields, such as physics, chemistry, traffic, and economy, usually have in common that finding their analytic solution is either elaborate or impossible. They are usually hard to solve because they depend on a large number of variables that can be random or unknown to some extent. An (in)famous example is the solution of diffusion problems, as performed by Enrico Fermi and others while working on the concept of an atomic bomb at Los Alamos during world war II (Metropolis, 1987). This application represents the birth of the modern MC simulation and is also the origin of its name. \u201cMonte-Carlo\u201d was used as a code name that referred to the casinos of Monaco as a reference to the stochastic nature of the method (Metropolis, 1987). The MC approach is basically an application of the law of large numbers. This essential law of statistics states that when independent experiments subject to statistical variations are repeated a large number of times, the average of all outcomes converges to the expected value (Bernoulli, 1713; Poisson, 1837; Hsu and Robbins, 1947).<br \/>\nIn the present work, only basic Monte Carlo methods are required, and only these are covered briefly here. Even though only basic MC methods are applied here, the present application is a good example of a problem that can, in fact, not be solved in an analytic way. Determining the transmitted power behind a shaded window would require solving a complex and large set of nested spatial and spectral integrals representing the relevant scattering processes and the incidence radiation. Providing the analytic solution to such an equation system is virtually impossible.<br \/>\nHowever, this task can be solved efficiently and straightforwardly by applying the MC method. Instead of considering the entire distributions that describe spectrally or angularly resolved flux densities, only single discrete samples matching the corresponding probabilities are used. These samples, which are random by nature but governed by distinct distributions, are fed as input parameters into a deterministic calculation. The results or output parameters are consequently subject to variation. However, by iterating this process for a large number of samples, the average of the results will converge to the desired expected value, and the measured variation can be used to assess the accuracy of the results. For the considered optical process, this means that the infinite number of continuous paths that energy flows follow are substituted by a large number of discrete random paths governed by probability functions.<br \/>\nConsequently, a key task of MC simulation is the generation of random samples that follow given probability distribution functions (PDF). Three simple methods relevant to this work are briefly presented below.<\/p>\n<h1>5.1.2. Simple sampling strategies<\/h1>\n<h2>5.1.2.1. Sampling discrete values<\/h2>\n<p>Choosing discrete outcomes based on given probabilities represents the simplest sampling case. A good example is the determination of powers going into reflection, absorption and transmission at a scattering event. Since the relevant coefficients are determined by Fresnel\u2019s equations and energy conservation demands that the absorption, reflection and transmittance coefficients add up to unity (\ud835\udc34 + \ud835\udc45 + \ud835\udc47 = 1), the MC implementation of the scattering can be performed using merely a single uniformly distributed random number:<\/p>\n<\/div><\/div>\n<div class=\"col small-12 large-12\"  ><div class=\"col-inner text-center\"  >\n\t<div class=\"img has-hover x md-x lg-x y md-y lg-y\" id=\"image_413665646\">\n\t\t\t\t\t\t\t\t<div class=\"img-inner dark\" >\n\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"907\" height=\"91\" src=\"https:\/\/radi-cal.org\/method\/wp-content\/uploads\/2023\/10\/a2-9.jpg\" class=\"attachment-large size-large\" alt=\"\" srcset=\"https:\/\/radi-cal.org\/method\/wp-content\/uploads\/2023\/10\/a2-9.jpg 907w, https:\/\/radi-cal.org\/method\/wp-content\/uploads\/2023\/10\/a2-9-800x80.jpg 800w, https:\/\/radi-cal.org\/method\/wp-content\/uploads\/2023\/10\/a2-9-768x77.jpg 768w\" sizes=\"(max-width: 907px) 100vw, 907px\" \/>\t\t\t\t\t\t\n\t\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t\n<style scope=\"scope\">\n\n#image_413665646 {\n  width: 89%;\n}\n<\/style>\n\t<\/div>\n\t\n<\/div><\/div>\n<div class=\"col small-12 large-12\"  ><div class=\"col-inner\"  >\n<p>Instead of following all paths, one distinct path is determined based on its probability and followed further on.<\/p>\n<h2>5.1.2.2. Sampling continuous values \u2013 inverse transform method<\/h2>\n<p>Provided the targeted PDF can be integrated in order to determine its cumulated distribution function (CDF) and provided this function can be inverted (CDF-1 ), a random sample following the PDF can efficiently be generated by evaluating this CDF-1 for a random number \ud835\udc5f in the range of 0 to 1, see, e.g., (Robert and Casella, 2004):<\/p>\n<\/div><\/div>\n<div class=\"col small-12 large-12\"  ><div class=\"col-inner text-center\"  >\n\t<div class=\"img has-hover x md-x lg-x y md-y lg-y\" id=\"image_2010297436\">\n\t\t\t\t\t\t\t\t<div class=\"img-inner dark\" >\n\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"424\" height=\"110\" src=\"https:\/\/radi-cal.org\/method\/wp-content\/uploads\/2023\/10\/a3-7.jpg\" class=\"attachment-large size-large\" alt=\"\" \/>\t\t\t\t\t\t\n\t\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t\n<style scope=\"scope\">\n\n#image_2010297436 {\n  width: 40%;\n}\n<\/style>\n\t<\/div>\n\t\n<\/div><\/div>\n<div class=\"col small-12 large-12\"  ><div class=\"col-inner\"  >\n<p>If either the analytic integration or inversion is impossible, a numerical solution can be applied instead. However, in this case, it has to be considered that only numerically efficient solutions are suitable for application in sampling methods. A numerical inversion is, e.g., applied in this work to generate wavelength samples following the global radiation spectrum (see section 4.4.2). An analytic form of the CDF-1 function is, e.g., used to determine the z component of the diffuse reflection in the method localLambert (see section 4.11.2) or the ray starting point on a triangle (see section 7.10.2).<\/p>\n<h2>5.1.2.3. Sampling continuous values \u2013 rejection method<\/h2>\n<p>This method is applied if the CDF-1 cannot be derived analytically or if solving it is computationally too expensive, but the targeted \ud835\udc43\ud835\udc37\ud835\udc39 \ud835\udc53(\ud835\udc65) can be evaluated for any x easily; see e.g. (Robert and Casella, 2004). In this case, an alternative \ud835\udc43\ud835\udc37\ud835\udc39 (\ud835\udc65) that allows drawing samples based on the inversion method is applied. This function \u210e(\ud835\udc65) should form an envelope on the targeted \ud835\udc43\ud835\udc37\ud835\udc39 function and can be scaled using a constant \ud835\udc36 so that:<\/p>\n<\/div><\/div>\n<div class=\"col small-12 large-12\"  ><div class=\"col-inner text-center\"  >\n\t<div class=\"img has-hover x md-x lg-x y md-y lg-y\" id=\"image_833852929\">\n\t\t\t\t\t\t\t\t<div class=\"img-inner dark\" >\n\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"163\" height=\"36\" src=\"https:\/\/radi-cal.org\/method\/wp-content\/uploads\/2023\/10\/a5-8.jpg\" class=\"attachment-large size-large\" alt=\"\" \/>\t\t\t\t\t\t\n\t\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t\n<style scope=\"scope\">\n\n#image_833852929 {\n  width: 20%;\n}\n<\/style>\n\t<\/div>\n\t\n<\/div><\/div>\n<div class=\"col small-12 large-12\"  ><div class=\"col-inner\"  >\n<p>In order to achieve high performance, the function \ud835\udc36 \u2219 (\ud835\udc65) should cover \ud835\udc53(\ud835\udc65) as narrow as possible. To determine a random sample x following the \ud835\udc43\ud835\udc37\ud835\udc39 \ud835\udc53(\ud835\udc65) the following steps are performed:<\/p>\n<\/div><\/div>\n<div class=\"col small-12 large-12\"  ><div class=\"col-inner\"  >\n\t<div class=\"img has-hover x md-x lg-x y md-y lg-y\" id=\"image_895908747\">\n\t\t\t\t\t\t\t\t<div class=\"img-inner dark\" style=\"margin:-22px 0px 0px 0px;\">\n\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"430\" height=\"171\" src=\"https:\/\/radi-cal.org\/method\/wp-content\/uploads\/2023\/10\/a7-8.jpg\" class=\"attachment-large size-large\" alt=\"\" \/>\t\t\t\t\t\t\n\t\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t\n<style scope=\"scope\">\n\n#image_895908747 {\n  width: 42%;\n}\n<\/style>\n\t<\/div>\n\t\n<\/div><\/div>\n<div class=\"col small-12 large-12\"  ><div class=\"col-inner\"  >\n<p>Following this algorithm, a distribution of samples \ud835\udc4b proportional to the target \ud835\udc43\ud835\udc37\ud835\udc39 can be generated.<br \/>\nMore sophisticated sampling methods include, e.g. importance sampling and the metropolis algorithm (Robert and Casella, 2004). While these sampling methods were not required in the present work, a special variant of the metropolis algorithm was used for the required optimisation processes in the thesis (see section 5.2).<\/p>\n<h2>5.1.3. Sampling accuracy \u2013 the central limit theorem<\/h2>\n<p>Apart from generating random samples, the second essential task of MC applications is to evaluate the statistical accuracy of the results. As mentioned, the Monte Carlo method relies on stochastic input parameters fed into a deterministic process producing results that are subject to variation of initially unknown scale.<br \/>\nIn order to assess the uncertainty of the result, the fundamental central limit theorem (CLT) can be applied. The essential theorem is presented in many forms. E.g. Kreyszig et al. (2011) state it as:<\/p>\n<\/div><\/div>\n<div class=\"col small-12 large-12\"  ><div class=\"col-inner text-center\"  >\n\t<div class=\"img has-hover x md-x lg-x y md-y lg-y\" id=\"image_441578049\">\n\t\t\t\t\t\t\t\t<div class=\"img-inner dark\" >\n\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"742\" height=\"312\" src=\"https:\/\/radi-cal.org\/method\/wp-content\/uploads\/2023\/10\/a8-6.jpg\" class=\"attachment-large size-large\" alt=\"\" \/>\t\t\t\t\t\t\n\t\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t\n<style scope=\"scope\">\n\n#image_441578049 {\n  width: 70%;\n}\n<\/style>\n\t<\/div>\n\t\n<\/div><\/div>\n<div class=\"col small-12 large-12\"  ><div class=\"col-inner\"  >\n<p>Expressed in simple words, this means that all distributions formed as a sum of distributions converge to a normal distribution centred around the expected value of all distributions. Note that the initial distributions can be of any \u201cnon-pathological\u201d type, to put it casually, but their average, always converges to a normal distribution. More specifically, random, independent samples with finite expected values and variance are required; see e.g. Montgomery and Runger (2014).<br \/>\nIn its practical application, subsamples of size \ud835\udc5a of the MC results \ud835\udc5f\ud835\udc56 are used to generate \ud835\udc5b mean values \u00b5\ud835\udc60\ud835\udc60,\ud835\udc56 in parallel. The sample means are used to estimate the population mean \u00b5\ud835\udc52 , that converges to the targeted expected value \u00b5 of the result (see, e.g., Montgomery et al. (2010)):<\/p>\n<\/div><\/div>\n<div class=\"col small-12 large-12\"  ><div class=\"col-inner text-center\"  >\n\t<div class=\"img has-hover x md-x lg-x y md-y lg-y\" id=\"image_40603783\">\n\t\t\t\t\t\t\t\t<div class=\"img-inner dark\" >\n\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"413\" height=\"72\" src=\"https:\/\/radi-cal.org\/method\/wp-content\/uploads\/2023\/10\/a9-7.jpg\" class=\"attachment-large size-large\" alt=\"\" \/>\t\t\t\t\t\t\n\t\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t\n<style scope=\"scope\">\n\n#image_40603783 {\n  width: 45%;\n}\n<\/style>\n\t<\/div>\n\t\n<\/div><\/div>\n<div class=\"col small-12 large-12\"  ><div class=\"col-inner\"  >\n<p>While dividing the samples into subsamples has no impact on the result of \u00b5\ud835\udc52 , it is relevant for monitoring the accuracy of the results. Since, unlike the r\ud835\udc56 values, the \u00b5\ud835\udc60\ud835\udc60,\ud835\udc56 will be normally distributed according to the CLT, the standard error of the sample means (\ud835\udf0e\ud835\udc46\ud835\udc38\ud835\udc40) can be used to assess the accuracy of the estimate \u00b5\ud835\udc52 . It can be derived as (see, e.g., Montgomery et al. (2010)):<\/p>\n<\/div><\/div>\n<div class=\"col small-12 large-12\"  ><div class=\"col-inner text-center\"  >\n\t<div class=\"img has-hover x md-x lg-x y md-y lg-y\" id=\"image_850045262\">\n\t\t\t\t\t\t\t\t<div class=\"img-inner dark\" >\n\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"674\" height=\"150\" src=\"https:\/\/radi-cal.org\/method\/wp-content\/uploads\/2023\/10\/a10-8.jpg\" class=\"attachment-large size-large\" alt=\"\" \/>\t\t\t\t\t\t\n\t\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t\n<style scope=\"scope\">\n\n#image_850045262 {\n  width: 77%;\n}\n<\/style>\n\t<\/div>\n\t\n<\/div><\/div>\n<div class=\"col small-12 large-12\"  ><div class=\"col-inner\"  >\n<p>This is the simple but fundamental relation used to assess the accuracy of MC results. Since based<br \/>\non a normal distribution, the expression \u03c3\ud835\udc46\ud835\udc38\ud835\udc40 can be used to state confidence intervals for the results.<\/p>\n<\/div><\/div>\n<div class=\"col medium-6 small-12 large-6\"  ><div class=\"col-inner\"  >\n<p>Note that the relation holds only for the case of independent sampling, as applied in the present method. If the samples are subject to correlation, like in the case of Markov chains, more complex approaches are required to assess the accuracy, see e.g. Robert and Casella (2004). The fundamental square root dependence on \ud835\udc5b in equation (91) gives us crucial information regarding the convergence speed of any MC simulation based on uncorrelated sampling. It implies that in order to achieve twice the accuracy, the number of iterations must be quadrupled; to reduce the error to<\/p>\n<\/div><\/div>\n<div class=\"col medium-6 small-12 large-6\"  ><div class=\"col-inner\"  >\n\t<div class=\"img has-hover x md-x lg-x y md-y lg-y\" id=\"image_2041461863\">\n\t\t\t\t\t\t\t\t<div class=\"img-inner dark\" >\n\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"529\" height=\"383\" src=\"https:\/\/radi-cal.org\/method\/wp-content\/uploads\/2023\/10\/a11-6.jpg\" class=\"attachment-large size-large\" alt=\"\" \/>\t\t\t\t\t\t\n\t\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t\n<style scope=\"scope\">\n\n#image_2041461863 {\n  width: 100%;\n}\n<\/style>\n\t<\/div>\n\t\n<\/div><\/div>\n<div class=\"col small-12 large-12\"  ><div class=\"col-inner\"  >\n<p>one tenth, the required iterations have to be increased a hundredfold, etc. Therefore, the convergence of MC is often perceived as fast in the beginning and slow in the end (see Figure 69).<\/p>\n<\/div><\/div>\n<\/div>\n<style>\n#menu-main li:nth-child(5) .sub-menu{display:block !important;}\n<\/style>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"page-right-sidebar.php","meta":{"footnotes":""},"_links":{"self":[{"href":"https:\/\/radi-cal.org\/method\/wp-json\/wp\/v2\/pages\/1047"}],"collection":[{"href":"https:\/\/radi-cal.org\/method\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/radi-cal.org\/method\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/radi-cal.org\/method\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/radi-cal.org\/method\/wp-json\/wp\/v2\/comments?post=1047"}],"version-history":[{"count":17,"href":"https:\/\/radi-cal.org\/method\/wp-json\/wp\/v2\/pages\/1047\/revisions"}],"predecessor-version":[{"id":1968,"href":"https:\/\/radi-cal.org\/method\/wp-json\/wp\/v2\/pages\/1047\/revisions\/1968"}],"wp:attachment":[{"href":"https:\/\/radi-cal.org\/method\/wp-json\/wp\/v2\/media?parent=1047"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}