June 16, 2021

# VIP Promotion

### The complete Time Series Analysis course has arrived

Hello friends!

2 years ago, I asked the students in my Tensorflow 2.0 course if they’d be interested in a course on time series. The answer was a resounding YES.

Don’t want to read the rest of this little spiel? Just get the coupon:

https://www.udemy.com/course/time-series-analysis/?couponCode=TIMEVIP

(Updated: Expires Dec 18, 2021) https://www.udemy.com/course/time-series-analysis/?couponCode=TIMEVIP6

(note: this VIP coupon expires in 30 days!)

Time series analysis is becoming an increasingly important analytical tool.

• With inflation on the rise, many are turning to the stock market and cryptocurrencies in order to ensure their savings do not lose their value.
• COVID-19 has shown us how forecasting is an essential tool for driving public health decisions.
• Businesses are becoming increasingly efficient, forecasting inventory and operational needs ahead of time.

Let me cut to the chase. This is not your average Time Series Analysis course. This course covers modern developments such as deep learning, time series classification (which can drive user insights from smartphone data, or read your thoughts from electrical activity in the brain), and more.

We will cover techniques such as:

• ETS and Exponential Smoothing
• Holt’s Linear Trend Model
• Holt-Winters Model
• ARIMA, SARIMA, SARIMAX, and Auto ARIMA
• ACF and PACF
• Vector Autoregression and Moving Average Models (VAR, VMA, VARMA)
• Machine Learning Models (including Logistic Regression, Support Vector Machines, and Random Forests)
• Deep Learning Models (Artificial Neural Networks, Convolutional Neural Networks, and Recurrent Neural Networks)
• GRUs and LSTMs for Time Series Forecasting

We will cover applications such as:

• Time series forecasting of sales data
• Time series forecasting of stock prices and stock returns
• Time series classification of smartphone data to predict user behavior

The VIP version of the course (obtained by purchasing the course NOW during the VIP period) will cover even more exciting topics, such as:

• AWS Forecast (Amazon’s state-of-the-art low-code forecasting API)
• GARCH (financial volatility modeling)
• FB Prophet (Facebook’s time series library)
• And MORE (it’s a secret!)

As always, please note that the VIP period may not last forever, and if / when the course becomes “non-VIP”, the VIP contents will be removed. If you purchased the VIP version, you will retain permanent access to the VIP content via my website, simply by letting me know via email you’d like access (you only need to email if I announce the VIP period is ending).

Small note:

I wanted to get this course into your hands early. Some sections are still in the editing stages, particularly:

• Convolutional Neural Networks (done, but more to be added later)
• Recurrent Neural Networks (done, but more to be added later)
• Vector Autoregression
• (VIP) GARCH
• (VIP) FB Prophet
• +MORE VIP CONTENT (it’s a surprise!)

UPDATE: The crossed-out items have since been added. There is no timeline for the remaining “surprise” lectures – it’ll be a surprise! 😉

So what are you waiting for? Get the VIP version of Time Series Analysis NOW:

# NEW COURSE: Financial Engineering and Artificial Intelligence in Python

September 8, 2020

# VIP Promotion

### The complete Financial Engineering course has arrived

Hello once again friends!

Today, I am announcing the VIP version of my latest course: Financial Engineering and Artificial Intelligence in Python.

https://www.udemy.com/course/ai-finance/?couponCode=FINANCEVIP (expires Oct 9, 2020)

https://www.udemy.com/course/ai-finance/?couponCode=FINANCEVIP15 (expires Dec 18, 2021)

(as usual, this coupon lasts only 30 days, so don’t wait!)

This is a MASSIVE (20 hours) Financial Engineering course covering the core fundamentals of financial engineering and financial analysis from scratch. We will go in-depth into all the classic topics, such as:

• Exploratory data analysis, significance testing, correlations
• Alpha and beta
• Advanced Pandas Data Frame manipulation for time series and finance
• Time series analysis, simple moving average, exponentially-weighted moving average
• Holt-Winters exponential smoothing model
• ARIMA and SARIMA
• Efficient Market Hypothesis
• Random Walk Hypothesis
• Time series forecasting (“stock price prediction”)
• Modern portfolio theory
• Efficient frontier / Markowitz bullet
• Mean-variance optimization
• Maximizing the Sharpe ratio
• Convex optimization with Linear Programming and Quadratic Programming
• Capital Asset Pricing Model (CAPM)

In addition, we will look at various non-traditional techniques which stem purely from the field of machine learning and artificial intelligence, such as:

• Regression models
• Classification models
• Unsupervised learning
• Reinforcement learning and Q-learning

We will learn about the greatest flub made in the past decade by marketers posing as “machine learning experts” who promise to teach unsuspecting students how to “predict stock prices with LSTMs”. You will learn exactly why their methodology is fundamentally flawed and why their results are complete nonsense. It is a lesson in how not to apply AI in finance.

### List of VIP-only Contents

As with my Tensorflow 2 release, some of the VIP content will be a surprise and will be released in stages. Currently, the entirety of the Algorithmic Trading sections are VIP sections. Newly added VIP sections include Statistical Factor Models and “The Lazy Programmer Bonus Offer”. Here’s a full list:

Classic Algorithmic Trading – Trend Following Strategy

You will learn how moving averages can be applied to do algorithmic trading.

Forecast returns in order to determine when to buy and sell.

I give you a full introduction to Reinforcement Learning from scratch, and then we apply it to build a Q-Learning trader. Note that this is *not* the same as the example I used in my Tensorflow 2, PyTorch, and Reinforcement Learning courses. I think the example included in this course is much more principled and robust.

Statistical Factor Models

The CAPM is one of the most renowned financial models in history, but did you know it’s only the simplest factor model, with just a single factor? To go beyond just this single factor model, we will learn about statistical factor models, where the multiple “factors” are found automatically using only the data.

The Lazy Programmer Bonus Offer

There are marketers out there who want to capitalize on your enthusiastic interest in finance, and unfortunately what they are teaching you is utter and complete garbage.

They will claim that they can “predict stock prices with LSTMs” and show you charts like this with nearly perfect stock price predictions.

Hint: if they can do this, why do they bother putting effort into making courses? Wouldn’t they already be billionaires?

Have you ever wondered if you are taking such a course from a fake data scientist / marketer? If so, just send me a message, and I will tell you whether or not you are taking such a course. (Hint: many of you are) I will give you a list of mistakes they made so you can look out for them yourself, and avoid “learning” things which will ultimately make YOU look very bad in front of potential future employers.

Believe me, if you ever try to get a job in machine learning or data science and you talk about a project where you “predicted stock prices with LSTMs”, all you will be demonstrating is how incompetent you are. I don’t want to see any of my students falling for this! Save yourself from this embarrassing scenario by taking the “Lazy Programmer Offer”!

Please note: The VIP coupon will work only for the next month (starting from the coupon creation time). It’s unknown whether the VIP period will renew after that time.

After that, although the VIP content will be removed from Udemy, all who purchased the VIP course will get permanent free access to these VIP contents on deeplearningcourses.com.

In case it’s not clear, the process is very easy. For those folks who want the “step-by-step” instructions:

STEP 1) I announce the VIP content will be removed.

STEP 2) You email me with proof that you purchased the course during the VIP period. Do NOT email me earlier as it will just get buried.

STEP 3) I will give you free access to the VIP materials for this course on deeplearningcourses.com.

### Benefits of taking this course

• Learn the knowledge you need to work at top tier investment firms
• Gain practical, real-world quantitative skills that can be applied within and outside of finance
• Make better decisions regarding your own finances

Personally, I think this is the most interesting and action-packed course I have created yet. My last few courses were cool, but they were all about topics which I had already covered in the past! GANs, NLP, Transfer Learning, Recommender Systems, etc etc. all just machine learning topics I have covered several times in different libraries. This course contains new, fresh content and concepts I have never covered in any of my courses, ever.

This is the first course I’ve created that extends into a niche area of AI application. It goes outside of AI and into domain expertise. An in-depth topic such as finance deserves its own course. This is that course. These are topics you will never learn in a generic data science or machine learning course. However, as a student of AI, you will recognize many of our tools and methods being applied, such as statistical inference, supervised and unsupervised learning, convex optimization, and optimal control. This allows us to go deeper than your run of the mill financial engineering course, and it becomes more than just the sum of its parts.

So what are you waiting for?

April 1, 2020

# VIP Promotion

### The complete PyTorch course has arrived

Hello friends!

I hope you are all staying safe. Well, I’m sure you’ve heard enough about that so how about some different news?

Today, I am announcing the VIP version of my latest course: PyTorch: Deep Learning and Artificial Intelligence

https://www.udemy.com/course/pytorch-deep-learning/?couponCode=PYTORCHVIP20 (expires Dec 18, 2021)

This is a MASSIVE (over 22 hours) Deep Learning course covering EVERYTHING from scratch. That includes:

• Machine learning basics (linear neurons)
• ANNs, CNNs, and RNNs for images and sequence data
• Time series forecasting and stock predictions (+ why all those fake data scientists are doing it wrong)
• NLP (natural language processing)
• Recommender systems
• Transfer learning for computer vision
• Deep reinforcement learning and applying it by building a stock trading bot

IN ADDITION, you will get some unique and never-before-seen VIP projects:

Estimating prediction uncertainty

Drawing the standard deviation of the prediction along with the prediction itself. This is useful for heteroskedastic data (that means the variance changes as a function of the input). The most popular application where heteroskedasticity appears is stock prices and stock returns – which I know a lot of you are interested in.

It allows you to draw your model predictions like this:

Sometimes, the data is simply such that a spot-on prediction can’t be made. But we can do better by letting the model tell us how certain it is in its predictions.

Facial recognition with siamese networks

This one is cool. I mean, I don’t have to tell you how big facial recognition has become, right? It’s the single most controversial technology to come out of deep learning. In the past, we looked at simple ways of doing this with classification, but in this section I will teach you about an architecture built specifically for facial recognition.

You will learn how this can work even on small datasets – so you can build a network that recognizes your friends or can even identify all of your coworkers!

You can really impress your boss with this one. Surprise them one day with an app that calls out your coworkers by name every time they walk by your desk. 😉

Please note: The VIP coupon will work only for the next month (ending May 1, 2020). It’s unknown whether the VIP period will renew after that time.

After that, although the VIP content will be removed from Udemy, all who purchased the VIP course will get permanent free access on deeplearningcourses.com.

## Minimal Prerequisites

This course is designed to be a beginner to advanced course. All that is required is that you take my free Numpy prerequisites to learn some basic scientific programming in Python. And it’s free, so why wouldn’t you!?

You will learn things that took me years to learn on my own. For many people, that is worth tens of thousands of dollars by itself.

There is no heavy math, no backpropagation, etc. Why? Because I already have courses on those things. So there’s no need to repeat them here, and PyTorch doesn’t use them. So you can relax and have fun. =)

## Why PyTorch?

All of my deep learning courses until now have been in Tensorflow (and prior to that Theano).

So why learn PyTorch?

Does this mean my future deep learning courses will use PyTorch?

In fact, if you have traveled in machine learning circles recently, you will have noticed that there has been a strong shift to PyTorch.

Case in point: OpenAI switched to PyTorch earlier this year (2020).

Major AI shops such as Apple, JPMorgan Chase, and Qualcomm have adopted PyTorch.

PyTorch is primarily maintained by Facebook (Facebook AI Research to be specific) – the “other” Internet giant who, alongside Google, have a strong vested interest in developing state-of-the-art AI.

But why PyTorch for you and me? (aside from the fact that you might want to work for one of the above companies)

As you know, Tensorflow has adopted the super simple Keras API. This makes common things easy, but it makes uncommon things hard.

With PyTorch, common things take a tiny bit of extra effort, but the upside is that uncommon things are still very easy.

Creating your own custom models and inventing your own ideas is seamless. We will see many examples of that in this course.

For this reason, it is very possible that future deep learning courses will use PyTorch, especially for those advanced topics that many of you have been asking for.

Because of the ease at which you can do advanced things, PyTorch is the main library used by deep learning researchers around the world. If that’s your goal, then PyTorch is for you.

In terms of growth rate, PyTorch dominates Tensorflow. PyTorch now outnumbers Tensorflow by 2:1 and even 3:1 at major machine learning conferences. Researchers hold that PyTorch is superior to Tensorflow in terms of the simplicity of its API, and even speed / performance!

Do you need more convincing?

March 18, 2020

# VIP Promotion

Hello all!

In this post, I am announcing the VIP coupon to my course titled “Artificial Intelligence: Reinforcement Learning in Python”.

There are 2 places to get the course.

1. Udemy, with this VIP coupon: https://www.udemy.com/course/artificial-intelligence-reinforcement-learning-in-python/?couponCode=REINFORCEVIP6 (expires Dec 18, 2021)
2. Deep Learning Courses (coupon automatically applied): https://deeplearningcourses.com/c/artificial-intelligence-reinforcement-learning-in-python

You may recognize this course as one that has already existed in my catalog – however, the course I am announcing today contains ALL-NEW material. The entire course has been gutted and every lecture contained within the course did not exist in the original version.

One of the most common questions I get from students in my PyTorch, Tensorflow 2, and Financial Engineering courses is: “How can I learn reinforcement learning?”

While I do cover RL in those courses, it’s very brief. I’ve essentially summarized 12 hours of material into 2. So by necessity, you will be missing some things.

While that serves as a good way to scratch the surface of RL, it doesn’t give you a true, in-depth understanding that you will get by actually learning each component of RL step-by-step, and most importantly, getting a chance to put everything into code!

This course covers:

• The explore-exploit dilemma and the Bayesian bandit method
• MDPs (Markov Decision Processes)
• Dynamic Programming solution for MDPs
• Monte Carlo Method
• Temporal Difference Method (including Q-Learning)
• Approximation Methods using Radial Basis Functions
• Applying your code to OpenAI Gym with zero effort / code changes
• Building a stock trading bot (different approach in each course!)

When you get the DeepLearningCourses.com version, note that you will get both versions (new and old) of the course – totalling nearly 20 hours of material.

If you want access to the tic-tac-toe project, this is the version you should get.

Otherwise, if you prefer to use Udemy, that’s fine too. If you purchase on Udemy but would like access to DeepLearningCourses.com, I will allow this since they are the same price. Just send me an email and show me your proof of purchase.

Note that I’m not able to offer the reverse (can’t give you access to Udemy if you purchase on DeepLerningCourses.com, due to operational reasons).

So what are you waiting for?

# 🎄 BLACK FRIDAY 2021 COUPONS AND DEALS

November 26, 2021

 Hello friends!   The Black Friday 2021 sale is on! I’m sending you links now which will give you the maximum possible discount during the Black Friday / Cyber Monday season (see below for specific dates). For those students who are new (welcome!), you may not know that I have a whole catalog of machine learning and AI courses built up and continuously updated over the past 6 years, with separate in-depth courses covering nearly every topic in the field, including: – Machine Learning (Linear Regression, Logistic Regression, K-Means Clustering, GMMs, Hierarchical Clustering, HMMs, Markov Models, Decision Trees, Random Forests, Naive Bayes, Perceptrons, SVMs, boosting, Bayesian ML, A/B Testing) – NLP (Attention, seq2seq, BiLSTMs, word2vec, GloVe, article spinning, latent semantic indexing, sentiment analysis, spam detection) – Reinforcement Learning (the basics, along with modern Deep RL topics like DQN, Policy Gradient Methods, Evolution Strategies, A2C and A3C, DDPG) – Deep Learning (separate courses for ANNs, CNNs, RNNs, GANs, Variational Autoencoders, Recommender Systems, Computer Vision) BOOKMARK THIS POST because these links will give you the best discount possible over the Black Friday / Cyber Monday sales later this month. The “Black Friday” links will work on the following dates: – Friday November 26, 2021 (Black Friday) – All week before Black Friday (starting November 19) – Monday November 29, 2021 (Cyber Monday) – Maybe a few days after that, but don’t wait and regret it     Outline of the following discounts: 1. Time Series Analysis, Forecasting, and Machine Learning (VIP) 2. Financial Engineering and Artificial Intelligence in Python (VIP) 3. PyTorch: Deep Learning and Artificial Intelligence (VIP) 4. Artificial Intelligence: Reinforcement Learning in Python (VIP) 5. Black Friday Discounts for Other Courses Note that the “VIP links” will work for the next 30 days, you don’t need to wait until Black Friday for those.

Time Series Analysis, Forecasting, and Machine Learning (VIP PROMOTION)

==The Complete Time Series Analysis Course Has Arrived==

https://www.udemy.com/course/time-series-analysis/?couponCode=TIMEVIP6

(note: this VIP coupon expires in 30 days!)

We will cover techniques such as:

• ETS and Exponential Smoothing
• Holt’s Linear Trend Model
• Holt-Winters Model
• ARIMA, SARIMA, SARIMAX, and Auto ARIMA
• ACF and PACF
• Vector Autoregression and Moving Average Models (VAR, VMA, VARMA)
• Machine Learning Models (including Logistic Regression, Support Vector Machines, and Random Forests)
• Deep Learning Models (Artificial Neural Networks, Convolutional Neural Networks, and Recurrent Neural Networks)
• GRUs and LSTMs for Time Series Forecasting

We will cover applications such as:

• Time series forecasting of sales data
• Time series forecasting of stock prices and stock returns
• Time series classification of smartphone data to predict user behavior

The VIP version (obtained by purchasing the course NOW during the VIP period) of the course covers even more exciting topics, such as:

• AWS Forecast (Amazon’s state-of-the-art low-code forecasting API)
• GARCH (financial volatility modeling)
• FB Prophet (Facebook’s time series library)

Financial Engineering and Artificial Intelligence in Python

VIP Promotion

https://www.udemy.com/course/ai-finance/?couponCode=FINANCEVIP15

This is a MASSIVE (20 hours) Financial Engineering course covering the core fundamentals of financial engineering and financial analysis from scratch. We will go in-depth into all the classic topics, such as:

• Exploratory data analysis, significance testing, correlations, alpha and beta
• Time series analysis, simple moving average, exponentially-weighted moving average
• Holt-Winters exponential smoothing model
• ARIMA and SARIMA
• Efficient Market Hypothesis
• Random Walk Hypothesis
• Time series forecasting (“stock price prediction”)
• Modern portfolio theory
• Efficient frontier / Markowitz bullet
• Mean-variance optimization
• Maximizing the Sharpe ratio
• Convex optimization with Linear Programming and Quadratic Programming
• Capital Asset Pricing Model (CAPM)

In addition, we will look at various non-traditional techniques which stem purely from the field of machine learning and artificial intelligence, such as:

• Regression models
• Classification models
• Unsupervised learning
• Reinforcement learning and Q-learning

List of VIP content:

• Classic Algorithmic Trading – Trend Following Strategy
• Reinforcement Learning-Based (Q-Learning) Trading Strategy
• Statistical Factor Models
• Regime Detection and Volatility Clustering with HMMs and Sequence Modeling

PyTorch: Deep Learning and Artificial Intelligence

VIP Promotion

https://www.udemy.com/course/pytorch-deep-learning/?couponCode=PYTORCHVIP20

This is a MASSIVE (over 22 hours) Deep Learning course covering EVERYTHING from scratch. That includes:

• Machine learning basics (linear neurons)
• ANNs, CNNs, and RNNs for images and sequence data
• Time series forecasting and stock predictions (+ why all those fake data scientists are doing it wrong)
• NLP (natural language processing)
• Recommender systems
• Transfer learning for computer vision
• Deep reinforcement learning and applying it by building a stock trading bot
• VIP only: Making predictions with your trained NLP model
• VIP only: Making predictions with your trained Recommender model
• VIP only: Modeling prediction uncertainty and heteroskedasticity (i.e. stock returns!)
• VIP only: Facial recognition with Siamese Networks

Artificial Intelligence: Reinforcement Learning in Python

VIP Promotion

===The complete Reinforcement Learning course has arrived===

https://deeplearningcourses.com/c/artificial-intelligence-reinforcement-learning-in-python

Reinforcement Learning is the most general form of AI we know of so far – some speculate it is the way forward to mimic animal intelligence and attain “AGI” (artificial general intelligence).

This course covers:

• The explore-exploit dilemma and the Bayesian bandit method
• MDPs (Markov Decision Processes)
• Dynamic Programming solution for MDPs
• Monte Carlo Method
• Temporal Difference Method (including Q-Learning)
• Approximation Methods using RBF Neural Networks
• Applying your code to OpenAI Gym with zero effort / code changes
• Building a stock trading bot (different approach in each course!)

Tensorflow 2: Deep Learning and Artificial Intelligence VIP

Exclusive to deeplearningcourses.com only

===The complete Tensorflow 2 course has arrived===

## BLACK FRIDAY DISCOUNTED Courses

### Looking for the LOWEST PRICE POSSIBLE Udemy Coupons?

Please enjoy the below Black Friday coupons for the rest of my courses on Udemy.

The best part is, you don’t have to enter any coupon code at all. Simply clicking on the links below will automatically get you the best possible price.

*Note: a few of the courses below, marked with an asterisk (*) are not part of the Black Friday sale. However, if you purchase these courses at the current price, you will receive, upon request, complimentary access to the full VIP version of the course on deeplearningcourses.com. Just email me at [email protected] for free access with proof of purchase.

