Optimization: The Intuitive Process at the Core of AI

Aidan Gould
Nov 24, 2020 · 7 min read
Image for post
Image for post

Artificial Intelligence (AI) has gotten a reputation as being the big technological advancement of our time, but at the same time a force which stands to upend society. AI seems almost alien in all of its mystery, complexity, and implications. I want to prove that while the implications are enormous, the fundamental mathematical process driving it is understandable, and maybe even intuitive. Lets start with an analogy.

Consider how a lone blind explorer attempting to find the location the highest peak in his country. All that the person can do is walk North/South, walk East/West, or do a combination of those two. So, in this case, there are only two inputs the person has control over: the distance traveled North/South (lets call this Y) and the distance traveled East/West (lets call this X). The result of having traveled those two distances is his current location on the map and corresponding elevation. See the terrain below. At Y=0.5 miles North, X=0.5 miles South, for example, the current elevation would be Z=0.52 miles in elevation.

Image for post
Image for post

The location at top of the highest peak, then, is just the best possible combination of the two inputs. So how would the blind man approach the problem?

One approach would be to simply walk in the direction that feels the steepest, then after a while reevaluate and choose a new steepest direction, then continue walking. The process is repeated, taking “steps” until there is no longer any good direction to go. This should be at the top of a peak. In the animation below, the explorer, represented by a colored dot, finds the peak after 25 steps.

Image for post
Image for post

A slight modification is for the explorers to run. While moving quickly might mean that they are not able to perfectly evaluate which way is the steepest and shortest way to the top, taking faster less thoughtful steps will still reach the summit more quickly.

Image for post
Image for post

However, for a different starting location, the explorer might only find a smaller peak and think that he is at the top, even if a bigger peak exists close by.

Image for post
Image for post

Fortunately, the computer is not limited to only one explorer, but can select several random starting locations for several explorers. Likely, at least one of them will have found the highest peak. In the case below, both the pink and red explorers find it while the others end on smaller peaks.

Image for post
Image for post

Now, the computer is able to quickly solve the optimization problem by sending out multiple explorer and having them run in the direction that is approximately the steepest path. With only a small amount of computational power, the X and Y location of the tallest peak is located.

Admittedly, in the two input case, the problem could instead be solved by simply checking every possible position on the map. However, most real-world optimization problems have many more than two inputs, up to several hundred. As the number of inputs grows, it becomes increasingly important to have a fast system, like the one the explorers used, to search for the optimal result instead of attempting to check every possible point. An exhaustive search of all points could likely take an impossible amount of computer time for a problem with many inputs. For instance, if the problem had 50 inputs and each input had 10 possible settings, to try every combination would be about as many trials as there are atoms on the Earth.

In this case, a two-input problem is used as an example because three dimensions (two inputs making one output) is the most that a person is able to easily visualize. While higher dimensional systems may be impractical to visualize, the intuition behind how the problem is solved remains exactly the same.

Image for post
Image for post
Artistic Representation of a Neural Network

Multi-dimensional optimization problems are at the core of many computer programs set to revolutionize several industries. One important use for this type of problem is with neural networks, a prominent type of AI. In this case, the current elevation of the explorer is how well the AI performs a task, and each input is how active a given neuron or neuron connection path is in the neural network. The structure of the network is complex, but the principle is still to find the best possible combination of inputs. The activations of each neuron and connection changes slightly every time the program runs, and the network performs its task better and better. This is just like how the explorer got progressively closer to the summit, but the summit here is a well performing neural network. AIs trained in this way will do tasks all the way from recognizing handwritten text to being the brains of self-driving cars.

Image for post
Image for post
Airbus Titanium Seat Bracket Made with Generative Design

Another important use is in generative design AI. Generative design software takes in several requirements from an engineer such as how strong a part needs to be and what material it will be made out of. For example, the part above is a bracket to hold an airplane seat to the floor, and will be made out of titanium. The computer is then tasked with designing the part to meet the requirements, but be as lightweight as possible. Again, from a starting geometry, the part becomes progressively lighter with each small change. Once no small change could possibly make the part better, then it is considered optimized. The parts made with this method take on strange alien-like shapes like the seat bracket, but are often 30% lighter, or more, than conventional parts which is a big deal in a lot of applications. This will mean lighter, faster cars, bridges that need less material to build, airplanes that can carry more weight, and mostly likely enable some new inventions that were not possible without it.

In addition to the two types discussed above, AI has many other forms, almost all of which rely on optimization. Even with all of the impact that AI is poised to have on our lives, it is almost comforting to know that, fundamentally, it is just a computer solving the problem of the blind explorer.

CODE: For those curious, the MatLab code used to generate the images is below. Feel free to copy it into a new file and see how it works.

clear; close all;

%% Options




Frame_Rate=3; %in frames/sec

Step_Rand=1; %turns random noise on the steps on or off

randAngle=30; %angle +/-






%% Generate terrain

[Y,X] = ndgrid(-1.5:0.05:1.5,-1.5:0.05:1.5);



%make surface

Z = getZ(North,East);

%background color



set(gcf, ‘OuterPosition’, [0 0 1000 800]);

%plot surface


axis equal

hold on








%% Make Interpolent For Gradient (in nd grid form so coordinates are (Y,X) or (North,East))

[fx,fy] = gradient(Z,0.05);



%% Explorer Initialization








%% Take Steps



for stepNum=1:Number_Of_Steps

for i=1:ne

if ~summit(i) %if that explore has not summitted already



%pTest=pNow+moveTest+moveTest.*(randi([-pRand,pRand],1,2)./100).*Step_Rand;%add rand if it is turned on

if Step_Rand




if getZ(pNow(1),pNow(2))<getZ(pTest(1),pTest(2)) %if the new point is higher

currentLocation(i,:)=pTest; %move

locationHistory(i,:,stepNum+1)=pTest; %update history


summit(i)=1; %otherwise they have summitted





%% Animation Frames

%frame parameters


pos = get(gcf, ‘Position’); %// gives x left, y bottom, width, height

width = pos(3);

height = pos(4);




for stepNum=1:Number_Of_Steps

for i=1:ne


if sum(pNow)~=0


if stepNum~=1



title([‘Step Number’ ‘ ‘ num2str(stepNum-1)])




% Get frame now

M(stepNum)= getframe(1,fr);


%% Save Animation

movie_obj = VideoWriter(Animation_File);




for K= 1:startImageLen

this_image = M(1);

writeVideo(movie_obj, this_image);


for K = 1:length(M)

this_image = M(K);

writeVideo(movie_obj, this_image);



function Z=getZ(North,East)



Z = sin(X.*pi).*cos(Y.*pi).*exp(-sqrt(X.*X+Y.*Y))./2+0.5;


Medium's largest active publication, followed by +771K people. Follow to join our community.

Aidan Gould

Written by

The Startup
Aidan Gould

Written by

Northeastern University Mechanical Engineering Student

The Startup

Medium's largest active publication, followed by +771K people. Follow to join our community.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store