‫In this lecture, we are going to discuss a practical matter, we're going to cover a question I get
‫very often from beginners, which is why do we have to do all this programming and math?
‫Why can't we just use a library?
‫I often hear that in order to be so-called practical, one must use libraries.
‫Now, first, let's start with being practical is a great thing.
‫Putting all this theory into practice is obviously the end goal.
‫There are two problems with this beginner question.
‫Number one, people often use this as an excuse for the fact that they don't have the ability to do
‫the math or write the code.
‫So that's very important.
‫A library can be a replacement for a lack of ability and skill.
‫Number two, there are no libraries that will fit your use case.
‫So what you're asking for does not even exist.
‫A true matter of practicality is that if you're going to ask for something, you have to know what you're
‫asking for in the first place.
‫And many people who do ask this question simply don't.
‫The rest of this lecture will explain why.
‫OK, so why are there no libraries that will help us implement these algorithms in a so-called practical
‫manner?
‫Well, let's think about the code we just wrote.
‫How much of it was devoted to the actual algorithm itself?
‫Let's count.
‫We have one line of code to sample from our posterior distribution.
‫We have two lines of code to update the posterior distribution.
‫And finally, we have one more line of code to select a bandit by choosing the Amax over the samples.
‫In total, that's four lines of code.
‫Let's ask ourselves, do we need a library for four lines of code?
‫In actuality, we do not need a library for just a few lines of code.
‫Most of the work that you need to do when implementing this algorithm in the real world is actually
‫outside of this so-called library and has more to do with backend engineering in order to make this
‫lecture complete.
‫I'm going to explain what this backend engineering involves.
‫Even though some of you may not be back in engineers, I hope that it at least helps you understand
‫why the idea of looking for a library to do this job does not make any sense.
‫First, let's consider that many back in service do not use Python, Python is a slow language.
‫Some companies do use Python as a back end, but it's not as ubiquitous as it is for, say, data science
‫and machine learning.
‫Many companies use other languages and frameworks such as Ruby on Rails, Java, Scala, Erlang, Go
‫and C++.
‫And in many of these languages, doing data science is not a popular thing.
‫So you're unlikely to find something like a library for Bayesian statistics.
‫It just doesn't exist.
‫But again, you don't need a library for a few lines of code anyway.
‫So what are the tasks that actually need to be done?
‫First, you're going to need a centralized data store, whether that's an actual database or a key value
‫store, which holds all of your band at arm's parameters.
‫Unlike our toy examples, that's not going to exist in memory in the real world, you might have 10
‫or 20 servers all around the world.
‫Obviously, you can't keep the data on each machine synchronized and replicated.
‫Exactly on all of these servers.
‫You need to have a database of some kind.
‫In addition, your data might be stored in log files if you don't want to deal with them in real time
‫due to performance issues.
‫So you might need to have some botched job that ingests these log files periodically and then uses that
‫data to update the parameters of your model in an offline setting.
‫That would be an entirely separate computer program living on separate machines.
‫So clearly, a single library on a single machine is not going to do the job, you're going to have
‫your botched job workers and your Web servers, and they're both responsible for two totally different
‫things.
‫In fact, your best jobs and your Web services may not even be written in the same programming language
‫in the first place.
‫So where does a library fit into this architecture?
‫In reality, code like this is not fit for a library.
‫The libraries you do need to worry about might be as follows.
‫First, you want to have a Web server framework.
‫Obviously, this falls more into the responsibilities of the backend engineering team rather than the
‫data scientist team.
‫Maybe that's Jango or Ruby on Rails or the C++ active framework.
‫Then you need to figure out what database you're going to use that could be postgrads MySQL readies
‫or memcache.
‫You'll also need a library in your programming language that connects to that database, and if you're
‫processing large amounts of data in your batch jobs, you might need to perform these jobs on a cluster
‫of machines.
‫In that case, you might use a library like Apache Spark.
‫So this is the kind of thing you need to worry about in terms of libraries, in comparison, the actual
‫lines of code that implement your Bendit algorithm are minuscule overall.
‫I hope it's clear that a library for doing such a task in this context would not make sense.