Skip to content

Instantly share code, notes, and snippets.

@Colk-tech
Created October 8, 2020 06:53
Show Gist options
  • Save Colk-tech/a7b830ec5080cbe85a34c96f54bd282f to your computer and use it in GitHub Desktop.
Save Colk-tech/a7b830ec5080cbe85a34c96f54bd282f to your computer and use it in GitHub Desktop.
授業で即興で書いた平均情報量を求めるやつです
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