Notes on Monte Carlo Simulation

Sun 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

Assumptions

Probability Density Function

import random

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

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

        random.seed(0)

    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
        else:
            return -amount
    def __str__(self) -> str:
        return 'fair roulette'

class EURoulette(FairRoulette):
    def __init__(self):
        super().__init__()
        self.pockets.append('O')
    def __str__(self) -> str:
        return 'EU Roulette'

class USRoulette(EURoulette):
    def __init__(self):
        super().__init__()
        self.pockets.append('OO')
    def __str__(self) -> str:
        return 'US Roulette'


def play_roulette(game, num_spins, pocket, bet):
    '''
    Arguments:
    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):
        game.spin()
        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)



Paper Implementation - Uncertain rule-based fuzzy logic systems Introduction and new directions-Jerry M. Mendel; Prentice-Hall, PTR, Upper Saddle River, NJ, 2001,    555pp., ISBN 0-13-040969-3. Example 9-4, page 261

October 8, 2022
type2-fuzzy type2-fuzzy-library fuzzy python IT2FS paper-workout

Notes about Azure ML, Part 10 - An end-to-end AzureML example; Model Optimization

Creation and execution of an AzureML Model Optimization Experiment
machine-learning azure ml hyperparameter tuning model optimization

Notes about Azure ML, Part 9 - An end-to-end AzureML example Pipeline creation and execution

Creation and execution of a multi-step AzureML pipeline the selects the best model for a given dataset.
machine-learning azure ml pipeline
comments powered by Disqus


machine-learning 25 python 21 fuzzy 14 hugo_cms 11 azure-ml 10 linear-regression 10 gradient-descent 9 type2-fuzzy 8 type2-fuzzy-library 8 type1-fuzzy 5 cnc 4 dataset 4 datastore 4 it2fs 4 excel 3 paper-workout 3 r 3 c 2 c-sharp 2 experiment 2 iot 2 programming 2 robotics 2 weiszfeld_algorithm 2 arduino 1 automl 1 classifier 1 computation 1 cost-functions 1 development 1 embedded 1 fuzzy-logic 1 game 1 hyperparameter-tuning 1 javascript 1 learning 1 mathjax 1 maths 1 model-optimization 1 mxchip 1 pandas 1 pipeline 1 random_walk 1 roc 1 tools 1 vscode 1 wsl 1