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

Standard
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

Standard
Chrome, JavaScript

Monte Carlo Simulation On Compute Engine/App Script

App script on Ido's project place

This week in Google Developer Live Israel, we show you how to work with Google App script to run Monte Carlo simulations and get the results in an excellent informative way inside Google spreadsheets. We took it further and explained how to run these scripts on your instance machine inside Compute Engine with nodeJS.

This is a powerful option because the ability to ‘try’ quickly on App Script and then take the code to ‘production’ (=more efficient way) on Compute engine gives you more productivity.

So what are we doing?

First, let’s touch on the definition. This problem-solving technique approximates the probability of specific outcomes by running multiple trial runs, called simulations, using random input variables. The remarkable aspect is that we are steering the scenarios by using randomness.The randomness helps us ‘try’ each future strategy in a way that includes our probability per variable. This allows us to fine-tune our trial runs to answer a question with several variables. It will help us find the best way to spend time with our salesperson.

 Monte Carlo Simulations Steps

1. Define a model with a domain of possible inputs.

2. Generate input values randomly, sampling from a probability distribution over the domain.

3. Perform a deterministic computation on the inputs.

4. Aggregate the results. Continue reading

Standard