# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3 (sm)
#     language: python
#     name: stat18
# ---

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd


# %matplotlib inline

# # Opgave 1.4

# +
class Dice(object):
     
    def __init__():
        pass
    
    @staticmethod
    def outcome_space():
        
        return [i + 1 for i in range(6)]

  
# -

t1, t2, t3 = Dice.outcome_space(), Dice.outcome_space(), Dice.outcome_space() 

# +
outcomes = list()

for i in t1:
    for j in t2:
        for k in t2:
            outcomes.append(i+j+k)

# -

# ### Distribution of outcomes

bins = [i*0.5 + 3 for i in range(16*2)]
plt.hist(outcomes, bins=bins)


def number_of_tens(x):
    if x == 10:
        return 1
    else:
        return 0


gunstige_udfald = np.sum([number_of_tens(outcome) for outcome in outcomes ])
print('antal gunstige udfald er:',gunstige_udfald)


# # Opgave 1.24

# Vi laver en nem kodning: (1,1) = 11, (2,1) = 21 osv.

# +
def gen_set(t1,t2):
    return int(str(t1) + str(t2))

def read_set(s):
    t1, t2 = int(str(s)[0]),int(str(s)[1])
    return t1, t2


# -

A = set(['41','42','43','44','45','46'])
B = set(['11','21','31','41','51','61'])
C = set(['41','42','43','44','14','24','34'])
D = set(['14','23','32','41'])
F = set(['16','61','25','52','34','43'])


# +
def get_intersection(set1, set2):
    
    return set1.intersection(set2)

def elements_in_intersection(set1, set2):
    
    intersection = get_intersection(set1, set2)
    return len(intersection)

def get_intersection_probability(set1, set2):
    
    intersection = get_intersection(set1, set2)
    return len(intersection)/36

def get_probability(set1, set2):
    
    nr_elements1 = len(set1)
    nr_elements2 = len(set2)
    
    return nr_elements1*nr_elements2/(36*36)


# +
all_sets = [A, B, C, D, F]
set_names =  ['A', 'B', 'C', 'D', 'F']

results = {'set':set_names}
for i in range(len(all_sets)):
    results[set_names[i]] = [elements_in_intersection(all_sets[i],j) for j in all_sets]
    
# -

# puts everything to dataframe for printing
df = pd.DataFrame(results)

df

# Til Latex output:

print(df.to_latex(index=False))

# ### Calculating intersections probabilities

results = {'set':set_names}
for i in range(len(all_sets)):
    results[set_names[i]] = [get_intersection_probability(all_sets[i],j) for j in all_sets]

df = pd.DataFrame(results)
df.round(3)

# Til Latex output:

print(df.round(3).to_latex(index=False))

# ### Calculating P(A)P(B)

results = {'set':set_names}
for i in range(len(all_sets)):
    results[set_names[i]] = [get_probability(all_sets[i],j) for j in all_sets]

# puts everything to dataframe for printing
df = pd.DataFrame(results)
df.round(3)

# Til Latex output:

print(df.round(3).to_latex(index=False))


# # Opgave 1.9

def prob_func(x):
    
    return (52-x-16)/(52-x)


prob = 1
for i in range(13):
    #print(i, prob_func(i))
    prob = prob * prob_func(i)

prob



StarcoderdataJupyterScriptsDedupFiltered