def approach2():

    W_table = {'sunny': 1 / 2, 'rainy': 1 / 6, 'snowy': 1 / 3}
    I_table = {0: 1 / 2, 1: 1 / 2}
    W = comp_prob_inference.sample_from_finite_probability_space(W_table)
    I = comp_prob_inference.sample_from_finite_probability_space(I_table)
    print("Approach 2: ", W, I)
Ejemplo n.º 2
0
def approach_2():
    print("Approach 2")
    W_table = {'sunny': 1 / 2, 'rainy': 1 / 6, 'snowy': 1 / 3}
    I_table = {0: 1 / 2, 1: 1 / 2}
    W = comp_prob_inference.sample_from_finite_probability_space(W_table)
    I = comp_prob_inference.sample_from_finite_probability_space(I_table)
    print("Random variable W = " + W)
    print("Random variable I = " + str(I))
def run_experiment():
    random_outcome = comp_prob_inference.sample_from_finite_probability_space(prob_space)
    W = random_outcome
    if random_outcome == 'sunny':
        I = 1
    else:
        I = 0
    print(W, I)
def approach1():

    prob_space = {'sunny': 1 / 2, 'rainy': 1 / 6, 'snowy': 1 / 3}
    W_mapping = {'sunny': 'sunny', 'rainy': 'rainy', 'snowy': 'snowy'}
    I_mapping = {'sunny': 1, 'rainy': 0, 'snowy': 0}
    random_outcome = comp_prob_inference.sample_from_finite_probability_space(
        prob_space)
    W = W_mapping[random_outcome]
    I = I_mapping[random_outcome]
    print("Approach 1: ", W, I)
Ejemplo n.º 5
0
def first_look():
    prob_space = {'sunny': 1 / 2, 'rainy': 1 / 6, 'snowy': 1 / 3}
    random_outcome = comp_prob_inference.sample_from_finite_probability_space(
        prob_space)
    W = random_outcome
    if random_outcome == 'sunny':
        I = 1
    else:
        I = 0
    print("Random variable W = " + W)
    print("Random variable I = " + str(I))
Ejemplo n.º 6
0
def approach_1():
    print("Approach 1")
    prob_space = {'sunny': 1 / 2, 'rainy': 1 / 6, 'snowy': 1 / 3}
    W_mapping = {'sunny': 'sunny', 'rainy': 'rainy', 'snowy': 'snowy'}
    I_mapping = {'sunny': 1, 'rainy': 0, 'snowy': 0}
    random_outcome = comp_prob_inference.sample_from_finite_probability_space(
        prob_space)
    W = W_mapping[random_outcome]
    I = I_mapping[random_outcome]

    print("Random variable W = " + W)
    print("Random variable I = " + str(I))
Ejemplo n.º 7
0
# -*- coding: utf-8 -*-
"""
Spyder Editor

This is a temporary script file.
"""
import numpy as np
import matplotlib.pyplot as plt
import comp_prob_inference

prob_space = {'sunny': 1 / 2, 'rainy': 1 / 6, 'snowy': 1 / 3}
random_outcome = comp_prob_inference.sample_from_finite_probability_space(
    prob_space)

# Aproach 1
W_mapping = {'sunny': 'sunny', 'rainy': 'rainy', 'snowy': 'snowy'}
I_mapping = {'sunny': 1, 'rainy': 0, 'snowy': 0}

W1 = W_mapping[random_outcome]
I1 = I_mapping[random_outcome]

# Approach 2
W_table = {'sunny': 1 / 2, 'rainy': 1 / 6, 'snowy': 1 / 3}
I_table = {0: 1 / 2, 1: 1 / 2}

W2 = comp_prob_inference.sample_from_finite_probability_space(W_table)
I2 = comp_prob_inference.sample_from_finite_probability_space(I_table)

print("W1 :", W1, "I1: ", I1)
print("W2 :", W2, "I2: ", I2)
Ejemplo n.º 8
0
cpi.plot_discrete_histogram(flips)
pdf_pages.savefig()

cpi.plot_discrete_histogram(flips, frequency=True)
pdf_pages.savefig()

n = 100000
heads_so_far = 0
fraction_of_heads = []
for i in range(n):
    if cpi.flip_fair_coin() == 'heads':
        heads_so_far += 1
    fraction_of_heads.append(heads_so_far / (i + 1))

plt.figure(figsize=(8, 4))
plt.plot(range(1, n + 1), fraction_of_heads)
plt.xlabel('Number of flips')
plt.ylabel('Fraction of heads')

pdf_pages.savefig()
pdf_pages.close()

prob_space = {'sunny': 1 / 2, 'rainy': 1 / 6, 'snowy': 1 / 3}
random_outcome = cpi.sample_from_finite_probability_space(prob_space)
W = random_outcome
if random_outcome == 'sunny':
    I = 1
else:
    I = 0
print(I)
Ejemplo n.º 9
0
import comp_prob_inference

# PROBABILITY SPACES AND EVENTS
#def prob_of_event(event, prob_space):
#	total = 0
#	for outcome in event:
#		total += prob_space[outcome]
#	return total

#RANDOM VARIABLES EXERCISE

prob_space = {'sunny': 1. / 2, 'rainy': 1. / 6, 'snowy': 1. / 3}
random_outcome = comp_prob_inference.sample_from_finite_probability_space(
    prob_space)
W = random_outcome
if random_outcome == 'sunny':
    I = 1
else:
    I = 0
Ejemplo n.º 10
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import comp_prob_inference as cpi 
"""
Probability mappings
"""

prob_space = {'sunny': 1/2, 'rainy': 1/6, 'snowy': 1/3}

W_mapping = {'sunny': 'sunny', 'rainy': 'rainy', 'snowy': 'snowy'}
I_mapping = {'sunny': 1, 'rainy': 0, 'snowy': 0}

random_outcome = cpi.sample_from_finite_probability_space(prob_space)
W = W_mapping[random_outcome]
print(W)
I = I_mapping[random_outcome]
print(I)

W_table = {'sunny': 1/2, 'rainy': 1/6, 'snowy': 1/3}
I_table = {0: 1/2, 1: 1/2}

W = cpi.sample_from_finite_probability_space(W_table)
print(W)
I = cpi.sample_from_finite_probability_space(I_table)
print(I)
Ejemplo n.º 11
0
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 15 18:31:01 2018

@author: pia-hp
"""
import numpy as np
import comp_prob_inference
p_X = {i: 1/6 for i in range(1, 7)}
num_samples = 10000
print(np.mean([comp_prob_inference.sample_from_finite_probability_space(p_X) 
for n in range(num_samples)])):