Coder Social home page Coder Social logo

total_probability's Introduction

Scrutinizer Code Quality Build Status MIT Licence

Total probability + Thomas Bayes, Bernoulli distribution formulas

This project was created for those folks who love Math + PHP and either want to have a great library to work with Total probability and Bayes, Bernoulli formulas to calculate any real-world tasks on demand.

Examples

Total probability

We have 3 baskets:

  • 1-st basket contains 7 black and 4 white balls

  • 2-nd basket contains only white balls

  • 3-d basket contains only black balls

What's the probability of taking a black ball?

The basket choice is 1/3.

  • In the 1st basket we've got 7/11(7+4) probability of taking black ball.

  • In 2nd basket there are only white balls - probability is 0.

  • In 3d basket there are only black balls - probability is 1.

So we execute totalProbability method from Formula class:

$this->formula = new Formula();
$result = $this->formula->totalProbability(
    [0.33, 0.33, 0.33],
    [0, 1, 0.45],
]);
echo $result; // 6/11=0.(54)

Thomas Bayes

At the warehouse came 2 party products:

  • 1st - 4000 items
  • 2nd - 6000 items

The percent of a non-standard items in 1st party is 20%

The percent of a non-standard items in 1st party is 10%

Randomly taken item of two parties turned out to be standard - what's the probability relation of this item to 1st and 2nd party.

Part 1:

Overall items at the warehouse: 4000 + 6000 = 10000 -> 4000/10000 = 0.4, 6000/10000 = 0.6

Check: 0.4+0.6=1

  • 1st party has standard items -> 100% - 20% = 80% standard items -> 80/100 = 0.8

  • 2nd party has standard items -> 100% - 10% = 90% standard items -> 90/100 = 0.9

Using total probability formula:

$this->formula = new Formula();
$result = $this->formula->totalProbability([0.4, 0.8], [
    0.8,
    0.9
]);
echo $result; // 0.86

We've got the probability, that the any picked item will be standard.

Then using Bayes formula:

$result = $this->formula->bayesProbability(0.4, 0.8, 0.86);
echo $result; // 0.37

We've got a probability, that the selected standard item will be related to 1st party.

$result = $this->formula->bayesProbability(0.6, 0.9, 0.86);
echo $result; // 0.63

We've got a probability, that the selected standard item will be related to 2nd party.

Check: 0.37+0.63=1

Bernoulli distribution

Find the probability, that within 10 flips of a coin tails will result in 3 times.

Using combinatorial combinations function 10! / 7! * 3! = 120 and combining it with Bernoulli distribution formula Cmn * p^m * q^n-m - getting the result:

$result = $this->formula->independentProbability(10, 3, 0.5);
echo $result; // 0.1171875

We've got a probability, that withing 10 flips of a coin tails will result in 3 times.

The probability of the relative frequency deviation of the probability

total_probability's People

Contributors

arthurkushman avatar

Stargazers

 avatar

Watchers

 avatar  avatar

total_probability's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.