Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def update_probability(prior, prob_true, prob_false=0.):
- """Update probability using Bayes' rule."""
- numerator = prob_true * prior
- denominator = numerator + prob_false * (1 - prior)
- probability = numerator / denominator
- return probability
- prior = 0.1
- list_posteriors = []
- threshold = 0.9
- #weather_home_cloudy
- prob_true_1 = 0.6
- prob_false_1 = 0.2
- sensor_cloudy = 'cloudy'
- try:
- if sensor_cloudy == 'cloudy':
- posterior = update_probability(prior, prob_true_1, prob_false_1)
- prior = posterior
- print('post_1: ', round(posterior,2), round(prior,2))
- except:
- prior = prior
- #weather_home_snowy
- prob_true_2 = 0.6
- prob_false_2 = 0.1
- sensor_snowy = 'not_snowy'
- try:
- if sensor_snowy == 'snowy':
- posterior = update_probability(prior, prob_true_2, prob_false_2)
- prior = posterior
- print('post_2: ', round(posterior,2), round(prior,2))
- except:
- prior = prior
- #weather_home_rainy
- prob_true_3 = 0.9
- prob_false_3 = 0.1
- sensor_rainy = 'not_rainy'
- try:
- if sensor_rainy == 'rainy':
- posterior = update_probability(prior, prob_true_3, prob_false_3)
- prior = posterior
- print('post_3: ', round(posterior,2), round(prior,2))
- except:
- prior = prior
- #sun.sun_above_horizon
- prob_true_4 = 0.5
- prob_false_4 = 0.5
- sensor_sun_state = 'below'
- try:
- if sensor_sun_state == 'above':
- posterior = update_probability(prior, prob_true_4, prob_false_4)
- prior = posterior
- print('post_4: ', round(posterior,2), round(prior,2))
- except:
- prior = prior
- #numeric_state_pressure
- prob_true_5 = 0.65
- prob_false_5 = 0.1
- sensor_pressure = 1032
- try:
- if sensor_pressure <= 1000:
- posterior = update_probability(prior, prob_true_5)
- prior = posterior
- print('post_5: ', round(posterior,2), round(prior,2))
- except:
- prior = prior
- #numeric_state_humidity
- prob_true_6 = 0.5
- prob_false_6 = 0.1
- sensor_humid = 75
- try:
- if sensor_humid >= 70:
- posterior = update_probability(prior, prob_true_6, prob_false_6)
- prior = posterior
- print('post_6: ', round(posterior,2), round(prior,2))
- except:
- prior = prior
- print('posterior: ', round(posterior,2), round(prior,2))
- if posterior >= threshold:
- binary_sensor = True
- print('Będzie deszcz')
- else:
- binary_sensor = False
- print('Nie będzie deszczu')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement