SlideShare a Scribd company logo
1 of 50
Download to read offline
Power Laws: Optimizing
Demand-side Strategies
Second prize solution
guillermobarbadillo@gmail.com
Introduction
2
Power Laws: Optimizing Demand-side
Strategies
This is one of three challenges in the “Power Laws” series being run
simultaneously by Schneider Electric
They are hosted on drivendata.org
3
Power Laws: Optimizing Demand-side
Strategies
Your goal in this competition is to
build an algorithm that controls a
battery charging system and spends
the least amount of money over a
simulation period.
4
Resources
● Train and public test datasets for 11 different sites (csv files). About 2.8GB
of data.
● A simulation that runs on docker and computes the score for our algorithm
The private test dataset is not known and it has not been published.
5
Submission
At the end of the challenge we have to provide a python script called
battery_controller.py that implements a BatteryController class that will be used
by the simulation.
A folder called assets may be used with models or data that the controller
uses.
The simulation should be able to run 240 simulations (2400 days) in less than
30 minutes. A dummy controller takes 10 minutes, so that leaves a small
margin. 6
Data exploration
7
Data
● Data every 15 minutes
● 11 different sites
● The duration of the train data is about 400 days and
100 days for the public test set
● The data is divided into smaller periods of time. 10
days for the test set
● 2.2GB for train and 0.5GB of data for the public test
● Csv files
8
Features
● Energy demand and photovoltaic production at each timestep
● Forecast for the following 96 timesteps (1 day)
○ Price of selling and buying energy
○ Energy demand
○ Photovoltaic production
And we are also given the properties of the battery: capacity, charge and
discharge power, charge and discharge efficiency
9
Data exploration
Understanding the data is crucial for designing a good model/algorithm. As a
consequence of the No free lunch theorem we have to adapt our solution to the
data in order to get the maximum performance.
Jupyter notebooks are are great tool for loading, analyzing and visualizing data.
On the following slides I will show some visualizations that help to get insights
into the data
10
Visualization of the time periods for the
different sites
11
Consumption and photovoltaic production
12
Consumption and photovoltaic production
13
Price schemes
14
Price schemes
15
Findings on the data
● Clear periodicity of the data. Days and weeks. Weekends can be observed
● Different ratios between consumption and photovoltaic production
between the different sites
● 2 prices and 3 prices schemes
16
Accuracy of the forecast on different sites
17
Influence of the forecast length
18
Conclusions about the forecast
● Different sites have different accuracy
● The longer the prediction the smaller the accuracy
19
First steps and initial approach
20
Initial approach
1. Find the optimum policy (this is assumed to be a slow process)
2. Train a fast model to learn the policy
That would met both the requirements of minimizing the cost and the
execution time constraint
21
Genetic algorithms
● The genome is as long as the number of timesteps of the period
● Each gene will be 0 if we want to discharge the battery or 1 if we want to
charge it
● The goal is to minimize the cost of the period
22
Genetic algorithms
● Very slow: 2 hours to optimize a period
● The optimization was not as good as future optimizations
● The search space is very big 2^960
Probably this is optimization is not a good choice
Probably we have to simplify the problem
23
Other perspective to the data
24
New representation of the data
● The consumption and photovoltaic production are not relevant. What
matters is the energy balance
● Sell price is always constant, so we don’t need to plot it
25
Energy balance and buy price
26
It’s possible to simplify the problem
● We can group the timesteps into bigger blocks
● The criteria for joining timesteps is that they have the same buy price.
○ If we have the same buy price on several consecutive timesteps it is not relevant if I buy
energy on the first or the last timestep. The cost will be the same
● If the energy balance changes that is also a reason for breaking a block.
○ If the energy balance is negative then we have the opportunity to charge the battery using
that energy. It is equivalent of buying that amount of energy at the sell price at that
moment, which is equivalent to a change in the buy price
27
Energy balance and buy price before simplification
28
Energy balance and buy price after simplification
29
Effects of the simplification
We have reduced the length of the period from 960 steps to just 40.
The search space is now much more smaller, so the optimization algorithms
will run much faster.
30
Dynamic programming
31
Dynamic programming (Wikipedia)
Is a method for solving a complex problem by breaking it down into a collection
of simpler subproblems, solving each of those subproblems just once, and
storing their solutions.
The next time the same subproblem occurs, instead of recomputing its
solution, one simply looks up the previously computed solution, thereby saving
computation time at the expense of a (hopefully) modest expenditure in
storage space.
32
Dynamic programming
Useful in processes where the history is not relevant for taking decisions, the
only relevant is the current state.
This is our case: the only relevant information is the current state of the battery.
When the battery was charged or discharged is not relevant for taking
decisions.
This simplifies a lot the search space
33
Simple example: 2 actions and 3 epochs
34
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
Action pruning
35
Why action pruning
In order for dynamic programming to be fast the number of available actions
on each state is very relevant.
The more the freedom on each state the more the bigger the search space and
the slower the algorithm.
We have to careful select which actions are available on each state.
36
Available actions
● To do the opposite as the system. This allows to supply the exact amount
of demanded energy or to charge the battery with the exact energy
provided by the system
● If we are on a block with low buy price we can charge the whole battery
● If the simulation is close to the end we allow to do nothing or even to
discharge the battery. This allows to arrive to the end without charge on
the battery
37
Available actions
● If the system is demanding energy but higher prices are expected soon it is
allowed to supply energy to the system but leaving enough energy for the
incoming block with higher prices
38
Available actions
Notice that 3 of the 4 available actions are conditional.
In most of the cases there would be just one or two available actions
39
Summary of all the simplifications
● Period simplification. Reduces the length of the period
● Dynamic programming. Reduces the search space
● Action pruning. Reduces the search space
This allows to optimize the whole train set in less than 15 seconds. (8800 days
of optimization). At the start of the challenge we needed 2 hours to optimize 10
days. The speedup is 4e5.
This speed eliminates the need to train a model to learn the policy. We can
simply use this optimization to solve the challenge. 40
From high level policy to low level
We are using a simplification of the period for optimizing the policy. This way
we get a high level policy.
However we have to take decisions on each timestep. So I had to implement
methods for translating the high level policy into a low level policy.
41
Forecast inaccuracies
42
Forecast inaccuracies
Until now all the optimizations where done using perfect information. However
during the simulation we only have access to forecasts of future values and to
the previous real values.
The inaccuracy in the forecast reduces slightly the cost optimization. For the
public test set the metric drops from -0.2173 to -0.1920 (the approximate
meaning of this metric is that we save a 21% of the cost comparing to a
building without the battery)
43
Improving the forecast
I tried different neural networks to improve the forecast. However the best
solution was to use simple linear regression.
As input I used used:
● The forecast for the timestep
● The real values of the two previous timesteps
This allows to improve the score on public test set from -0.1920 to -0.1922
44
Other useful stuff
45
Cprofile and snakeviz
They helped a lot to make a faster
implementation in code of the ideas
previously described.
Clear visualization of the
bottlenecks that guides the
optimization work of the code
46
Unit testing
It was very helpful to make fast iterations being sure that nothing was broken
when making changes to the optimizer
47
Results
48
Results
Public test set: -0.1922
Private test set: -0.1992
49
Links
https://www.drivendata.org/competitions/53/optimize-photovoltaic-battery/
50

