Notes on Monte Carlo Simulation

March 14, 2021
machine_learning python random_walk

Some notes taken from Prof. Guttag excellent discussion on the topic.

The technique was first developed by Stanislaw Ulam, a mathematician who worked on the Manhattan Project.

A method of estimating the value of an unknown quantity using the principles of inferential statistics.

Inferential Statistics

Confidence depends on:

Roulette Considerations

Gambler’s Fallacy: if a particular event occurs more frequently than normal during the past it is less likely to happen in the future (or vice versa), when it has otherwise been established that the probability of such events does not depend on what has happened in the past.

Regression to the mean: Following an extreme random event, it is likely that the next random event will be less extreme.

Quantifying Variation

$$ variance(X) = \frac{\sum_{x\in X}(x - \mu)^2}{|X|} $$

The mean $$\mu$$

$$\sigma(x) = \sqrt{variance(X)}$$

Empirical Rule


Probability Density Function

import random

class FairRoulette():
    def __init__(self):
        self.pockets = []
        for i in range(1, 37):

        self.pocket_odds = len(self.pockets) - 1


    def spin(self):
        self.ball = random.choice(self.pockets)

    def bet_pocket(self, pocket, amount):
        pocket: pocket placing bet
        amount: sum being bet
        if str(pocket) == str(self.ball):
            return amount * self.pocket_odds
            return -amount
    def __str__(self) -> str:
        return 'fair roulette'

class EURoulette(FairRoulette):
    def __init__(self):
    def __str__(self) -> str:
        return 'EU Roulette'

class USRoulette(EURoulette):
    def __init__(self):
    def __str__(self) -> str:
        return 'US Roulette'

def play_roulette(game, num_spins, pocket, bet):
    game: Roulette game being played
    num_spins: number of spins for the simulation
    pocket: pocket placing bet
    bet: amount of bet
    total_pocket = 0
    for i in range(num_spins):
        total_pocket += game.bet_pocket(pocket, bet)

    print(f'{num_spins} spins of {game}')
    print(f'expected return betting {pocket} = {str(100*total_pocket/num_spins)}%')

    return total_pocket/num_spins

if __name__ == "__main__":
    game = FairRoulette()
    for num_spins in (100, 1000000):
        for i in range(3):
            # betting 1 dollar on number 2 for num-spins trials
            play_roulette(game, num_spins, 2, 1)

Type2Fuzzy Library Implementation: Mendel, Jerry M., and RI Bob John. 'Type-2 fuzzy sets made simple.'

October 27, 2021
type2_fuzzy type2_fuzzy_library fuzzy python

Mathematical prerequisites for some Clustering techniques

October 14, 2021
maths machine_learning

Simple Python implementation of the Weiszfeld algorithm

March 14, 2021
machine_learning python weiszfeld_algorithm
comments powered by Disqus
hugo_cms 11 fuzzy 10 python 9 machine_learning 5 type2_fuzzy_library 5 cnc 4 type1_fuzzy 4 type2_fuzzy 4 r 3 excel 2 iot 2 it2fs 2 weiszfeld_algorithm 2 arduino 1 classifier 1 development 1 game 1 javascript 1 learning 1 mathjax 1 maths 1 mxchip 1 pandas 1 random_walk 1 robot 1 roc 1 set 1 tools 1 type_2_fuzzy 1 vscode 1 wsl 1