JavaScript, life

The Monty Hall Problem

The Monty Hall problem is a brain teaser loosely based on the American television game show “Let’s Make a Deal” and named after its original host, Monty Hall.

I wrote a little web app that show you what is the right choice with a simulator. It’s a bit hard to explain the correct solution as it’s going against ‘common’ sense. Continue reading

Chrome, JavaScript, webdev

(Try To) Predict The World Cup With Monte Carlo Simulation

brazil 2014 world cupWho will win this world cup? Brazil without Neymar? Lionel Messi? Or are we going to see the Nederland making a big surprise?

If you like coding, statistics and problems that are not trivial… You found the right place. In this post, I will try to show an example to a way for solving this type of questions. For the readers that don’t remember what is Monte Carlo simulation (don’t be shy) – You might want to check a previous post that I wrote last summer and give you an intro to the world of Monte Carlo on Apps script and Google compute engine.

Monte Carlo experiments (simulations) are a broad class of computational algorithms that rely on repeated random sampling to obtain numerical results. In most cases, we will run our simulations many times over in order to obtain the distribution of an unknown probabilistic entity.  This tool is often used in physical and mathematical problems and are most useful when it is difficult or impossible to obtain a closed-form expression, or infeasible to apply a deterministic algorithm.
In the real world, we see it being mainly used in three distinct problem classes:
* Optimization.
* Numerical integration.
* Generation of draws from a probability distribution.


OK, there is no time. The game starts in two days.

The Idea

Monte Carlo simulations tend to follow a particular pattern. Here is how we will use this tool: Continue reading

Chrome, JavaScript

Monte Carlo Simulation On Compute Engine/App Script

App script on Ido's project placeThis week in Google Developer Live Israel we show you how to work with Google App script in order to run Monte Carlo simulations and get the results in a nice informative way inside google spreadsheets. We took it one step farther, and explained how to run these script on your own instance machine inside Compute Engine with nodeJS. This is powerful option because with the ability to ‘try’ quickly on App Script and than take the code to ‘production’ (=more efficient way) on Compute engine give you more productivity.

So what we are doing? First let’s touch on the definition. This is a problem solving technique used to approximate the probability of certain outcomes by running multiple trial runs, called simulations, using random input variables. The cool aspect is that we are steering the scenarios by using randomness. The randomness helps us ‘try’ each future scenario in a way that includes our probability per variable. This gives us the ability to fine tune our trial runs to answer a question with several variables. In simple words, in our case, it will help us find the best way to spend the time of our sales person.

 Monte Carlo simulations Steps

1. Define a model with a domain of possible inputs.
2. Generate inputs values randomly, but sampling from a probability distribution over the domain.
3. Perform a deterministic computation on the inputs.
4. Aggregate the results. Continue reading