More Related Content

Similar to Optimizing Battery Charging Costs with Dynamic Programming and Forecasting

Training Deep Networks with Backprop (D1L4 Insight@DCU Machine Learning Works...
Training Deep Networks with Backprop (D1L4 Insight@DCU Machine Learning Works...Training Deep Networks with Backprop (D1L4 Insight@DCU Machine Learning Works...
Training Deep Networks with Backprop (D1L4 Insight@DCU Machine Learning Works...Universitat Politècnica de Catalunya
 
PR-330: How To Train Your ViT? Data, Augmentation, and Regularization in Visi...
PR-330: How To Train Your ViT? Data, Augmentation, and Regularization in Visi...PR-330: How To Train Your ViT? Data, Augmentation, and Regularization in Visi...
PR-330: How To Train Your ViT? Data, Augmentation, and Regularization in Visi...Jinwon Lee
 
TSO Reliability Management: a probabilistic approach for better balance betwe...
TSO Reliability Management: a probabilistic approach for better balance betwe...TSO Reliability Management: a probabilistic approach for better balance betwe...
TSO Reliability Management: a probabilistic approach for better balance betwe...Leonardo ENERGY
 
Exploiting a Synergy between Greedy Approach and NSGA for Scheduling in Compu...
Exploiting a Synergy between Greedy Approach and NSGA for Scheduling in Compu...Exploiting a Synergy between Greedy Approach and NSGA for Scheduling in Compu...
Exploiting a Synergy between Greedy Approach and NSGA for Scheduling in Compu...Tarik Reza Toha
 
ProxGen: Adaptive Proximal Gradient Methods for Structured Neural Networks (N...
ProxGen: Adaptive Proximal Gradient Methods for Structured Neural Networks (N...ProxGen: Adaptive Proximal Gradient Methods for Structured Neural Networks (N...
ProxGen: Adaptive Proximal Gradient Methods for Structured Neural Networks (N...Jihun Yun
 
ROOM LIGHT CONTROL SYSTEM PROJECT PRESENTATION BY BITAN DAS AND MADHURIMA BASU
ROOM LIGHT CONTROL SYSTEM PROJECT PRESENTATION BY BITAN DAS AND MADHURIMA BASUROOM LIGHT CONTROL SYSTEM PROJECT PRESENTATION BY BITAN DAS AND MADHURIMA BASU
ROOM LIGHT CONTROL SYSTEM PROJECT PRESENTATION BY BITAN DAS AND MADHURIMA BASUBitan Das
 
Agile Kolkata 2023 I Deep Learning for Sustainable Energy: A journey - Dr Sap...
Agile Kolkata 2023 I Deep Learning for Sustainable Energy: A journey - Dr Sap...Agile Kolkata 2023 I Deep Learning for Sustainable Energy: A journey - Dr Sap...
Agile Kolkata 2023 I Deep Learning for Sustainable Energy: A journey - Dr Sap...AgileNetwork
 
Parametric Estimation in a nutshell
Parametric Estimation in a nutshellParametric Estimation in a nutshell
Parametric Estimation in a nutshellPlanisware
 
Design and optimization of pid controller using genetic algorithm
Design and optimization of pid controller using genetic algorithmDesign and optimization of pid controller using genetic algorithm
Design and optimization of pid controller using genetic algorithmeSAT Journals
 
Uber Data Analysis - SAS Project
Uber Data Analysis - SAS ProjectUber Data Analysis - SAS Project
Uber Data Analysis - SAS ProjectKushal417
 
Reactive by example (DevOpsDaysTLV 2019)
Reactive by example (DevOpsDaysTLV 2019)Reactive by example (DevOpsDaysTLV 2019)
Reactive by example (DevOpsDaysTLV 2019)Eran Harel
 
Deep Learning Based Integrated Energy Efficiency Optimization for Smart Building
Deep Learning Based Integrated Energy Efficiency Optimization for Smart BuildingDeep Learning Based Integrated Energy Efficiency Optimization for Smart Building
Deep Learning Based Integrated Energy Efficiency Optimization for Smart Buildingeliyart
 
Dynamic Matrix Control (DMC) on jacket tank heater - Rishikesh Bagwe
Dynamic Matrix Control (DMC) on jacket tank heater - Rishikesh BagweDynamic Matrix Control (DMC) on jacket tank heater - Rishikesh Bagwe
Dynamic Matrix Control (DMC) on jacket tank heater - Rishikesh BagweRishikesh Bagwe
 
A progressive domain expansion method for solving optimal control problem
A progressive domain expansion method for solving optimal control problemA progressive domain expansion method for solving optimal control problem
A progressive domain expansion method for solving optimal control problemTELKOMNIKA JOURNAL
 
Customer choice probabilities
Customer choice probabilitiesCustomer choice probabilities
Customer choice probabilitiesAllan D. Butler
 
08 neural networks
08 neural networks08 neural networks
08 neural networksankit_ppt
 
IREC part 02
IREC part 02IREC part 02
IREC part 02RCREEE
 

Similar to Optimizing Battery Charging Costs with Dynamic Programming and Forecasting (20)

Training Deep Networks with Backprop (D1L4 Insight@DCU Machine Learning Works...
Training Deep Networks with Backprop (D1L4 Insight@DCU Machine Learning Works...Training Deep Networks with Backprop (D1L4 Insight@DCU Machine Learning Works...
Training Deep Networks with Backprop (D1L4 Insight@DCU Machine Learning Works...
 
PR-330: How To Train Your ViT? Data, Augmentation, and Regularization in Visi...
PR-330: How To Train Your ViT? Data, Augmentation, and Regularization in Visi...PR-330: How To Train Your ViT? Data, Augmentation, and Regularization in Visi...
PR-330: How To Train Your ViT? Data, Augmentation, and Regularization in Visi...
 
TSO Reliability Management: a probabilistic approach for better balance betwe...
TSO Reliability Management: a probabilistic approach for better balance betwe...TSO Reliability Management: a probabilistic approach for better balance betwe...
TSO Reliability Management: a probabilistic approach for better balance betwe...
 
Thesis1
Thesis1Thesis1
Thesis1
 
Exploiting a Synergy between Greedy Approach and NSGA for Scheduling in Compu...
Exploiting a Synergy between Greedy Approach and NSGA for Scheduling in Compu...Exploiting a Synergy between Greedy Approach and NSGA for Scheduling in Compu...
Exploiting a Synergy between Greedy Approach and NSGA for Scheduling in Compu...
 
ProxGen: Adaptive Proximal Gradient Methods for Structured Neural Networks (N...
ProxGen: Adaptive Proximal Gradient Methods for Structured Neural Networks (N...ProxGen: Adaptive Proximal Gradient Methods for Structured Neural Networks (N...
ProxGen: Adaptive Proximal Gradient Methods for Structured Neural Networks (N...
 
ROOM LIGHT CONTROL SYSTEM PROJECT PRESENTATION BY BITAN DAS AND MADHURIMA BASU
ROOM LIGHT CONTROL SYSTEM PROJECT PRESENTATION BY BITAN DAS AND MADHURIMA BASUROOM LIGHT CONTROL SYSTEM PROJECT PRESENTATION BY BITAN DAS AND MADHURIMA BASU
ROOM LIGHT CONTROL SYSTEM PROJECT PRESENTATION BY BITAN DAS AND MADHURIMA BASU
 
Agile Kolkata 2023 I Deep Learning for Sustainable Energy: A journey - Dr Sap...
Agile Kolkata 2023 I Deep Learning for Sustainable Energy: A journey - Dr Sap...Agile Kolkata 2023 I Deep Learning for Sustainable Energy: A journey - Dr Sap...
Agile Kolkata 2023 I Deep Learning for Sustainable Energy: A journey - Dr Sap...
 
Parametric Estimation in a nutshell
Parametric Estimation in a nutshellParametric Estimation in a nutshell
Parametric Estimation in a nutshell
 
Design and optimization of pid controller using genetic algorithm
Design and optimization of pid controller using genetic algorithmDesign and optimization of pid controller using genetic algorithm
Design and optimization of pid controller using genetic algorithm
 
Uber Data Analysis - SAS Project
Uber Data Analysis - SAS ProjectUber Data Analysis - SAS Project
Uber Data Analysis - SAS Project
 
Reactive by example (DevOpsDaysTLV 2019)
Reactive by example (DevOpsDaysTLV 2019)Reactive by example (DevOpsDaysTLV 2019)
Reactive by example (DevOpsDaysTLV 2019)
 
Deep Learning Based Integrated Energy Efficiency Optimization for Smart Building
Deep Learning Based Integrated Energy Efficiency Optimization for Smart BuildingDeep Learning Based Integrated Energy Efficiency Optimization for Smart Building
Deep Learning Based Integrated Energy Efficiency Optimization for Smart Building
 
N03430990106
N03430990106N03430990106
N03430990106
 
Dynamic Matrix Control (DMC) on jacket tank heater - Rishikesh Bagwe
Dynamic Matrix Control (DMC) on jacket tank heater - Rishikesh BagweDynamic Matrix Control (DMC) on jacket tank heater - Rishikesh Bagwe
Dynamic Matrix Control (DMC) on jacket tank heater - Rishikesh Bagwe
 
presentation 2.pptx
presentation 2.pptxpresentation 2.pptx
presentation 2.pptx
 
A progressive domain expansion method for solving optimal control problem
A progressive domain expansion method for solving optimal control problemA progressive domain expansion method for solving optimal control problem
A progressive domain expansion method for solving optimal control problem
 
Customer choice probabilities
Customer choice probabilitiesCustomer choice probabilities
Customer choice probabilities
 
08 neural networks
08 neural networks08 neural networks
08 neural networks
 
IREC part 02
IREC part 02IREC part 02
IREC part 02
 

Recently uploaded

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 

Recently uploaded (20)

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 

Optimizing Battery Charging Costs with Dynamic Programming and Forecasting

  • 1. Power Laws: Optimizing Demand-side Strategies Second prize solution guillermobarbadillo@gmail.com
  • 3. Power Laws: Optimizing Demand-side Strategies This is one of three challenges in the “Power Laws” series being run simultaneously by Schneider Electric They are hosted on drivendata.org 3
  • 4. Power Laws: Optimizing Demand-side Strategies Your goal in this competition is to build an algorithm that controls a battery charging system and spends the least amount of money over a simulation period. 4
  • 5. Resources ● Train and public test datasets for 11 different sites (csv files). About 2.8GB of data. ● A simulation that runs on docker and computes the score for our algorithm The private test dataset is not known and it has not been published. 5
  • 6. Submission At the end of the challenge we have to provide a python script called battery_controller.py that implements a BatteryController class that will be used by the simulation. A folder called assets may be used with models or data that the controller uses. The simulation should be able to run 240 simulations (2400 days) in less than 30 minutes. A dummy controller takes 10 minutes, so that leaves a small margin. 6
  • 8. Data ● Data every 15 minutes ● 11 different sites ● The duration of the train data is about 400 days and 100 days for the public test set ● The data is divided into smaller periods of time. 10 days for the test set ● 2.2GB for train and 0.5GB of data for the public test ● Csv files 8
  • 9. Features ● Energy demand and photovoltaic production at each timestep ● Forecast for the following 96 timesteps (1 day) ○ Price of selling and buying energy ○ Energy demand ○ Photovoltaic production And we are also given the properties of the battery: capacity, charge and discharge power, charge and discharge efficiency 9
  • 10. Data exploration Understanding the data is crucial for designing a good model/algorithm. As a consequence of the No free lunch theorem we have to adapt our solution to the data in order to get the maximum performance. Jupyter notebooks are are great tool for loading, analyzing and visualizing data. On the following slides I will show some visualizations that help to get insights into the data 10
  • 11. Visualization of the time periods for the different sites 11
  • 16. Findings on the data ● Clear periodicity of the data. Days and weeks. Weekends can be observed ● Different ratios between consumption and photovoltaic production between the different sites ● 2 prices and 3 prices schemes 16
  • 17. Accuracy of the forecast on different sites 17
  • 18. Influence of the forecast length 18
  • 19. Conclusions about the forecast ● Different sites have different accuracy ● The longer the prediction the smaller the accuracy 19
  • 20. First steps and initial approach 20
  • 21. Initial approach 1. Find the optimum policy (this is assumed to be a slow process) 2. Train a fast model to learn the policy That would met both the requirements of minimizing the cost and the execution time constraint 21
  • 22. Genetic algorithms ● The genome is as long as the number of timesteps of the period ● Each gene will be 0 if we want to discharge the battery or 1 if we want to charge it ● The goal is to minimize the cost of the period 22
  • 23. Genetic algorithms ● Very slow: 2 hours to optimize a period ● The optimization was not as good as future optimizations ● The search space is very big 2^960 Probably this is optimization is not a good choice Probably we have to simplify the problem 23
  • 24. Other perspective to the data 24
  • 25. New representation of the data ● The consumption and photovoltaic production are not relevant. What matters is the energy balance ● Sell price is always constant, so we don’t need to plot it 25
  • 26. Energy balance and buy price 26
  • 27. It’s possible to simplify the problem ● We can group the timesteps into bigger blocks ● The criteria for joining timesteps is that they have the same buy price. ○ If we have the same buy price on several consecutive timesteps it is not relevant if I buy energy on the first or the last timestep. The cost will be the same ● If the energy balance changes that is also a reason for breaking a block. ○ If the energy balance is negative then we have the opportunity to charge the battery using that energy. It is equivalent of buying that amount of energy at the sell price at that moment, which is equivalent to a change in the buy price 27
  • 28. Energy balance and buy price before simplification 28
  • 29. Energy balance and buy price after simplification 29
  • 30. Effects of the simplification We have reduced the length of the period from 960 steps to just 40. The search space is now much more smaller, so the optimization algorithms will run much faster. 30
  • 32. Dynamic programming (Wikipedia) Is a method for solving a complex problem by breaking it down into a collection of simpler subproblems, solving each of those subproblems just once, and storing their solutions. The next time the same subproblem occurs, instead of recomputing its solution, one simply looks up the previously computed solution, thereby saving computation time at the expense of a (hopefully) modest expenditure in storage space. 32
  • 33. Dynamic programming Useful in processes where the history is not relevant for taking decisions, the only relevant is the current state. This is our case: the only relevant information is the current state of the battery. When the battery was charged or discharged is not relevant for taking decisions. This simplifies a lot the search space 33
  • 34. Simple example: 2 actions and 3 epochs 34 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
  • 36. Why action pruning In order for dynamic programming to be fast the number of available actions on each state is very relevant. The more the freedom on each state the more the bigger the search space and the slower the algorithm. We have to careful select which actions are available on each state. 36
  • 37. Available actions ● To do the opposite as the system. This allows to supply the exact amount of demanded energy or to charge the battery with the exact energy provided by the system ● If we are on a block with low buy price we can charge the whole battery ● If the simulation is close to the end we allow to do nothing or even to discharge the battery. This allows to arrive to the end without charge on the battery 37
  • 38. Available actions ● If the system is demanding energy but higher prices are expected soon it is allowed to supply energy to the system but leaving enough energy for the incoming block with higher prices 38
  • 39. Available actions Notice that 3 of the 4 available actions are conditional. In most of the cases there would be just one or two available actions 39
  • 40. Summary of all the simplifications ● Period simplification. Reduces the length of the period ● Dynamic programming. Reduces the search space ● Action pruning. Reduces the search space This allows to optimize the whole train set in less than 15 seconds. (8800 days of optimization). At the start of the challenge we needed 2 hours to optimize 10 days. The speedup is 4e5. This speed eliminates the need to train a model to learn the policy. We can simply use this optimization to solve the challenge. 40
  • 41. From high level policy to low level We are using a simplification of the period for optimizing the policy. This way we get a high level policy. However we have to take decisions on each timestep. So I had to implement methods for translating the high level policy into a low level policy. 41
  • 43. Forecast inaccuracies Until now all the optimizations where done using perfect information. However during the simulation we only have access to forecasts of future values and to the previous real values. The inaccuracy in the forecast reduces slightly the cost optimization. For the public test set the metric drops from -0.2173 to -0.1920 (the approximate meaning of this metric is that we save a 21% of the cost comparing to a building without the battery) 43
  • 44. Improving the forecast I tried different neural networks to improve the forecast. However the best solution was to use simple linear regression. As input I used used: ● The forecast for the timestep ● The real values of the two previous timesteps This allows to improve the score on public test set from -0.1920 to -0.1922 44
  • 46. Cprofile and snakeviz They helped a lot to make a faster implementation in code of the ideas previously described. Clear visualization of the bottlenecks that guides the optimization work of the code 46
  • 47. Unit testing It was very helpful to make fast iterations being sure that nothing was broken when making changes to the optimizer 47
  • 49. Results Public test set: -0.1922 Private test set: -0.1992 49