<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="http://www.r-bloggers.com/sustainability-through-energy-load-shaping-for-buildings-using-r/"></div></div><div><a data-url="http://www.r-bloggers.com/sustainability-through-energy-load-shaping-for-buildings-using-r/" data-counturl="http://www.r-bloggers.com/sustainability-through-energy-load-shaping-for-buildings-using-r/" data-count="horizontal" data-text="Sustainability through Energy Load Shaping for Buildings using R" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://blog.revolutionanalytics.com/2016/07/energy-load-shaping.html"> Revolutions</a></strong>, and kindly contributed to <a rel="nofollow" href="http://www.r-bloggers.com/">R-bloggers)</a> </div>
<div>
<p>by Mike Wise, Data Scientist / Solution Architect – MCS Incubation Services</p>
<h2>Background</h2>
<p>Building energy consumption is a huge component of energy consumption. In the USA for example, around 40 percent of the energy consumed is in buildings, and as the USA consumes something like 25 percent of the worlds energy, it is clear we are talking about a multi-trillion-dollar segment with a huge environmental footprint. So it makes sense to look for ways to cut it back. And as more and more of our energy comes from renewable but intermittent sources like solar and wind, we will need to introduce variable pricing that reflects the current availability of energy — facilitating the move to <em>sustainable solutions</em>.</p>
<p>Load shaping is a technique that describes the process of changing the timing of your energy consumption to take advantage of low energy prices when they occur, or avoid times of high prices. There are many ways to do this, and I was fortunate enough to have been tasked with implementing a form of load shaping to reduce wintertime peak energy usage on the Microsoft campus in cooperation with Microsoft RE&amp;F (Real Estate and Finance). R was the language that we used for it.</p>
<p><a target="_blank" href="http://revolution-computing.typepad.com/.a/6a010534b1db25970b01bb091f5fbb970d-pi"><img title="W1" alt="W1" src="http://revolution-computing.typepad.com/.a/6a010534b1db25970b01bb091f5fbb970d-800wi" border="0"></a></p>
<h2>Business Problem and Solution</h2>
<p>While load shaping is surely in our future, variably-priced energy for consumers is still very much the exception — due in part to the relative rarity of smart meter deployment.</p>
<p>However, one form that is very common in the commercial market place is “demand charging”, or a demand surcharge that is proportionate to the worst 15-minute period in a month. This is rarely seen in the retail market, but is pretty common worldwide in the commercial space as it is easy to implement without smart meters. For example, note the following figure, a typical bill for a rather large building on campus. The demand charge is a power charge (kW), whereas all of the other consumption based charges are for energy (kWH).</p>
<p><a target="_blank" href="http://revolution-computing.typepad.com/.a/6a010534b1db25970b01bb091f5fd6970d-pi"><img title="W2" alt="W2" src="http://revolution-computing.typepad.com/.a/6a010534b1db25970b01bb091f5fd6970d-800wi" border="0"></a></p>
<p>On this campus the worst peaks occur on some cold winter mornings, when the buildings are electrically heated and have been allowed to cool down overnight. This means that they will have to be heated up aggressively again, just as everyone is coming in and powering up their computer, brewing coffee, and turning on the lights. This is sometimes referred to as “Sharktoothing” because of shape of the energy usage profile.</p>
<p>So what we want to do is get rid of the peaks, by spending a relatively small amount of energy to preheat the buildings on cold nights.</p>
<p><a target="_blank" href="http://revolution-computing.typepad.com/.a/6a010534b1db25970b01bb091f5fe6970d-pi"><img title="W3" alt="W3" src="http://revolution-computing.typepad.com/.a/6a010534b1db25970b01bb091f5fe6970d-800wi" border="0"></a></p>
<p>While this has been attempted manually in the past, it was abandoned then due to several reasons:</p>
<ul>
<li>It was hard to predict the size of the peaks as they were sensitive to weather and whether or not it was going to be necessary to perform the preheating.</li>
<li>It was difficult to manually guess the optimal pre-heating profile to avoid the peak but also minimize energy usage.</li>
</ul>
<p>So this was seen as a natural for an automated Machine Learning approach.</p>
<h2>Model Design – going from Predictive to Prescriptive Modeling</h2>
<p>In a previous project, we had created weather and time-based energy prediction models for these buildings, and we anticipated this would be an easy extension of those models, using much of the same data and code. This proved not to be true, and is typical of what can happen when a purely <em>predictive solution</em> is adapted into being <em>prescriptive solution</em>, where the algorithms not only have to predict the future, but show an optimal course forward. This is because there were two things that needed to be done that were not necessary in the predictive model:</p>
<ul>
<li>The control variable (the control of the thermostat settings) was not in the original model as that behavior did not vary with the weather and thus did not affect energy prediction. As these settings are building and time dependent we need an entirely new model to predict these as well.</li>
<li>There was no tracking of the temperature (i.e. the stored energy) in the original models. Obviously we were going to need this if we were going to be able to optimize the values.</li>
<li>There are thousands of thermostat and temperature measurements in our biggest buildings, so they needed to be aggregated and cleansed as well.</li>
</ul>
<p><a target="_blank" href="http://revolution-computing.typepad.com/.a/6a010534b1db25970b01b7c87be0b4970b-pi"><img title="W4" alt="W4" src="http://revolution-computing.typepad.com/.a/6a010534b1db25970b01b7c87be0b4970b-800wi" border="0"></a></p>
<p>So we had to cleanse new data and develop two new models. We used <em>RandomForest</em> for all of them as that had worked well in the prediction project, using the <em>caret</em> library to tune the model and compare different techniques with each other. Our plots were all in <em>ggplot2</em> (and a bit of <em>rgl</em>), but we also made extensive use of many other elements of the “tidy-verse” like <em>dplyr</em> and <em>reshape2</em>. Our data resided in a <em>Hive</em> database running under <em>Azure HDInsight.</em></p>
<p>Also, as in the preceding project, we made heavy use of R-markdown here to document our various approaches and find the best cleansing techniques and models. This phase was mostly before the advent of <em>RTVS (R Tools for Visual Studio) </em>and we used <em>R-Studio</em> for most of it, though we did use these results in “alpha-trials” of RTVS.</p>
<h2>Stabilizing Model</h2>
<p>In the end we had was amounted to a dynamic model, with some of the functions being estimated from data. <a target="_blank" href="http://revolution-computing.typepad.com/.a/6a010534b1db25970b01b8d205b768970c-pi"><img title="W5" alt="W5" src="http://revolution-computing.typepad.com/.a/6a010534b1db25970b01b8d205b768970c-800wi" border="0"></a></p>
<p>Of course a dynamic model is not guaranteed to converge (it is not subject to the same physical constraints that reality is), and we indeed had a number of convergence problems, that we eventually overcame by adjusting various parameters and choosing different sets of explanatory variables.</p>
<p><a target="_blank" href="http://revolution-computing.typepad.com/.a/6a010534b1db25970b01b7c87be0ca970b-pi"><img title="W6" alt="W6" src="http://revolution-computing.typepad.com/.a/6a010534b1db25970b01b7c87be0ca970b-800wi" border="0"></a></p>
<h2>Validation Work</h2>
<p>Originally we had intended to trial this in the winter of 2015/2016 but model development took longer than planned and the Pacific North West experienced an unusually warm winter anyway. So we took to simulations to try out our model. For deployment we went with a R-Shiny application, developed in R-Studio and later RTVS as that allows the engineers to try out various optimization parameters and see how well the load shaping worked.</p>
<p><a target="_blank" href="http://revolution-computing.typepad.com/.a/6a010534b1db25970b01bb091f6048970d-pi"><img title="W7" alt="W7" src="http://revolution-computing.typepad.com/.a/6a010534b1db25970b01bb091f6048970d-800wi" border="0"></a></p>
<p>We used a simple brute-force optimization (simply trying out various parameter values laid out in a 2D-grid) as we were at this point only interested in seeing if the model worked. A more sophisticated optimization algorithm will be developed before deployment.</p>
<p>In the four panel plots (each with nine panels) in the figure below we see how varying the pre-heating values in 0.1, 0.5, 0.9 percent (in the X-direction) over 2, 3, and 4 hours (in the Y-direction) before 7:45 AM result in different energy use profiles and internal air temperatures (IAT) in the building, in this case the optimal result is the maximum preheating (0.9 for 4 hours), not unexpected as this was our biggest recorded peak in the data and thus required a large amount of pre-heating. The peak was reduced by about 25% in this case (the blue area).</p>
<p><a target="_blank" href="http://revolution-computing.typepad.com/.a/6a010534b1db25970b01b8d205b789970c-pi"><img title="W8" alt="W8" src="http://revolution-computing.typepad.com/.a/6a010534b1db25970b01b8d205b789970c-800wi" border="0"></a></p>
<h2>Future Plans</h2>
<p>While we have developed convincing models that fit our measured data, it is the nature of prescriptive solutions that they predict behavior outside of the measured envelope. Thus we need to try this out in a real life situation to see if the building actually behaves in this manner when so controlled. We are aiming for a deployment in the in the winter of 2016/17, whereby we will of course also need cooperation from the winter weather to deliver some cold days for us to test with.</p>
<p>And while it is clear that this particular solution is only interesting to electrically heated buildings in cold climates, the general approach of applying load shaping to HVAC systems to achieve optimal-cost energy usage under a variable energy price regime is an application that will clearly see wide-scale deployment as we move to sustainable energy solutions. </p>
</div>
<p><div><div><div><div data-width="55" data-show-faces="false" data-send="true" data-layout="box_count" data-height="62" data-href="http://www.r-bloggers.com/sustainability-through-energy-load-shaping-for-buildings-using-r/"></div></div><div><a data-url="http://www.r-bloggers.com/sustainability-through-energy-load-shaping-for-buildings-using-r/" data-counturl="http://www.r-bloggers.com/sustainability-through-energy-load-shaping-for-buildings-using-r/" data-count="vertical" data-text="Sustainability through Energy Load Shaping for Buildings using R" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://blog.revolutionanalytics.com/2016/07/energy-load-shaping.html"> Revolutions</a></strong>.</div>
<hr>
<a rel="nofollow" href="http://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="http://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="http://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="http://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="http://www.r-bloggers.com/?s=Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="http://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="http://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="http://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="http://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="http://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="http://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="http://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="http://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="http://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="http://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="http://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="http://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="http://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="http://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/VaVMxupQmVI"></a></div>