<commit_before>from disclosuregame.Games.game import *
from disclosuregame.Games.referral import *
from disclosuregame.Games.recognition import *
from disclosuregame.Games.carrying import *
from disclosuregame.Games.sharing import *

from disclosuregame.Agents.cpt import *
from disclosuregame.Agents.recognition import *
from disclosuregame.Agents.heuristic import *
from disclosuregame.Agents.payoff import *
from disclosuregame.Agents.rl import *

from disclosuregame.Measures import *
from disclosuregame.Measures.abstract import *

from disclosuregame.experiments import *

from disclosuregame.Util import random_expectations


from multiprocessing import Pool, Queue
import multiprocessing
import itertools
from collections import OrderedDict
import argparse
from os.path import expanduser
import os.path

import cPickle
import gzip, csv


def scale_weights(weights, top):
    scaling = top / float(sum(weights))
    for i in range(len(weights)):
        weights[i] *= scaling
    return weights


def make_random_patients(signaller, num=1000, weights=[1/3., 1/3., 1/3.]):
    women = []
    player_type = 0
    for weight in weights:
        for i in range(weight*100):
            women.append(signaller(player_type=player_type))
        player_type += 1
    return women


def make_random_weights(num=1000):
    weights = []
    for i in range(num):
        weights.append((random_expectations(), [random_expectations(breadth=2) for x in range(3)]))
    return weights


def inject_type_belief(weights, num):
    """
    Return a function that will modify the type distribution priors of num 
    random women to be those in weights and restarts faith.
    """
    def f(women):
        target = random.sample(women, num)
        signals = [0, 1, 2]
        for agent in target:
            agent.response_belief = dict([(signal, dict([(response, []) for response in [0, 1]])) for signal in signals])
            agent.type_distribution = dict([(signal, []) for signal in signals])
            agent.type_weights = weights
            agent.update_beliefs(None, None, None)
    return f


def make_random_midwives(responder, num=100, weights=[80/100., 15/100., 5/100.]):
    midwives = []
    for i in range(num):
        midwives.append(responder(player_type=weighted_choice(zip([0, 1, 2], weights))))
    return midwives

def proportions(num):
    """
    Generate some number of combinations of 3
    random numbers that sum to 1.
    """
    proportions = []
    for i in range(num):
        initial = 100
        result = []
        for i in range(2):
            n = random.randint(0, initial)
            initial -= n
            result.append(n)
        result.append(initial)

        proportions.append([x/100. for x in result])
    return proportions

def proportions_experiment():
    """
    Sample space for type proportions.
    """
    mw = proportions(10000)
    w = proportions(10000)
    kwargs = []
    for i in range(10000):
        kwarg = {'women_weights':w[i], 'mw_weights':mw[i]}
        kwargs.append(kwarg)
    return kwargs

def naive_partition(resolution=0.1):
    """
    Generator that yields combinations of three numbers that sum to
    one.
    """
    parts = []
    for x in itertools.product(xrange(0, 101, int(100 * resolution)), repeat=3):
        if sum(x) == 100:
            yield map(lambda y: y / 100., x)
            #parts.append(map(lambda y: y / 100., x))
    #return parts

