AI Learns To Play Golf

b2studios
5 Mar 202413:56

Summary

TLDRIn this video, the creator explores the development of a golf-playing AI using four separate neural networks for different golf clubs. Each network is trained with a reward system to optimize swing mechanics. Despite unconventional techniques, the AI achieves impressive results, with the driving AI hitting balls 210 yards. Challenges arise in adapting the algorithm for irons and short game clubs, but the AI shows promise, raising anticipation for its performance in an actual golf course scenario.

Takeaways

  • 🤖 The video features an AI-controlled ragdoll named 'Block House' playing golf, utilizing a neural network to simulate a golf swing.
  • 🏌️‍♂️ The AI is split into four separate neural networks, each specialized for driving, irons, chipping, and putting.
  • 🚀 The driving AI is trained to swing the club with a specific direction determined by the cross product of vectors from the shoulder line to the club face and the right shoulder.
  • 🎯 A reward system is implemented to guide the AI, focusing on club velocity matching the target direction and minimizing deviation from the swing plane.
  • 📉 The iron AI is adjusted to account for shots typically taken from the ground, not an elevated tee, and emphasizes keeping the club flush with the ground.
  • 🌐 The wedge AI is trained with an extra input to control swing strength and is tested on randomized terrains to improve adaptability.
  • 💻 The putting AI focuses on accuracy and control, with a reduced backswing to encourage consistency over speed.
  • 🤹‍♂️ Despite the AI's unconventional techniques, such as one-legged stance and face plants, it can achieve consistent and effective golf shots.
  • 📊 The training process involves reinforcement learning, where the AI learns from rewards and punishments based on its performance.
  • 🌟 The video concludes with a teaser for a future video where the AI will be tested on actual golf courses.

Q & A

  • What is the purpose of increasing the size of the golf ball in the AI simulation?

    -The size of the golf ball is increased to overcome limitations in the physics engine where small objects tend to phase through solid surfaces. This also helps to better simulate how the club interacts with the ground during golf shots.

  • How many separate neural networks are used for the AI golfer, and what are they responsible for?

    -Four separate neural networks are used for the AI golfer: one for driving, one for irons, one for chipping, and one for putting. Each network is specialized to handle the unique swing requirements for each type of golf shot.

  • What is the swing plane and how is it calculated?

    -The swing plane is defined as the axis around which the golf club needs to be tilted to hit a perfect golf shot. It is calculated using the cross product of two vectors: one from the shoulder line to the club face and the other from the shoulder line to the right shoulder.

  • How does the reward system for the driver AI work?

    -The reward system for the driver AI compares the velocity of the club to a target direction using the dot product. It also measures how far the club has deviated from the swing plane and gives a punishment that scales with that deviation.

  • What changes are made to the AI's swing when it needs to come back the other way after the backswing?

    -The swinging reward is reversed once the club is past a certain point relative to the ball, and the swinging reward is squared to emphasize the importance of moving the club fast.

  • How does the AI's iron swing differ from its driver swing?

    -The iron swing is similar to the driver swing, but with a slight tweak to the reward system to keep the club flush with the ground. The backswing is also shortened to reduce the swing speed, leading to a more precise swing.

  • What additional input is added to the neural networks for the wedge and putting AI?

    -An extra input is added to control how hard the AI swings, shifting the focus from rewarding speed to rewarding how close it gets to the target speed.

  • How does the AI handle uneven terrain during wedge shots?

    -The AI learns to hit shots on uneven terrain by simulating random platforms for the ragd doll to stand on during training, which makes it more resilient to uneven terrain on actual courses.

  • What adjustments are made to the putting AI to improve its performance?

    -The putting AI has its backswing greatly reduced to focus more on consistency than speed. It also follows a set of rules to ensure proper putting technique, such as keeping the leg straight and hitting the ball at a 45° angle.

  • What are the results of the AI's training for different types of golf shots?

    -The AI's training has been successful for driving and iron shots, with the AI capable of hitting long distances and maintaining a consistent swing. The wedge AI shows versatility in hitting from various surfaces, while the putting AI, despite some issues, is functional and can putt effectively.

Outlines

00:00

🏌️‍♂️ Golf AI Development

The video script introduces the development of a golfing AI using a neural network. The AI, named 'algorithm poo,' is enhanced with four separate neural networks, each specialized for different types of golf swings: driving, irons, chipping, and putting. The script discusses the limitations of physics engines in simulating golf, such as small objects passing through solid surfaces and the difficulty in simulating club-ground interaction. To address these, the ball size is increased. The AI's reward system is explained in detail, focusing on the driver swing, where the direction of the swing is determined by the cross product of vectors from the shoulder line to the club face and the right shoulder. This direction defines the swing plane. The script also explains how the reward system is adjusted for the backswing and the importance of speed in the downswing. The AI's training results in a successful golf swing, although it ends with a humorous face plant.

05:00

🚀 Iron and Short Game AI Training

The script continues with the application of the same algorithm to an iron swing, which is similar to a driver swing but with the added challenge of being hit from the ground. The reward system is tweaked to emphasize keeping the club flush with the ground. The backswing is shortened to reduce the AI's swing speed, aiming for a more precise swing. The training is successful, and the AI demonstrates a consistent iron swing, albeit with a tendency to drag the club along the ground before striking the ball. The script then discusses the challenges of training the AI for short game shots, where accuracy and control are more important than distance. For the wedge and putting AI, the reward system is adjusted to reward proximity to the target speed rather than speed itself. The wedge AI is trained on uneven terrain to increase its resilience, while the putting AI focuses on consistency due to the generally flat nature of the green.

10:02

🤖 Mixed Results in AI Golf Performance

The final paragraph discusses the results of training the AI for wedge and putting shots. The wedge AI performs well, with a stance and swing similar to real golfers, but it tends to fall over, likely due to its training on randomized surfaces. The putting AI, however, does not perform as expected, humorously described as following a set of rules that lead to an ineffective putting technique. Despite the mixed results, the script concludes that the golf AI is complete, with four neural networks for different types of golf shots. The anticipation is set for the next video, where the AI will be tested on actual golf courses.

Mindmap

Keywords

💡AI

AI, or Artificial Intelligence, refers to the simulation of human intelligence in machines that are programmed to think like humans and mimic their actions. In the context of the video, AI is used to develop a golf-playing system that can learn to swing a golf club effectively. The script describes how different neural networks are trained for various aspects of golf, such as driving, iron play, chipping, and putting.

💡Neural Networks

Neural networks are a set of algorithms modeled loosely after the human brain that are designed to recognize patterns. They interpret sensory data through a kind of machine perception, labeling, or clustering. In the video, neural networks are used to control the AI's golf swing, with separate networks for different types of shots, demonstrating how they can be tailored to specific tasks.

💡Reinforcement Learning

Reinforcement Learning is a type of machine learning where an agent learns to make decisions by taking actions in an environment to maximize some type of reward. The video describes using reinforcement learning to train the AI for golf, where the system learns to improve its swing by receiving rewards for actions that lead to better shots.

💡Physics Engines

Physics engines are systems that simulate how objects move and interact in a virtual environment. They calculate the effects of forces such as gravity, friction, and collisions. The video mentions the limitations of physics engines, particularly with small objects, and how they affect the simulation of golf shots.

💡Cross Product

The cross product is a mathematical operation that takes two vectors in three-dimensional space and returns a third vector which is perpendicular to the first two, effectively defining a plane. In the script, the cross product is used to calculate the swing plane for the AI, which is the axis around which the golf club should be swung for an optimal shot.

💡Swing Plane

In golf, the swing plane refers to the path that the clubhead takes through the hitting area during a golf swing. It is crucial for making solid contact with the ball. The video explains how the AI calculates the swing plane using the cross product to ensure the club is on the correct path for a good swing.

💡Dot Product

The dot product is an algebraic operation that takes two vectors and returns a scalar. It is used to find the angle between two vectors and can also determine the magnitude of one vector in the direction of another. In the video, the dot product is used to calculate rewards for the AI based on how closely the club's velocity matches the target direction during a swing.

💡Driver

In golf, the driver is the club with the longest shaft and the largest head, typically used to hit the ball the greatest distance. The video discusses training a separate AI neural network for using the driver, focusing on maximizing distance and speed.

💡Iron

Irons are golf clubs used for shorter distance shots, with a flat, angled striking face. The script describes how the AI is trained to use irons, emphasizing a more precise swing and adjusting for the fact that iron shots are typically made from the ground, not an elevated tee.

💡Wedge

A wedge is a type of golf club with a highly lofted angled face, used for short approach shots and for getting out of sand traps or other difficult lies. The video explains how the AI's wedge neural network is trained to handle uneven terrain, simulating the varied conditions found on a golf course.

💡Putting

Putting is the act of striking the golf ball with the putter on the green to finish the hole by getting the ball into the hole. The video discusses how the AI's putting neural network is trained to prioritize accuracy and control over speed, with a focus on consistent swings.

Highlights

Introduction of a sporting AI for golf using algorithm 'poo'

Return of the 6ft tall, 187 lb ragdoll 'block house' with a neural network

Limitations of Big Balls physics engines and solutions

Increasing the size of the golf ball for realistic simulation

Splitting AI into four separate neural networks for different golf clubs

Use of cross product to determine the swing plane

Reward system based on club velocity and target direction

Adjusting the reward system for backswing and emphasizing speed

Training results showing AI capable of hitting golf balls 210 yards

AI's unique golf swing technique despite ignoring traditional principles

Applying the same algorithm to an iron for different swing mechanics

Tweaking the reward system for iron shots to keep the club flush with the ground

Shortening the backswing for a more precise iron swing

AI's iron swing technique and its impact on distance

Transitioning to short game with a focus on accuracy and control

Adding extra inputs to neural networks for wedge and putting AI

Simulating uneven terrain during training for wedge AI

Reducing backswing for wedge and putting AI to focus on consistency

Mixed results from wedge AI showing versatility but issues with balance

Putting AI's performance and the challenges it faces

Completion of golf AI with four neural networks for different types of shots

Upcoming test of golf AI on actual golf courses

Transcripts

play00:01

we are starting to rack up quite the

play00:02

collection of sporting AI on this

play00:04

channel but honestly it's not enough I

play00:07

want more so today we're going to play

play00:10

some golf with this comes the return of

play00:12

our trusty algorithm poo which is making

play00:14

its fourth appearance on this channel

play00:16

similarly a red ragd doll will also be

play00:19

returning a friend of mine has told me

play00:20

to name it block house but unfortunately

play00:23

some bouldering place we both go to has

play00:25

stolen it so that's unlucky in case

play00:27

you're new to this channel this ragd

play00:28

doll is 6t tall and about 187 lb or if

play00:32

you're English about 1 and 1/2 hours of

play00:34

beer at the allei pal it also Sports a

play00:36

big neural network to control itself

play00:38

which in this case will be used to

play00:40

create a golf swing now before you begin

play00:42

I just want to clear up a few things

play00:44

firstly Big Balls physics engines have

play00:47

limitations small objects tend to phase

play00:49

through the solid surfaces and it's kind

play00:51

of difficult to simulate how the club

play00:53

interacts with the ground on some golf

play00:55

shots to solve both these issues we're

play00:57

going to increase the size of the ball

play00:59

besides that it should behave

play01:00

identically to a real one this includes

play01:03

rolling friction bounciness shot shaping

play01:06

not being able to find it in the woods

play01:08

and kicking it when nobody's watching as

play01:10

for the AI there's a different kind of

play01:12

issue golf is hard and each Club

play01:14

requires a different kind of swing with

play01:16

this in mind we're going to split our AI

play01:18

into four separate neural networks one

play01:20

for driving one for irons one for

play01:23

chipping and one for putting we are

play01:25

dealing with reinforcement learning here

play01:27

so we need a reward system for each one

play01:30

let's start with the driver the first

play01:32

thing we need to do is tell the AI which

play01:34

direction it needs to swing the club but

play01:36

what direction is this well let's take

play01:38

the direction from the shoulder line to

play01:40

the club face and the direction from the

play01:41

shoulder line to the right shoulder we

play01:44

can take these two vectors and perform

play01:46

an operation known as the cross product

play01:48

this spits out a new Direction this

play01:50

direction defines something called a

play01:51

swing plane which is basically the axis

play01:54

we need to tilt around to hit a perfect

play01:55

golf shot we can take this new Direction

play01:58

with the shoulder line to the club face

play02:00

and apply the cross product again this

play02:02

final Vector is the exact Direction the

play02:04

