If you're a fan of HBO's Game of Thrones or the A Song of Ice and Fire books, you'll be well aware that there are about a billion intertwined characters in George R. R. Martin's cruelly fascinating world.

But when it comes down to it, who's the real star of the show? The storyline often seems to revolve around the Stark children - Arya and Sansa - and Cersei, Jon Snow, and mother of dragons, Daenerys Targaryan, all get their share of the spotlight (as did Ned and Rob Stark before they were killed off). But mathematicians have now used an algorithm to calculate who's most vital to the storyline, and it's probably not your first pick.

According to the researchers, the character best connected to the other characters, and therefore the most influential, is the small but mighty lion, Tyrion Lannister.

And when you think about it, he certainly has had his fingers in a lot of proverbial pies, starting off the series on a tour of Winterfell and the Wall, before being captured by Catelyn Stark and reaching the Eyrie as her prisoner, and then eventually returning to control the coffers of King's Landing (and assassinate a few key characters before fleeing). He's now by the side of our favourite Khaleesi across the Narrow Sea, and everyone's hoping he'll be the one to finally bring her victorious back to Westeros.

But all my fan-girling aside, how do you map that type of influence from a mathematical point of view? Andrew J. Beveridge and Jie Shan from Macalaster College in Minnesota were able to tease apart the many characters in the books using network science - which basically examines how information flows from one thing to another.

To do this, they used the third book of the series, A Storm of Swords, and pinpointed every time two characters appeared within 15 words of one another. The more often those names appeared together, the more weight the link between the two characters was given.

"This is a fanciful application of network science," Beveridge told Quartz. "But it's the kind of accessible application that shows what mathematics is all about, which is finding and explaining patterns."

That mapping produced the network below, broken down into characters and their communities. And as fans of the book of TV show will note, it pretty accurately represents the groups we know and… love? "We didn't tell it what the communities were, the network actually tells you what the communities are," Beveridge said.

But connections alone don't tell you the whole story, and the researchers then ranked each of the characters using a several different measures, including PageRank - the algorithm that Google users in its search engine - to reward characters based on how important their associates were.

In the end, Tyrion ranked first in every measure except for one, making him the stand-out main character in Game of Thrones.

Second place went to Jon Snow, who may or may not still be alive as head of the Night's Watch. He was also the only one to beat Tyrion in the measure of 'betweenness', which assesses a character's influence over different groups. The third most influential character was Sansa Stark, who we can't wait to see come into her own this season.

In fact, Beveridge and Shan think Sansa is the real surprise in their study, seeing as so many viewers overlook her as the 'weak' pawn.

"However, other players are aware of her value as a Stark heir and they repeatedly use her as a pawn in their plays for power," they write in their report, called "Network of Thrones", in the Mathematical Association of America's publication, Math Horizons. "If she can develop her cunning, then she can capitalise on her network importance to dramatic effect."

Daenerys is an interesting one, because she didn't rate too highly in A Storm of Swords or this study due to her physical isolation in Essos. But she becomes far more important in the later books, and that's somewhat predicted by the research - because the few links she does have are with extremely important people.

While it's fun to apply maths to our favourite show, there are also a lot of practical applications of this type of research - most importantly to help security agencies and police to help study terrorist networks.

And surely if the technique has proved itself with the twisted, convoluted world of Game of Thrones, mapping out our comparatively simple IRL relationships should be a piece of cake, right? Let's just hope that history doesn't repeat itself and our main character isn't about to be killed off, because we're not sure how we'd go without Tyrion's pithy one-liners.

Game of Thrones/HBO