def qualitative_trends():
    args = {'game_args': {'mw_share_prob':0.,
            'women_share_prob':0.,
            'type_weights':[[10., 1., 1.], [1., 10., 1.], [1., 1., 10.]],
            'baby_payoff':10, 'referral_cost':9}, 
            'signaller_args':{'share_weight':0.},
            'responder_args':{'share_weight':0.},
            'mw_weights':[0.85, 0.1, 0.05, 
            'women_weights':[1/3., 1/3., 1/3.]}
    return [args]

def naive_proportions(key='women_weights', resolution=0.1, chunksize=None):
    """
    Produces a list of lists of kwargs for type proportions split into
    chunks.
    """
    w = naive_partition(resolution)<commit_msg>Oh good grief: [<commit_after>from disclosuregame.Games.game import *
from disclosuregame.Games.referral import *
from disclosuregame.Games.recognition import *
from disclosuregame.Games.carrying import *
from disclosuregame.Games.sharing import *

from disclosuregame.Agents.cpt import *
from disclosuregame.Agents.recognition import *
from disclosuregame.Agents.heuristic import *
from disclosuregame.Agents.payoff import *
from disclosuregame.Agents.rl import *

from disclosuregame.Measures import *
from disclosuregame.Measures.abstract import *

from disclosuregame.experiments import *

from disclosuregame.Util import random_expectations


from multiprocessing import Pool, Queue
import multiprocessing
import itertools
from collections import OrderedDict
import argparse
from os.path import expanduser
import os.path

import cPickle
import gzip, csv


def scale_weights(weights, top):
    scaling = top / float(sum(weights))
    for i in range(len(weights)):
        weights[i] *= scaling
    return weights


def make_random_patients(signaller, num=1000, weights=[1/3., 1/3., 1/3.]):
    women = []
    player_type = 0
    for weight in weights:
        for i in range(weight*100):
            women.append(signaller(player_type=player_type))
        player_type += 1
    return women


def make_random_weights(num=1000):
    weights = []
    for i in range(num):
        weights.append((random_expectations(), [random_expectations(breadth=2) for x in range(3)]))
    return weights


def inject_type_belief(weights, num):
    """
    Return a function that will modify the type distribution priors of num 
    random women to be those in weights and restarts faith.
    """
    def f(women):
        target = random.sample(women, num)
        signals = [0, 1, 2]
        for agent in target:
            agent.response_belief = dict([(signal, dict([(response, []) for response in [0, 1]])) for signal in signals])
            agent.type_distribution = dict([(signal, []) for signal in signals])
            agent.type_weights = weights
            agent.update_beliefs(None, None, None)
    return f


def make_random_midwives(responder, num=100, weights=[80/100., 15/100., 5/100.]):
    midwives = []
    for i in range(num):
        midwives.append(responder(player_type=weighted_choice(zip([0, 1, 2], weights))))
    return midwives

def proportions(num):
    """
    Generate some number of combinations of 3
    random numbers that sum to 1.
    """
    proportions = []
    for i in range(num):
        initial = 100
        result = []
        for i in range(2):
            n = random.randint(0, initial)
            initial -= n
            result.append(n)
        result.append(initial)

        proportions.append([x/100. for x in result])
    return proportions

def proportions_experiment():
    """
    Sample space for type proportions.
    """
    mw = proportions(10000)
    w = proportions(10000)
    kwargs = []
    for i in range(10000):
        kwarg = {'women_weights':w[i], 'mw_weights':mw[i]}
        kwargs.append(kwarg)
    return kwargs

def naive_partition(resolution=0.1):
    """
    Generator that yields combinations of three numbers that sum to
    one.
    """
    parts = []
    for x in itertools.product(xrange(0, 101, int(100 * resolution)), repeat=3):
        if sum(x) == 100:
            yield map(lambda y: y / 100., x)
            #parts.append(map(lambda y: y / 100., x))
    #return parts

def qualitative_trends():
    args = {'game_args': {'mw_share_prob':0.,
            'women_share_prob':0.,
            'type_weights':[[10., 1., 1.], [1., 10., 1.], [1., 1., 10.]],
            'baby_payoff':10, 'referral_cost':9}, 
            'signaller_args':{'share_weight':0.},
            'responder_args':{'share_weight':0.},
            'mw_weights':[0.85, 0.1, 0.05], 
            'women_weights':[1/3., 1/3., 1/3.]}
    return [args]

def naive_proportions(key='women_weights', resolution=0.1, chunksize=None):
    """
    Produces a list of lists of kwargs for type proportions split into
    chunks.
    """
    w = naive_partition(resolution)
{'fraction_non_alphanumeric': 0.1177116369846304, 'fraction_numerical': 0.030495242742132226, 'mean_word_length': 2.9042857142857144, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1336191', 'n_tokens_mistral': 2721, 'n_tokens_neox': 2460, 'n_words': 696}