def simulate_number_of_words(nr_words):
    """
    Simulations with a varying number of responses to a RAT problem.
    The simulation is run for the maximal number of words and based on that the
    success rates for a smaller number of words are calculated.
    """

    performance = np.zeros((len(nr_words), 4))
    max_words = nr_words[-1]

    # load an existing file
    try:
        positions = np.load('nr_words_simulation.npz')['positions']
        print('Loading existing file...')
    except IOError:
        print('Running simulation!')
        positions,  _ = simulate_test(**{'nr_words': max_words})

    nr_items = float(len(positions))

    for i, nr_w in enumerate(nr_words):
        print('Testing words = %d' % nr_w)
        solutions = np.where(positions < nr_w, positions, -1)

        performance[i, :3] = get_difficulties(solutions)
        percent_correct = 100*len(np.where(solutions > -1)[0])/nr_items
        performance[i, 3] = percent_correct

    return performance
def simulate_threshold(thresholds, nr_words):
    """
    Simulations with different thresholds.
    """
    performance = np.zeros((len(thresholds), 4))

    for i, th in enumerate(thresholds):
        print('Threshold = %.2f' % th)

        param = {'theta': th,
                 'nr_words': nr_words
                 }

        positions,  _ = simulate_test(**param)
        nr_items = len(positions)

        performance[i, :3] = get_difficulties(positions)
        percent_correct = 100*len(np.where(positions > -1)[0])/nr_items
        performance[i, 3] = percent_correct

    return performance