# Mistakes in Stock Prediction: Trying to Predict the Price

November 15, 2021

Hello friends! Curious about how to properly predict stock prices?

I’ve now released the third video in this YouTube mini-series.

For those unfamiliar: this is a video series that debunks common mistakes found in nearly all blog articles / Github repos claiming to do “stock price predictions with LSTMs”.

These are typically written by non-experts in the field just looking for clicks, and I have a lot of fun breaking down precisely what they’re doing wrong.

Why is this important?

Beginners are often fooled by such content, wasting money on courses to learn things that don’t work. Even worse, they may end up putting such examples on their own Github accounts or in their portfolios / resumes, worsening their chances of getting a job in the field.

To be clear: the bad part isn’t that they learned something that doesn’t work (although that is pretty bad by itself). The bad part is, they don’t even understand why it doesn’t work. They are confident that it does and will fight me over it! (That is, until I ask them to verify or rebut any of the claims I’ve made).

Thus, not only does this stuff not work (due to all the mistakes I outline in my video series), but it could actually be detrimental to getting a job and working in this area. These are not just harmless mistakes!

The first video discussed why min-max scaling over the train set doesn’t work.

The second video discussed why using prices as inputs (i.e. lagged prices to build an autoregressive model) doesn’t work.

This third video (this video) will discuss why using prices as targets does not work.

Enjoy!

# Intel Extension for Scikit-Learn

November 2, 2021

Hello friends!

Today, Intel announced their extension for Scikit-Learn, which allows you to accelerate your Scikit-Learn code 10-100x without any code changes.

The new extension fully conforms to Scikit-Learn’s existing API, so you can take your existing code and speed it up essentially for free.

See here for more details: https://intel.github.io/scikit-learn-intelex/

# Why you shouldn’t use prices as inputs to predict stock prices in machine learning (YouTube Episode 20)

October 12, 2021

Ever come across a machine learning / data science blog demonstrating how to predict stock prices using an autoregressive model, with past stock prices as input?

It’s been awhile, but I am finally continuing this YouTube mini-series I started awhile back, which goes over common mistakes in popular blogs on predicting stock prices with machine learning. This is the 2nd installment.

It is about why you shouldn’t use prices as inputs.

# Convert a Time Series Into an Image with Gramian Angular Fields and Markov Transition Fields

August 30, 2021

In my latest course (Time Series Analysis), I made subtle hints in the section on Convolutional Neural Networks that instead of using 1-D convolutions on 1-D time series, it is possible to convert a time series into an image and use 2-D convolutions instead.

CNNs with 2-D convolutions are the “typical” kind of neural network used in deep learning, which normally are used on images (e.g. ImageNet, object detection, segmentation, medical imaging and diagnosis, etc.)

In this article, we will look at 2 ways to convert a time series into an image:

1. Gramian Angular Field
2. Markov Transition Field

## Gramian Angular Field

The Gramian Angular Field is quite involved mathematically, so this article will discuss the intuition only, along with the code.

Those interesting in all the gory details are encouraged to read the paper, titled “Encoding Time Series as Images for Visual Inspection and Classification Using Tiled Convolutional Neural Networks” by Zhiguang Wang and Tim Oates.

We’ll build the intuition in a series of steps.

Let us begin by recalling that the dot product or inner product is a measure of similarity between two vectors.

$$\langle a, b\rangle = \lVert a \rVert \lVert b \rVert \cos \theta$$

Where $$\theta$$ is the angle between $$a$$ and $$b$$.

Ignoring the magnitude of the vectors, if the angle between them is small (i.e. close to 0) then the cosine of that angle will be nearly 1. If the angle is perpendicular, the cosine of the angle is 0. If the two vectors are pointing in opposite directions, then the cosine of the angle will be -1.

The Gram Matrix is just the repeated application of the inner product between every vector in a set of vectors, and every other vector in that same set of vectors.

i.e. Suppose that we store a set of column vectors in a matrix called $$X$$.

The Gram Matrix is:

$$G = X^TX$$

This expands to:

$$G = \begin{bmatrix} \langle x_1, x_1 \rangle & \langle x_1, x_2 \rangle & … & \langle x_1, x_N \rangle \\ \langle x_2, x_1 \rangle & \langle x_2, x_2 \rangle & … & \langle x_2, x_N \rangle \\ … & … & … & … \\ \langle x_N, x_1 \rangle & \langle x_N, x_2 \rangle & … & \langle x_N, x_N \rangle \end{bmatrix}$$

In other words, if we think of the inner product as the similarity between two vectors, then the Gram Matrix just gives us the pairwise similarity between every vector and every other vector.

Note that the Gramian Angular Field (GAF) does not apply the Gram Matrix directly (in fact, each value of the time series is a scalar, not a vector).

The first step in computing the GAF is to normalize the time series to be in the range [-1, +1].

Let’s assume we are given a time series $$X = \{x_1, x_2, …, x_N \}$$.

The normalized values are denoted by $$\tilde{x_i}$$.

The second step is to convert each value in the normalized time series into polar coordinates.

We use the following transformation:

$$\phi_i = \arccos \tilde{x_i}$$

$$r_i = \frac{t_i}{N}$$

Where $$t_i \in \mathbb{N}$$ represents the timestamp of data point $$x _i$$.

Finally, the GAF method defines its own “special” inner product as:

$$\langle x_1, x_2 \rangle = \cos(\phi_1 + \phi_2)$$

From here, the above formula for $$G$$ still applies (except using $$\tilde{X}$$ instead of $$X$$, and using the custom inner product instead of the usual version).

Here is an illustration of the process:

So why use the GAF?

Like the original Gram Matrix, it gives you a “picture” (no pun intended) of the relationship between every point and every other point in the time series.

That is, it displays the temporal correlation structure in the time series.

Here’s how you can use it in code.

Firstly, you need to install the pyts library. Then, run the following code on a time series of your choice:

Note that the library allows you to rescale the image with the image_size argument.

As an exercise, try using this method instead of the 1-D CNNs we used in the course and compare their performance!

## Markov Transition Field

The Markov Transition Field (MTF) is another method of converting a time series into an image.

The process is a bit simpler than that of the GAF.

If you have taken any of my courses which involve Markov Models (like Natural Language Processing, or HMMs) you should feel right at home.

Let’s assume we have an N-length time series.

We begin by putting each value in the time series into quantiles (i.e. we “bin” each value).

For example, if we use quartiles (4 bins), the smallest 25% of values would define the boundaries of the first quartile, the second smallest 25% of values would define the boundaries of the second quartile, etc.

We can think of each bin as a ‘state’ (using Markov model terminology).

Intuitively, we know that what we’d like to do when using Markov models is to form the state transition matrix.

This matrix has the values:

$$A_{ij} = P(s_t = j | s_{t-1} = i)$$

That is, $$A_{ij}$$ is the probability of transitioning from state i to state j.

As usual, we estimate this value by maximum likelihood. ( $$A_{ij}$$ is the count of transitions from i to j, divided by the total number of times we were in state i).

Note that if we have $$Q$$ quantiles (i.e. we have $$Q$$ “states”), then $$A$$ is a $$Q \times Q$$ matrix.

The MTF follows a similar concept.

The MTF (denoted by $$M$$) is an $$N \times N$$ matrix where:

$$M_{kl} = A_{q_k q_l}$$

And where $$q_k$$ is the quantile (“bin”) for $$x_k$$, and $$q_l$$ is the quantile for $$x_l$$.

Note: I haven’t re-used the letters i and j to index $$M$$, which most resources do and it’s super confusing.

Do not mix up the indices for $$M$$ and $$A$$! The indices in $$A$$ refer to states. The indices for $$M$$ are temporal.

$$A_{ij}$$ is the probability of transitioning from state i to state j.

$$M_{kl}$$ is the probability of a one-step transition from the bin for $$x_k$$, to the bin for $$x_l$$.

That is, it looks at $$x_k$$ and $$x_l$$, which are 2 points in the time series at arbitrary time steps $$k$$ and $$l$$.

$$q_k$$ and $$q_l$$ are the corresponding quantiles.

$$M_{kl}$$ is then just the probability that we saw a direct one-step (i.e. Markovian) transition from $$q_k$$ to $$q_l$$ in the time series.

So why use the MTF?

It shows us how related 2 arbitrary points in the time series are, relative to how often they appear next to each other in the time series.

Here’s how you can use it in code.

Note that the library allows you to rescale the image with the image_size argument.

As an exercise, try using this method instead of the 1-D CNNs we used in the course and compare their performance

Enjoy!