jueves, 14 de julio de 2016

Binomial distribution

Binomial distribution is a bernoulli distribution in an experiment which is repeated n times (usually to find the probability of x ocurrences in n experiments).

Probability Mass Function:



Median:

np

Mode:

(n+1)p

variance:

np(1-p)


Example:

In a game a player trhow the dice 10th times hoping to get the 6 numbers  three times in order to win a prize. Define the median, mode, variance and probability to win the game.

Median:

(10)*(1/6) = 1.67

Mode:

(10 + 1)*(1/6) = 1.83

Variance:

10*(1/6)*(5/6) = 1.389

Probability:

(10|3)*(1/6)^3*(5/6)^7 =  0.155

miércoles, 13 de julio de 2016

Counter of total words and without repeating words in a text, using JAVA

Just what the title says, this code counts the total of words in a text and count the words without repeating. For example:

My name is Perez Perez

total words: 5
total without repeating words: 4 (since Perez appear two times)

Hope you got it, now the code:

// don't forget to add the required libraries
public void countWords(String text1 ){

         // text1 is the text whose we want to get the count of words
        ArrayList<String> wordArray = new ArrayList<String>();
        //split the text in an array using spaces to get the words
        String[] words = text1.split(" ");
        //add the word to an ArrayList
        wordArray.addAll(Arrays.asList(words));
        //Create a HashSet
        HashSet hs = new HashSet();
        //next line add to the HashSet the words without repeating
        hs.addAll(wordArray);
        //clean the Array
        wordArray.clear();
        //add to the Array the words without repeating
        wordArray.addAll(hs);
        //print the output
       
        System.out.print("total words: "+words.length); 
        System.out.print("total without repeating words: "+wordArray.size()); 
}

martes, 12 de julio de 2016

Bernoulli distribution

Bernoulli distribution is the one where categorical atribution has two possible values {x1,x2}, the probability mass function is p1 if value is x1 and p2 if value is x2, where p1+p2=1. Median would be 1 if p1 probability is higher than p2, 0 if p2 probability is higher than p1, and 0,5 if both p1 and p2 probability are equal. Mode would be 1 if p1 probability is higher and p2, 0 if probability of p2 is higher than p1 or both p1 and p2 if they are equally likely. Variance  would be p*q.

Example: on a tv show a random guy have to take out from a bag a ball, there arre 8 red ball and two blue balls, he would  only win if he take a blue ball, he just have a single attempt. Which is the mode, the median and the variance in this case?.

blue probability = 0,8
red probability = 0,2


Mode = 1
Median = 1
Variance =0.8*0,2=  0,16