Capturing NMEA sentences over WiFi using Python

In order to figure out how the NMEA-WiFi Gateway deals with clients, e.g. if it expects any “handshake” or any other communication setup protocol, I decided to write a simulator mimicing the gateway, and then using iRegatta 2 from Zifago to verify that it can read the simulated NMEA messages sent by my “soft” gateway.

So, in the video above, my laptop (on the right) is pretending to be the NMEA-WiFi gateway, constantly broadcasting UDP packages containing NMEA sentences onto the network, and on the left my iPad running iRegatta 2 is collecting them and displaying the information obtained from the sentences.

With the communication between the Gateway and its clients now figured out, I’m able to collect full race data, including multiday races, from all the instruments onboard onto my laptop for after race “post mortem” race performance analysis.

Posted in Data Analytics, Maritime Technology, Nautical Information Systems, NMEA, Numpy, performance, Python, Simulation, TCPIP | Tagged , , , , , , , , , , , , | Leave a comment

Parsing NMEA 0183 sentences in Python

My skipper has recently bought an NMEA wifi gateway, which means that the NMEA messages from the various onboard instruments on his yacht are broadcasted on the yacht’s wifi network. This makes it very easy to grab the NMEA messages, and start trying to make sense of them.

Below an example of parsing a handful of the message types, on a Garmin network (note: the data collection was done with the boat stationary, thus there’s no interesting info about speed, vmg etc in these graphs, that will have to wait until we are actually sailing… 😉

The first graph is a frequency plot over the various NMEA message types – the most frequent messages are (remember, the boat was stationary):

IIHDT – heading T
GPWCV – waypoint closure velocity
GPZDA – time & date
IIVTG – track made good and ground speed
GPXTE – xross track error
IIVPW – speed parallel to wind
IIDBT – depth below transducer
GPGSV – satellites in view
IIHDM – magnetic heading
IIWHW – Speed thru water
GPGLL – lat & long
IIMWD – wind direction & speed
GPRMC – recommended minimum data


The next plot shows the true wind speed and angle over a period of time.


The last graph shows two polar plots over true and apparent wind.


Finally, an idea for the main performance analysis screen:


Continue reading

Posted in Data Analytics, Maritime Technology, Nautical Information Systems, NMEA, Python | Tagged , , , , , | Leave a comment

New Theory Cracks Open the Black Box of Deep Learning | Quanta Magazine

A new idea is helping to explain the puzzling success of today’s artificial-intelligence algorithms — and might also explain how human brains learn.
— Läs på

Posted in AI, development, Machine Learning | Tagged , , | Leave a comment

Making a living as a Professional Scientific Gambler using Bayesian Inference…?

prediction_results_unibetprediction_results_M2prediction_results_M1profit-lossreal_profitsAs my readers know, over the past few weeks I’ve been conducting an experiment:

Applying scientific betting on the just finished Ice Hockey World Championships.  By “scientific”, I’m referring to the exclusive use of statistical and mathematical models, simulation, and probabilistic programming, more specifically, Markov Chain Monte Carlo and Bayesian Inference.

For this experiment, wrote a Python based Bayesian Inference Engine, which fundamentally uses two main sources of information: historical game results and the official IIHF rankings table. Based on those two sources of information, the engine will come up with probalities for the outcomes of each of the 64 games in the tournament.

It is also important to state that I know absolutely nothing about contemporary ice hockey, I don’t know the teams nor the players,I have  not been watching ice hockey for at least 15 years, my interest in the game is zip & nada, so my own knowledge about ice hockey is pretty much zero. That means that I have not used any other information in my experiment, than the historical game outcome data and the official rankings. The predictions, and the betting resulting from those predictions are thus solely based on what the inference engine predicts in terms of outcomes.

So, with these premises, how did the experiment go ? Is it possible, even without any own interest or knowledge about a sport, to make a living as a professional gambler…?

The tournament consisted of 16 teams and 64 games. My inference engine predicted the outcomes of each of these games, and I placed bets, one or more, on most of the games.

Withouth revealing the actual sums involved, here’s the results, both financial and for the predictions:

  • Return on Investment: 21%
  • Net Profit Margin: 5%
  • Game Outcome Prediction Success Rate: 53% [to be compared to Unibet’s 58%]
  • Ratio successful/failed bets: 27%
  • Average betting odds: 6.5

So, over the past couple of weeks, I made 21% profit on top of my investment. From a financial perspective, that’s an ok ROI, and hadn’t this been an experiment, but a real attempt to make money, the profit would very likely been (much) higher: now, because of the experimental status, I’ve placed many “stupid” bets in order to see what happens,  bets which I wouldn’t have placed in a production scenario, where the sole objective would be to make money, not making experiments.

What about the performance of the Python based home made inference engine, then…? Actually, it performed much better than I hoped for: until the last few somewhat surprising games in the final rounds, the hit rate was around 63%, with Unibet at the same time being at 67%. Due to a couple of surprising outcomes, e.g. FIN-SUI and CAN-USA, my hit rate dropped to 53%, compared to Unibet’s final 58%.  So, my home made  program performed about 5 pct points worse than the prediction engine of a professional, huge betting shop, with zillions of computing power as well as zillions of experts, studying and knowing every aspect of each team and game.  Better yet, the engine performed well enough to allow me exit the experiment with a 21% ROI, i.e “winning over the betting house”, which is the real measure of success/failure.

So, in summary, to answer the question “Is it possible to make a living as a professional gambler using scientific methods ?”

My answer, after this experiment is YES. And the more you are interested in the game, the more you know about the game, the better “odds” you’ll have for being successful. But this experiment has demonstrated that by appying scientific methods, you can be fairly successful even if you know absolutely nothing about the game, nor have any interest in it.


Posted in Bayes, Data Analytics, Data Driven Management, Finance, Gambling, HOCKEY-2018, Math, Numpy, Probability, PYMC, Python, Simulation, Statistics | Tagged , , , , , , , , , | Leave a comment

Scientific Gambling – Ice Hockey World Championships starting tomorrow


The tournament is starting tomorrow with four games. From now on, future posts on this topic on the public Facebook group Scientific Gambling on Ice Hockey World Championships 2018 only.

So, I you want to continue following how my Bayesian Inference engine performs in its attempts to scientifically predict the outcomes of the games, and how much money I’m going to win – or lose – on my gambling, check out the FB-group.


Posted in Bayes, Big Data, Data Analytics, Data Driven Management, Gambling, HOCKEY-2018, Math, Numpy, Probability, PYMC, Python, Statistics | Tagged , , , , , , , , , , , , | Leave a comment

Scientific Gambling – “House Advantage”

In previous post we looked at how Betting Shops, Casinos etc make money, fundamentally by ‘salting’ the odds just a tiny bit in their favor.

Let’s use two very simple games to illustrate how this works, tossing coins and throwing dice.

Let’s start with a game of coin toss, assuming a fair coin, that is, the probability of getting heads or tails is fifty-fifty, that is, 0.5. The corresponding ‘straight’ odds for this game are thus 2 (decimal format), or 1:1 (fractional format). By ‘straight’, I mean odds that are directly given by the outcome probabilities. However, no professional betting shop can issue straight odds, if they would do so, they would very soon go out of business, simply because playing with straight odds is a zero sum game, that is, in the long run, the expected value of the game is zero, for both the player and for the house.

How to see that…? Let’s pretend we play coin toss repeatedly, very many times. In the long run, we should expect winning in half (50%) of the games, losing in the other 50% of the games. As an example, let’s say we play 100 times, the stake per game is 1$, and we have fair odds, that is 2 (inverse of 50% probability). So, these 100 games, where each game costs 1$, will cost us 100$. Statistically, we should win 50 times, lose 50 times. To make this a fair game, i.e. a zero sum game, we need to win back the cost of all the 100 games, that is 100$ within the 50 winning games. Dividing 100$ by 50 wins means that each win should return 2$, what is what will happen if we have straight odds set, i.e odds of 2 for this game.

So, in order to make money, the betting shops do not use straight odds, but instead ‘salt’ the odds a tiny bit in their favor, to ensure a healthy margin.  Let’s markup the probabilities by 5%, i.e. applying a markup of 1.05 to the odds. Now,  and instead of odds 2, we have odds 1.90 for both outcomes. Still, assuming a fair coin, we can expect winning 50% of the time. So, again, with 100 games, we should expect to win 50. The cost of the 100 games is still 100$, but the returns now are not 50 * 2 == 100, but 50 * 1.90 == 95$. That is, in the long run, we should expect to lose 5% of our stake. That markup of  of the odds, here 5% , thus generates a house advantage of 5%, which is the reason for being for any professional betting shop or casino.

For the game of throwing dice the same thing applies: in dice throwing, the probability of a fair dice to land on any of the 6 sides is 1/6, which gives that fair betting odds are 6 (decimal), or 5:1 (fractional). In order to make a profit, the betting shop must markup the odds, exactly as for the coin tossing example above.

Below two graphs shows simulations of 1.000.000 games of coin tossing and dice throwing, where the red lines show the cumulative results (total win/loss) after the 1.000.000 games. As can be seen, with fair odds both games are very close to zero sum, while with a 5% markup, the house makes a healthy profit of 5%, i.e. about 50.000 $.


Posted in Gambling, Math, Probability, Statistics | Tagged , , , | Leave a comment

Scientific Gambling – how do betting shops make money….?

Betting shops are commercial businesses, that is, they want to and must make money in order to survive. Like any other business. So take a casino as an example: they make money – in the long run – by having set the odds just a tiny bit in their favor, the typical “house advantage” in games like Roulette is 5.26% (American Roulette) and 2.70% (European Roulette). What the house advantage tells us, is the relative amount a player is expected to lose for each play.  In the long run. Thus, making a bet of 1$, you should expect to lose about 5 or 3 cents, each time. Over time, these tiny wins for the casino accumulate to quite a lot of money. I have no idea what turnover per day the typical Las Vegas casino has, but let’s say 10.000.000 USD. 5% of that is 500.000 USD, not bad for spinning a few wheels…

The cool thing about games like Roulette is that they are based on “known unknowns”, where the risk is fully understood mathematically, i.e. all the probabilities involved are fully known.

In sports betting, on the other hand, the probabilies are not known, since we are dealing not with risk, but uncertainty, i.e. we are dealing with Unknown Unknowns. So how do betting shops like Unibet, Svenska Spel and others make money on sports betting…?

Easy: just apply a markup to the probabilies/odds: Below an illustration, from a simulation run on my computer:

The blue line shows the cumulative returns given “fair odds”, i.e. odds that are a direct reflexion of the probability of the game outcome: for instance, if the probabilities for a given game are believed to be 1/3 each for WIN, DRAW, LOSS, then each of these outcomes would have odds set to 3 (decimal), or 1:2 (fractional) , that is, you’d get 3$ back for your 1$ stake, if you happened to win.  As can be seen from the graph, after a million games the blue line ends up a little bit above 0, meaning that the player, i.e. you, in this case would leave the casino – or betting shop – with a small gain.

The red line shows what happens to expected returns when I have applied a tiny markup to the probabilities/odds, as all betting shops or casinos do: the line grows almost monotonically towards the negative side, i.e. constantly accumulating wins for the casino/betting shop. That’s the “house advantage” at play.  In this simulation run, I’ve set the house advantage, or markup, to a rediculously low value, regardless, the result is clear, the house is making money.

Anyone wanting to take a guess on the house advantage set in this example…? 🙂

But remember that in sports betting, we are dealing with Unknown Unknowns. That means that to safeguard against potentially huge losses due to all the uncertainties involved in sports game outcomes, the betting shops need to apply a fairly hefty markup to their odds, otherwise the would run a clear risk of going bankrupt in the case when they have set way too high odds.

“Prediction is difficult, particularily about the future”.



Posted in Bayes, Data Analytics, Gambling, HOCKEY-2018, Math, Numpy, Probability, PYMC, Pystan, Python, Simulation, Statistics | Tagged , , , , , , , , , , , | Leave a comment

Scientific gambling – How to identify potentially profitable odds/plays ?

In all sports gambling, success or failure is determined by a number of factors, luck not being the least of them, since in any sport there are loads of “Unknown Unknowns“, which we could also call “Uncertainty”. And then there is randomness.

If we compare sports betting with casino type betting, in casino betting we can talk about “Risk” instead of “Uncertainty”, since for the casino games like roulette etc we can mathematically calculate all the probabilities involved. However, in sports betting, no matter how much data we have, we have no way to mathematically decide the exact odds, because there are many Unknown Unknowns involved in each game. Thus, sports betting is a truly probabilistic endeavor, fully dominated by uncertainty, asop to calculable risk.

But, despite the presence of the Unknown Unknowns, we can attempt to do the best we can, by utilizing data that we have available, such as rankings, historical results etc. This is what my Bayesian Inference Engine does, basically calculating the most likely outcomes for any game, given the rankings and historical results (as well as the statistical model I’ve given it).

So, let’s take a concrete example of how I decide upon which games to bet on:

First, I execute my Bayesian Engine on the rankings and historical game data that I’ve gathered, about 1100 world championship games since year 2000 to date. Basically, what the engine does is to do millions on simulations, trying to come up with model parameters that generate the same results as in the historical games. Once these parameters are known, they are used to predict the outcomes of new games.  Such a run can take anything from a few hours to days (or even weeks) depending on how many games the model is predicting, how much data there is, and how “deep” I’ve told it to go in its analysis. A typical run covering each days 4-6 games takes about 10 hours of cpu-time on my machine.

When the Bayesian Inference in the above step is done – typically run overnight – it’s time to analyze the predictions, and to compare the predictions with the predictions of a commercial betting shop, in my case, Unibet, trying to identify games where my program has found an advantage in the odds setting.

The first thing I do, is to check for any games where the probabilities between Unibet’s predictions and my predictions differ:


Instead of looking at de massive amount of numbers in rows and columns, the above graph gives me a quick overview on where, according to my program, there might be an odds setting that is advantageous to me: basically, here I look for the different colored sub-bars, and compare their size. For instance, here, I can see that the game RUS-FRA, my program has identified the probability of a draw quite a bit higher than Unibet, thus, that might be a candidate for placing a bet. Let’s have a closer look:


Above graph shows the differences in probabilities between Unibet’s predictions and my predictions. The one’s that are potentially interesting, are the one’s on the plus-side, i.e. where my program has found a higher probability than Unibet.  RUS-FRA is interesting, as well as SWE-BLR, and SUI-AUT. Let’s dig deeper, using RUS-FRA as our example:


Here we can see that given my program’s prediction of the outcome of RUS-FRA, vs. the prediction on which Unibet bases its odds, there is an opportunity here to make money  – IFF MY PROGRAMS PREDICTION HAPPENS TO BE CORRECT AND THE SMALL MIRACLE OF FRA WINNING HAPPENS! – since according to my program, the probability for a draw as my program sees it, is higher than how Unibet sees it, and therefore, they have set the odds for a draw higher than they should be, as my prediction sees the outcome of that game.

Of course, RUS is still a huge favorite to win, for Unibet as well as for my program, with 8/10 vs 7/10 wins for Russia, respectively, but that small difference is exploitable, as a high risk/high reward gamble, since the odds are set for 8/10 wins, not 7/10 wins, as my program predicts.

Let’s zoom in a bit closer to see why it might be that my program puts a bit higher probability to a draw than does Unibet:


Russia – France have met 4 times at world championship level since 2000, and Russia have won all but one, the 2013 game. Now, I have no insights into how Unibet’s odd compiler ranks this type of “anomaly”, but that single loss could be the difference in predictions.

Anyways, it’s interesting enough for me to put some money on that game, yes, the likelihood of winning the bet is fairly small – after all, my program thinks that RUS will beat FRA in more than 7 out of 10 games, but the upside is quite large, thus worth the calculated risk. As stated above, sports betting has loads of Unknown Unknowns, and who knows, perhaps I’m getting lucky….? 🙂

Posted in Bayes, Data Analytics, Data Driven Management, Gambling, HOCKEY-2018, Math, Numpy, Probability, PYMC, Python, Statistics | Tagged , , , , , , , , , , , | Leave a comment

Scientific Gambling on Ice Hockey Worlds – identifying potentially exploitable games

One of the most difficult aspects of dealing with lots of data, is to present the information obtained from various computations in a clear and meaningful way. For instance, in order to identify games where there is a potentially exploitable gambling advantage between the odds given by Unibet, and the probabilities obtained from my Bayesian engine, I must compute all predited game outcomes (WIN/DRAW/LOSS) for both Unibet and my system, and then identify potential exploitable differences. The graph below is a new attempt to consolidate all this information into a single graph.
Each game has potentially 4 bars. The 3 leftmost are predictions from my system, where the third is the average prediction of the two statistical models I use. The rightmost bar (where it exists) is Unibet’s odds converted to probabilities (taking into account the markup that all betting shops place on their odds).
So, with this graph, the basic process to identify potentially exploitable games is to compare each of the colored sub-bars from my program, with the corresponding Unibet bar. Those bets where any of my sub-bars are taller than Unibet’s, are the high risk/high reward games that might be exploitable.
[there are two reasons not all games have all four bars: if there’s no previous historical games between the two teams, like for FIN-KOR, or if Unibet have not yet publicized their odds, as for FRA-BLR and DEN-USA]
Posted in Bayes, Data Analytics, Data Driven Management, Gambling, HOCKEY-2018, Math, Numpy, Probability, PYMC, Python, Statistics | Tagged , , , , , , , , , , , , | Leave a comment

Scientific Betting on Ice Hockey Worlds now on Facebook

Scientific Gambling on Ice Hockey World Championships 2018


Posted in Bayes, development, Gambling, HOCKEY-2018 | Tagged , , | Leave a comment