club should be moving in to create a

play02:06

perfect swing we can now easily turn

play02:08

this into a reward by comparing how much

play02:10

the velocity of the club matches this

play02:11

direction and then give out a reward

play02:13

accordingly in Math's terms this will be

play02:16

the dot product of the club's velocity

play02:17

and the target direction we can also

play02:20

reuse the swing plane to measure how far

play02:22

the club has deviated from it and give

play02:24

out a punishment that scales with that

play02:26

to help guide the club back on target

play02:28

this is a good start and this reward

play02:30

system will generate a good back swing

play02:32

but eventually the club will need to

play02:33

come back the other way this can be done

play02:35

by measuring the angle of the club

play02:37

relative to the ball and simply

play02:39

reversing The Swinging reward once it is

play02:41

past a certain point once this happens

play02:43

we will change the swinging reward a bit

play02:45

by squaring it this really emphasizes

play02:48

the importance of moving the club fast

play02:50

by giving the AI huge rewards for doing

play02:52

so unless you're really bad with your

play02:54

wedges your driver should be your

play02:55

longest shot so we're going to encourage

play02:57

the AI to swing as hard as possible here

play03:00

back come back other than that we've now

play03:04

covered all the basics of a golf swing

play03:06

and it should be enough for our driving

play03:08

AI to learn how to hit good golf shots

play03:10

let's see what it comes up

play03:16

[Music]

play03:23

[Music]

play03:28

with

play03:30

[Music]

play03:40

[Music]

play04:11

[Music]

play04:13

H some interesting results there our

play04:16

training has been successful and our

play04:18

driving AI is now capable of Smashing

play04:20

golf Falls roughly 210 yard there is a

play04:23

slight pull in its shots but this can

play04:25

easily be compensated for by aiming

play04:27

slightly to the right if we examine the

play04:29

Technique we can see this beautiful

play04:31

swing in action the AI immediately

play04:33

shifts all of its weight onto its right

play04:35

foot because obviously one leg is better

play04:38

for balance than two but you know what's

play04:40

better than one leg none which the AI

play04:43

demonstrates by attempting to fly like

play04:44

Superman as it brings the club back down

play04:46

it holds this position all the way until

play04:48

it strikes the ball at which point its

play04:50

legs are completely parallel with the

play04:52

ground we are then treated to two very

play04:54

contrasting actions a beautiful drive

play04:57

and a painful face plant despite

play05:00

completely ignoring all golf principles

play05:02

our AI has managed to create a unique

play05:04

and interesting swing but how well will

play05:06

this transfer to other types of golf

play05:08

shots let's apply the same algorithm to

play05:11

an iron iron swings are very similar to

play05:13

driver swings but there is one big

play05:15

difference typically irons are hit from

play05:17

the ground not an elevated te this makes

play05:20

the shot slightly more challenging as

play05:22

lowering the club to much will at best

play05:24

turn it into a lawn mower and at worse a

play05:26

shovel we will take the original reward

play05:28

system and add one small tweak we will

play05:31

measure the height of the club from the

play05:32

ground and give it a reward based on how

play05:34

close it is to being flush this places a

play05:37

bit of emphasis on keeping the club

play05:38

flush with the ground without being too

play05:40

overbearing on the original system

play05:42

additionally we will shorten the back

play05:44

swing a bit which will reduce the speed

play05:46

at which the AI swings overall this

play05:49

slightly tweaked reward system should

play05:50

lead to a more precise swing let's see

play05:53

how it

play05:58

goes

play06:04

[Music]

play06:12

[Music]

play06:21

[Music]

play06:52

[Music]

play06:59

[Music]

play07:04

once again our training has been

play07:06

successful overall the technique Remains

play07:09

the Same the AI pivots onto its left

play07:11

foot like before but this time it's a

play07:13

little more stubborn and opts to keep it

play07:15

there all the way until it strikes the

play07:16

ball after the hit it transforms into a

play07:19

Tetris piece and face plants the path of

play07:22

the club is a little sloppier and tends

play07:24

to drag along the ground just before the

play07:26

ball is struck this is a little

play07:28

unfortunate and it does cost the AI some

play07:30

distance but overall it is still

play07:32

consistent enough to do its job properly

play07:34

so we can now move on to the next steps

