Skip to content

Instantly share code, notes, and snippets.

@joelthelion
Created January 29, 2016 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joelthelion/1525225e7abd806ff02d to your computer and use it in GitHub Desktop.
Save joelthelion/1525225e7abd806ff02d to your computer and use it in GitHub Desktop.
#!/bin/python3
""" Optimize redundant predictions on hypermind """
import numpy
from collections import namedtuple
from itertools import product
Proba = namedtuple("Proba", ["hollande", "sarkozy"])
possibilities = [Proba(h, s) for (h, s) in product(numpy.linspace(0, 1, 101),
numpy.linspace(0, 1, 101))]
HOLLANDE_ET_SARKOZY = 0.24
HOLLANDE_SEUL = 0.60
SARKOZY_SEUL = 0.02
AUCUN = 0.18
def metric(p):
""" Deviation from hypermind predictions """
return (p.hollande * p.sarkozy - HOLLANDE_ET_SARKOZY) ** 2 +\
(p.hollande * (1 - p.sarkozy) - HOLLANDE_SEUL) ** 2 +\
(p.sarkozy * (1 - p.hollande) - SARKOZY_SEUL) ** 2 +\
((1 - p.sarkozy) * (1 - p.hollande) - AUCUN) ** 2
possibilities.sort(key=metric, reverse=True)
for p in possibilities:
print("%s : %.5f" % (p, metric(p)))
print()
p = possibilities[-1]
print("Best: %s (%.5f)" % (p, metric(p)))
print("p.hollande*p.sarkozy ", p.hollande * p.sarkozy)
print("p.hollande*(1-p.sarkozy) ", p.hollande * (1 - p.sarkozy))
print("p.sarkozy*(1-p.hollande) ", p.sarkozy * (1 - p.hollande))
print("(1-p.sarkozy)*(1-p.hollande)", (1 - p.sarkozy) * (1 - p.hollande))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment