Emulating a PID Controller with Long Short-term Memory

Welcome to Part 2 of this exciting project! The results have looked great so far, and now we can get into the meat of what we’re trying to accomplish: emulating the behavior of a PID controller with an LSTM. As a recap, here’s what we’ve explored so far and where we’re going:

  1. Using the Temperature Control Lab to create Proportional-Integral-Derivative controller data
  2. Training a Long Short-term Memory neural network in Keras to emulate a PID controller (this article)
  3. Controlling the Temperature Control Lab with an LSTM
  4. Practical applications of temperature control using LSTM controller instead of PID controller (coming October 2020)

If you want to run this code on your own, you can find it on Github. It’s heavily dependent on using the TCLab device on your computer, but eventually I plan to generate data and add some notebooks so you can run it as a standalone project as well. Of course, I always encourage you to see what principles you can take from this and apply them to your own project.

Emulate PID behavior with LSTM

After completing the last segment, we have some data to work with, and we want to see if an LSTM can emulate the behavior of the PID controller. There are some excellent articles about how LSTMs work, so I’ll point you to those if you haven’t worked with them before. Here is one of the places I went when looking at some of the math behind them, and this is a fantastic Towards Data Science article that introduced me to how they’re implemented in Python with Keras. Here’s another great tutorial that has a video. As usual, APMonitor.com is a rich resource in all things relevant to machine learning and process control.

LSTMs have been a popular approach to all types of machine learning models because of their versatility. I’ve used them in sequence prediction tasks, natural language processing, and anomaly detection; others have found applications ranging from image processing to speech recognition. What sets it apart from a standard recurrent neural network is the presence of its cell memory unit, which helps to address the vanishing gradient problem.

LSTMs work well on this type of problem because we want to remember what has been happening previously in the control system. If we just barely changed the setpoint from 35°C to 70°C, we know the heater is going to be put on max for a while to get to that setpoint. However, if we just drop from 45°C down to 42°C, or have been holding steady at say 55°C for a while, the controller will have to account differently.

In context of emulating the PID controller, we want to input a window of data, such as the temperature, setpoint, error, or heater values, and predict what the next heater value should be to reach the desired setpoint. This prediction is emulating the output that the PID controller with the given tuning constants would give us. Of course, if the tuning constants change, we’re no longer looking at the same type of controller behavior. That’s an interesting idea to explore in part 4 (coming November 2020).

#keras #lstm #python #pid-controller

What is GEEK

Buddha Community

Emulating a PID Controller with Long Short-term Memory

Emulating a PID Controller with Long Short-term Memory

Welcome to Part 2 of this exciting project! The results have looked great so far, and now we can get into the meat of what we’re trying to accomplish: emulating the behavior of a PID controller with an LSTM. As a recap, here’s what we’ve explored so far and where we’re going:

  1. Using the Temperature Control Lab to create Proportional-Integral-Derivative controller data
  2. Training a Long Short-term Memory neural network in Keras to emulate a PID controller (this article)
  3. Controlling the Temperature Control Lab with an LSTM
  4. Practical applications of temperature control using LSTM controller instead of PID controller (coming October 2020)

If you want to run this code on your own, you can find it on Github. It’s heavily dependent on using the TCLab device on your computer, but eventually I plan to generate data and add some notebooks so you can run it as a standalone project as well. Of course, I always encourage you to see what principles you can take from this and apply them to your own project.

Emulate PID behavior with LSTM

After completing the last segment, we have some data to work with, and we want to see if an LSTM can emulate the behavior of the PID controller. There are some excellent articles about how LSTMs work, so I’ll point you to those if you haven’t worked with them before. Here is one of the places I went when looking at some of the math behind them, and this is a fantastic Towards Data Science article that introduced me to how they’re implemented in Python with Keras. Here’s another great tutorial that has a video. As usual, APMonitor.com is a rich resource in all things relevant to machine learning and process control.

