Created
October 8, 2020 06:53
-
-
Save Colk-tech/a7b830ec5080cbe85a34c96f54bd282f to your computer and use it in GitHub Desktop.
授業で即興で書いた平均情報量を求めるやつです
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
def amount_of_information(expectation_value: float, probability: float) -> float: | |
retval = expectation_value * math.log2(1.0/probability) | |
return retval | |
events = {"sunny": 0.40, "cloudy": 0.30, "rainy": 0.30} | |
print(sum([amount_of_information(event, event) for event in events.values()])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment