Overview of Infinity in Machine Learning Projects
Guide Tasks
  • Read Tutorial
  • Watch Guide Video
Video locked
This video is viewable to users with a Bottega Bootcamp license

In this guide, we're going to have a quick discussion about infinity and how it's most often used in NumPy.

I'm not sure how many of you have explored the concept of infinity, but I've always found it to be one of the most fascinating, yet ridiculously complicated ideas to even begin to try to wrap my brain around. Do any of you remember the first time that somebody told you infinity divided by infinity wasn't actually one, that some infinities are bigger than other infinities, or that if you have an infinite set with alternating signs it can be manipulated to converge on any number?

And those are just some of the weird things that happens when you use infinity. But if you're ever bored, there's a bunch of really great YouTube videos that talk about all the crazy stuff that happens at infinity. Some of my personal favorites have to do with Cantor set or Cantor's paradox, chaos theory, set theory, Russell's paradox, singularity, and probably the multiverse.

But thankfully for us, NumPy doesn't worry about the theoretical side of infinity. Instead, it simply categorizes infinity as a constant and can even handle all of the basic arithmetic. If we try to divide infinity by infinity or multiply infinity and zero, we'll get an nan value for both. We can also divide or multiply real numbers with infinity.

medium

Outside of the basic arithmetic, another infinity function that NumPy offers lets us check for an infinity. Just pass in np.isinf with parentheses, followed by the subject you want to check, and there you have it. It's not going to be super important for most of us since all the math is done under the hood, but infinity actually plays a pretty huge role for some of the algorithms that we'll be using later on. And the algorithms that I'm talking about are any of those that use the principles for convergence or an infinite set.

medium

But infinity is probably used most often for optimization problems. It's something that we'll be talking about later on, but oftentimes you'll see infinity used for shortest path algorithms, when we need to compare the current distance with the best or least distance. We'll be initializing unknown distances with positive infinity. So then no matter what distance you enter into your program, it can never be greater than the initial infinite value.

I know most of this is a little bit abstract for the time being. But once we get into optimizing algorithms, this will make a lot more sense. In the meantime, I'm going to wrap this guide up, and I will see you in the next one.