LSTMs have been a popular approach to all types of machine learning models because of their versatility. I’ve used them in sequence prediction tasks, natural language processing, and anomaly detection; others have found applications ranging from image processing to speech recognition. What sets it apart from a standard recurrent neural network is the presence of its cell memory unit, which helps to address the vanishing gradient problem.

LSTMs work well on this type of problem because we want to remember what has been happening previously in the control system. If we just barely changed the setpoint from 35°C to 70°C, we know the heater is going to be put on max for a while to get to that setpoint. However, if we just drop from 45°C down to 42°C, or have been holding steady at say 55°C for a while, the controller will have to account differently.

In context of emulating the PID controller, we want to input a window of data, such as the temperature, setpoint, error, or heater values, and predict what the next heater value should be to reach the desired setpoint. This prediction is emulating the output that the PID controller with the given tuning constants would give us. Of course, if the tuning constants change, we’re no longer looking at the same type of controller behavior. That’s an interesting idea to explore in part 4 (coming November 2020).

#keras #lstm #python #pid-controller

Emulating a PID Controller with Long Short-term Memory

Do you ever just get really excited about an idea? Maybe it’s a new DIY project you’re tackling, or a cool assignment at work. Maybe you’re crazy like me and want to hike the Pacific Crest Trail (as I’m moving to Seattle soon, so I can’t help but get excited about the idea of flying down to San Diego and walking home). Well, this project is one of those types of ideas for me, and I hope you enjoy the ride!

Before I get started, though, I want to warn you that this is quite an extensive project, and so I’m breaking it up into parts. They will be as follows:

  1. Using the Temperature Control Lab to create Proportional-Integral-Derivative controller data (this article)
  2. Training a Long Short-term Memory neural network to emulate a PID controller (coming October 2020)
  3. Controlling the Temperature Control Lab with an LSTM (coming October 2020)
  4. Practical applications of temperature control using LSTM controller instead of PID controller (coming November 2020)

Project Framework

While working on a project for work one day, I came across a paper that introduced a novel idea. Some researchers had the idea to emulate the behavior of a model predictive control (MPC) strategy using a neural network. The idea was that some MPC problems are extremely computationally expensive, but the behavior is predictable;** if we could emulate that behavior by training a deep neural network, we could, in theory, replace the computationally expensive MPC with a much faster machine learning model.** The only computationally expensive part of the process would be the model training.

The really neat part of this is that I test the idea here at my desk. The Temperature Control Lab is perfectly designed to prototype this kind of problem. I introduced the TCLab and some basic anomaly detection you can do with machine learning in an earlier post. If you’re new to the TCLab, you can check out my article, or look at the abundant resources at APMonitor.com.

So here’s what I decided to try: I wanted to tune a Proportional-Integral-Derivative (PID) controller so I could set a temperature on the TCLab and the controller would adjust the heater until it hit that setpoint. Then, I wanted to see if I could emulate this behavior with a Long Short-term Memory neural network. If this prototype worked, it would open the doors for not only improving computational speed, but also applications such as anomaly detection.

This series is about the machine learning, so if you’re not familiar with PID controllers or control theory, that’s perfectly fine; we’ll just hit a few highlights so you understand the context. There are some amazing resources at APMonitor.com to help you understand PID controllers and how to tune them. These controllers are ubiquitous in engineering industry, and so the potential applications for this are numerous.

#python #pid-controller #machine-learning #lstm

Build & Deploy a Telegram Bot with short-term and long-term memory

Create a Chatbot from scratch that remembers and reminds events with Python

Summary

In this article, using Telegram and Python, I will show how to build a friendly Bot with multiple functions that can chat with question-answering conversations (short-term information) and store user data to recall in the future (long-term information).

All this started because a friend of mine yelled at me for not remembering her birthday. I don’t know if that has ever happened to you. So I thought I could pretend I remember birthdays while I actually have a Bot doing it for me. Now I know what you’re thinking, why building something from scratch instead of using one of the millions of calendar apps around? And you’re right, but for nerds like us … what’s the fun in that?

Through this tutorial, I will explain step by step how to build an intelligent Telegram Bot with Python and MongoDB and how to deploy it for free with Heroku and Cron-Job,using my Dates Reminder Bot as an example(link below).

I will present some useful Python code that can be easily applied in other similar cases (just copy, paste, run) and walk through every line of code with comments so that you can replicate this example (link to the full code below).

In particular, I will go through:

  • Setup: architecture overview, new _Telegram _Bot generation, _MongoDB _connection, _Python _environment.
  • Front-end: code the Bot commands for user interaction with pyTelegramBotAPI.
  • Back-end: create the server-side app with _flask _and threading.
  • Deploy the Bot through Heroku and Cron-Job

#artificial-intelligence #programming #web-development #chatbots #engineering #build & deploy a telegram bot with short-term and long-term memory

Arne  Denesik

Arne Denesik

1603400400

Emulating a PID Controller with Long Short-term Memory

Welcome to part 3 of this project! By now, your employer is looking at your results and saying “so what?” You’ve done a lot of legwork in getting things going, but so far it just looks nice on a computer. Well, here’s the “so what” part. Here’s where we finally get to implement this LSTM neural network to emulate the behavior of the PID controller. As a quick recap, here’s where we’ve been and where we’re going:

  1. Using the Temperature Control Lab to create Proportional-Integral-Derivative controller data
  2. Training a Long Short-term Memory neural network in Keras to emulate a PID controller
  3. Controlling the Temperature Control Lab with an LSTM (this article)
  4. Practical applications of temperature control using LSTM controller instead of PID controller (coming October 2020)

As always, feel free to run the code on your own, ideally with the Temperature Control Lab so you can see live data.

One Last Check

Although we checked the LSTM controller output last time, we still want to practice safety first. We don’t want to debug our control loop while running something as sensitive as a reactor temperature. So, to start, we’ll keep our PID controller, but also compute the LSTM controller output. This allows us to see what the LSTM controller that we programmed does in comparison to the PID controller, and also debug it.

You’re familiar with this by now, but setting up the run requires just a few tweaks:

##### Set up run ####

## Import model and model parameters
model = load_model('pid_emulate.h5')
model_params = pickle.load(open('model_params.pkl', 'rb'))
s_x = model_params['Xscale']
s_y = model_params['yscale']
window = model_params['window']
## Run time in minutes
run_time = 30.0
## Number of cycles
loops = int(60.0*run_time)
## arrays for storing data
T1 = np.zeros(loops) ## measured T (degC)
Qpid = np.zeros(loops) ## Heater values for PID controller
Qlstm = np.zeros(loops) ## Heater values for LSTM controller
tm = np.zeros(loops) ## Time
## Temperature set point (degC)
with tclab.TCLab() as lab:
    Tsp = np.ones(loops) * lab.T1
## vary temperature setpoint
## leave 1st window + 15 seconds of temp set point as room temp
end = window + 15 
while end <= loops: 
    start = end
    ## keep new temp set point value for anywhere from 4 to 10 min
    end += random.randint(240,600) 
    Tsp[start:end] = random.randint(30,70)
## leave last 120 seconds as room temp
Tsp[-120:] = Tsp[0]

#pid #machine-learning #lstm #python

Apps For Short News – The Trend Is About To Arrive

Short news apps are the future, and if they will play a defining role in changing the way consumers consume their content and how the news presenters write their report.

If you want to build an app for short news then you can check out some professional app development companies for your app project As we head into the times where mobile applications and smartphones will be used for anything and everything, the short news applications will allow the reader to choose from various options and read what they want to read.

#factors impacting the short news apps #short news applications #personalized news apps #short news mobile apps #short news apps trends #short news apps