play07:36

so far our AI has trained to hit it long

play07:39

but how's it short game this is where

play07:41

things get tricky we are now less

play07:43

concerned with distance and more

play07:44

concerned about accuracy and control so

play07:47

our two remaining AI will be built with

play07:49

this in mind for both the wedge and the

play07:51

putting AI we are going to add an extra

play07:53

input to the neural networks which will

play07:55

help us control how hard they swing to

play07:57

enforce this both the reward reward

play07:59

systems will be changed slightly from

play08:01

rewarding speed to rewarding how close

play08:03

it gets to the Target speed we will also

play08:05

add something extra to the wedge AI if

play08:07

you've ever been around a green before

play08:09

you may have noticed the large amount of

play08:10

bumps and Hills or these holes that they

play08:13

put a rake in for some reason the

play08:14

terrain is far from being flat so our

play08:17

wedge AI will need to learn how to hit

play08:18

shots on uneven terrain during training

play08:21

we will simulate this by generating a

play08:23

random platform for the ragd doll to

play08:25

stand on every shot attempt this will

play08:27

change which will force our to become

play08:29

more resilient to the uneven terrain it

play08:31

will face on actual courses as for the

play08:33

putting AI this isn't necessary putting

play08:36

is almost exclusively done on the green

play08:39

which typically is the flattest part of

play08:41

a golf course for a final touch we will

play08:43

greatly reduce the back swing of the

play08:45

wedge and putting AIS which should

play08:47

encourage them to focus more on

play08:48

consistency rather than speed and that

play08:51

should be all we need to do so let's run

play08:53

yet another training session see you

play08:58

soon

play08:59

[Music]

play09:06

[Music]

play09:13

[Music]

play09:23

[Music]

play09:54

[Music]

play10:01

[Music]

play10:15

[Music]

play10:25

[Music]

play10:48

[Music]

play11:16

[Music]

play11:35

that's a mixed bagger results if I've

play11:37

ever seen one on one hand we have our

play11:39

wedge AI if you disregard the falling

play11:42

over part it's pretty good The Stance it

play11:44

takes at the start is quite similar to

play11:46

how real golfers are taught and the

play11:48

swing is also fairly normal even after

play11:50

the ball is hit the AI still looks okay

play11:53

unfortunately though this doesn't last

play11:56

the AI finishes by attempting a kotti

play11:58

kick and promptly fails because of its

play12:01

training on randomized surfaces the

play12:03

wedge AI boasts quite a bit of

play12:04

Versatility it can hit a ball from a

play12:06

flat surface or a bunker or a

play12:10

tree or even inside a clubhouse it

play12:13

doesn't matter it's pretty good at its

play12:15

job wish I could say the same about the

play12:17

putting AI though here's a small set of

play12:20

rules to ensure that you too can learn

play12:22

how to putt one make sure you keep your

play12:24

leg straight and make sure that you're

play12:26

looking at the ball two if you're sure

play12:29

of the speed of your swing drag your

play12:31

putter along the grass so that you can

play12:32

readjust it three follow through

play12:35

preferably as stiff as possible four hit

play12:38

the ball on a 45° angle this is

play12:41

extremely important as the flag might be

play12:43

in that direction and finally lie down

play12:47

this will conserve energy for your next

play12:48

shot follow these rules and you'll be a

play12:51

professional in no time or you might

play12:53

just end up being a shitty putting robot

play12:55

you know what it works and that's good

play12:57

enough for me our golf AI is now

play13:00

complete boasting four neural networks

play13:02

for every type of Shot Golf has but how

play13:04

will it perform in a real game in the

play13:07

next video I will put it to the test by

play13:09

cing it through some golf courses

play13:11

special thanks to the Banana Fish C for

play13:13

supporting this

play13:27

video yes I a ho in one I won had

play13:35

reward what mean no you didn't even

play13:39

check what does mean you think I

play13:42

understand that you got what it takes

play13:47

where where are my giant Apple te why

play13:50

did it take 6 months for that video to

play13:52

come

play13:55

out

Rate This

5.0 / 5 (0 votes)

Related Tags
AI GolfNeural NetworksPhysics EnginesGolf SwingMachine LearningAlgorithm GolfSwing PlaneGolf AIReinforcement LearningGolf Simulation