Zero Labs
Industry News / AI

The Mathematics Behind Artificial Intelligence: How Linear Algebra Makes Machines Learn

Source · Towards AI By D M Kenura Dasanayaka

From the publisher’s feed, collected in the ZeroLabs newsroom.

Cover ImageBehind every intelligent system, there is a language of numbers, vectors and metrices. From identifying human language to generating images and making predictions, Artificial Intelligence relies heavily on mathematical structures that allow systems to represent, process and learn from information. Among the many branches of Mathematics, Linear Algebra stands as one of the main fundamental pillars of modern AI. Yet its role extends far beyond simply arranging numbers into rows and columns. Vectors represent information, matrices transform data mathematical operations enable neural networks to learn complex patterns hidden within large datasets. In this article, we will explore how Linear Algebra works behind the surface of AI.Why does AI need Linear Algebra?In Artificial Intelligent systems, at its core, the AI model recieves information, represents it in a mathematical form, processes those information by using a huge amount of mathematical calculations and produces output. The input can be a text, image, video or any other input type. But, AI models, even computers cannot identify or understand those inputs and process them as humans do. They use a mathematical representation to store and process those. This is where Linear Algebra becomes important. It provides an efficient way to store data using matrices and vectors. Also, it provides an efficient way to perform the mathematical operations required to transform those data into a meaningful output. As AI models become more complex and datasets grow larger, these representations allow computations to be effective and organized. With billions of Mathematical operations involving matrices and vectors, Modern AI systems appear to be intelligent.From Real-World information to Mathematical VectorsImagine providing a picture of a cat to the AI System. To a human, with a single glance, the information about the picture such as, shape of the ears, color of the furs and the color, position of eyes can be observed. But, for a computer, a picture is a collection of a numerical pixel values. Each pixel contains a numerical value about its color and intensity. These values can be organized into mathematical structures that AI model can process. This is where Vectors are used.What is a vector?In Linear Algebra, a vector is an ordered collection of numbers that can represent a point in a mathematical space or encode a set of features describing an object.eg :-A simplified representation of an image might be expressed as,X = [0.2, 0.8, 0.5, 0.1] where each number represents a particular pixel value or a feature.Although this example contains only four values, real images may contain thousands or millions of numerical values. Similarly, an AI model can represent person’s characteristics, a piece of text or a collection of measurements as a vector. When these information are converted into vectors, AI model can perform calculations, identify relationships and learn patterns from the data. Vectors are the fundamental component between the complex real — world information and the mathematical computations that make AI possible.Image to VectorMatricesWhile vectors provide a way to represent single pieces of information, matrices allow to organize and store large collections of numerical data.A Matrix is a rectangular arrangement of numbers in rows and columns and it plays an important role in Artificial Intelligence. Consider an image of containing thousands of pixels. Its numerical values can be arranged into a matrix, allowing the computer to perform mathematical operations on the image. Not only for image representations, but also, in Machine Learning, datasets containing multiple observations and features are represented in matrices. More importantly, matrices are used in internal workings of neural networks. They are used to store weights and perform transformations that allow information to pass through different layers of a network. Through matrix operations, an AI model can combine input information, identify relationships between variables and gradually learn complex patterns from data. Therefore, Matrices provide the computational framework that enables AI models to process large amount of information efficiently.Matrix MultiplicationAmong the operations related to Matrices, Matrix Multiplication is one of the most important matrix operations which allows an AI model to combine information and transform it into different representations. Consider a simple neural network that recieves several numerical inputs, such as measurements describing an object. Each input is assigned a weight, representing its contribution to the model’s calculations. These weights can be arranged in a matrix and multiplied by an input vector to produce an output vector. Mathematically, this operation can be expressed as,y = Wx + bwhere y is the output vector, x is the input vector, W is the weight matrix and b is the bias vector. Although this expression looks simple, it represents one of the fundamental computations performed repeatedly throughout neural networks. Each layer receives information from the previous layer, applies its own weights and biases and passes the transformed information to the next layer. During the training process, the models adjusts these weights and biases to reduce prediction errors and improve its performance. Therefore, the matrix multiplication is the central computational mechanism which neural networks learn from data.Neural Networks Matrix Multiplication processEigenvalues and EigenvectorsWith matrices, vecctors and matrix multiplication, another important connection between Linear Algebra and Artificial Intelligence is from eigenvalues and eigenvectors. These two concepts help us to understand how a matrix transformation affects different directions in a mathematical space. Therefore, an eigenvector is a non-zero vector whose direction remains unchanged when a particular square matrix acts on it, while its corresponding eigenvalue describes how much that vector is scaled during the transformation. Mathematically, the relationship can be expressed asAv = λvwhere A represents a square matrix, v is eigenvector and λ is its corresponding eigenvalue. Although eigenvalues and eigenvectors are one of the fundamental mathematical concepts, they also have important applications in Artificial Intelligence and Machine Learning. Many machine learning algorithms work with large matrices to identify the patterns and relationships within datasets. Eigenvalues and eigenvectors provide a mathematical way to understand the properties of these matrices and how they transform information. For an example, they can identify important directions in which data varies, reveal important structures within datasets and simplify certain mathematical computations. Thses properties particularly useful when developing algorithms that need to analyse large amounts of information efficiently. Therefore, eigenvalues and eigenvectors not only mathematical concepts, they provide valuable tools for understanding and developing various techniques used in modern Machine Learning.Measuring similarity between vectorsIn Artificial Intelligence, representing information mathematically using vectors is only one part of the process. AI models also need mathematical techniques to compare these representations and identify relationships between them. One of the techniques that AI models use to identify the relationship between vectors is Cosine Similarity, which is based on the dot product of two vectors. To understand this concept, the geometric relationship between two vectors must be considered. The dot product of two vectors is related to the cosine value of the angle between them.Geometric Representation of vectorsMathematically, for two non-zero vectors a and b, cosine similarity is defined as the dot product divided by the product of their magnitudes. This normalization makes the result independent of the magnitudes of the vectors and allow only to focus on their directional relationship. The resulting values lies between -1 and 1. The value 1 indicates that vectors point in the same direction, the value 0 indicates that vectors are perpendicular while -1 indicates that vectors point to the opposite direction. This is particularly useful when comapring data represented by vectors because two vectors can have significantly different magnitudes while they are still sharing the same direction. For an example, consider two vectors a = (1,2) and b = (2,4). Although their magnitudes are different, one vector is simply a scalar multiple of the other. Then, the cosine value of the angle between two vectors is 1 which indicates the two vectors are in the same direction, while their dot product is 10. By looking at the dot product, it is hard to interpret anything about their directional similarity. In mathetically, we can express this as an equation,Cosine relation between two vectorsThis mathematical technique has important applications in AI, specially in Natural Language Processing (NLP) where words, sentences and documents can be represented as numerical representations. By comparing these vectors by using cosine similarity, AI systems can estimate how closely related two pieces of text are in their numerical representations. As an example, a document-search system can compare the vector representations of a user’s query with the representations of stored documets and identify the documents that are directionally similar to the query.Linear Algebra as a unified mathematical framework for AIThe true importance of Linear Algebra in Artificial Intelligence becomes clearer when the way of its different concepts work together is considered. Vectors and matrices provide structured ways to represent numerical information, while matrix operations allow AI models to manipulate and transform these representations. The dot product and cosine similarity offer mathematical methods for examining relationships between vectors and find their directional similarity. Meanwhile, eigenvalues and eigenvectors provide ways to investigate the properties of matrices and understand how certain transformations affect data. These concepts are not independent mathematical tools, they contribute to the development and operation of AI systems. From representing information to processing numerical data and identifying relationships, Linear Algebra provides a mathematical foundation for many of the operations performed by many modern AI tools.Why understanding Linear Algebra mattersArtificial Intelligence is often viewed as a field with programming languages, codes, algorithms and computational power. However, behind many of these technologies, there is a concrete mathematical foundation. Understanding Linear Algebra allows us to look beyond the AI outputs and gain insights into the mathematical operations that make them possible. Instead of treating a Machine Learning model as a black box, Knowledge of vectors, matrices and their operations helps us understand how information is represented, transformed and processed. It also provides a foundation for exploring more advanced areas of Artificial Intelligence, including deep learning, computer vision and natural language processing. Ultimately, learning the Mathematics behind AI does not simply help us use exisiting technologies, it helps us understand, analyse and gradually develop better ones.#LinearAlgebra #Mathematics #ArtificialIntelligence #MachineLearning #MathematicalFoundations #MathematicsInAIThe Mathematics Behind Artificial Intelligence: How Linear Algebra Makes Machines Learn was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.