Beispiel #1
0
def show_exercises(parameter_file):
    """Display a sigmoid for each exercise."""
    plt.figure(1)
    data = mirt_util.json_to_data(parameter_file)
    parameters = data['params']
    exercise_ind_dict = parameters.exercise_ind_dict

    def eval_conditional_probability(x, parameters, exercise_ind):
        """Evaluate the conditional probability of answering each question
        accurately for a student with ability x
        """
        return mirt_util.conditional_probability_correct(
            np.ones((parameters.num_abilities, 1)) * x, parameters,
            exercise_ind)

    abilities_to_plot = np.arange(-3, 3, .01)
    exercises, indices = exercise_ind_dict.keys(), exercise_ind_dict.values()
    exercise_plots = defaultdict(list)
    for ability in abilities_to_plot:
        conditional_probs = eval_conditional_probability(
            ability, parameters, exercise_ind_dict.values())
        for exercise in exercises:
            exercise_plots[exercise].append(
                conditional_probs[exercises.index(exercise)])
    for exercise in exercises:
        plt.plot(abilities_to_plot, exercise_plots[exercise], label=exercise)
    plt.xlabel('Student Ability')
    plt.ylabel('P(Answer Correctly)')
    plt.title('Two parameter IRT model')
    plt.legend(loc='best', prop={'size': 6})
    plt.show()
Beispiel #2
0
def show_exercises(parameter_file):
    """Display a sigmoid for each exercise."""
    plt.figure(1)
    data = mirt_util.json_to_data(parameter_file)
    parameters = data['params']
    exercise_ind_dict = parameters.exercise_ind_dict

    def eval_conditional_probability(x, parameters, exercise_ind):
        """Evaluate the conditional probability of answering each question
        accurately for a student with ability x
        """
        return mirt_util.conditional_probability_correct(
            np.ones((parameters.num_abilities, 1)) * x,
            parameters,
            exercise_ind)

    abilities_to_plot = np.arange(-3, 3, .01)
    exercises, indices = exercise_ind_dict.keys(), exercise_ind_dict.values()
    exercise_plots = defaultdict(list)
    for ability in abilities_to_plot:
        conditional_probs = eval_conditional_probability(
            ability,
            parameters,
            exercise_ind_dict.values())
        for exercise in exercises:
            exercise_plots[exercise].append(conditional_probs[
                exercises.index(exercise)])
    for exercise in exercises:
        plt.plot(abilities_to_plot, exercise_plots[exercise], label=exercise)
    plt.xlabel('Student Ability')
    plt.ylabel('P(Answer Correctly)')
    plt.title('Two parameter IRT model')
    plt.legend(loc='best', prop={'size': 6})
    plt.show()
Beispiel #3
0
def show_exercises(parameter_file):
    """Display a sigmoid for each exercise."""
    plt.figure(1)
    data = mirt_util.json_to_data(parameter_file)
    parameters = data['params']
    exercise_ind_dict = parameters.exercise_ind_dict

    def eval_conditional_probability(x, parameters, exercise_ind):
        """Evaluate the conditional probability of answering each question
        accurately for a student with ability x
        """
        return mirt_util.conditional_probability_correct(
            np.ones((parameters.num_abilities, 1)) * x,
            parameters,
            exercise_ind)

    abilities_to_plot = np.arange(-3, 3, .01)
    exercises, indices = exercise_ind_dict.keys(), exercise_ind_dict.values()
    exercise_plots = defaultdict(list)
    for ability in abilities_to_plot:
        conditional_probs = eval_conditional_probability(
            ability,
            parameters,
            exercise_ind_dict.values())
        for exercise in exercises:
            exercise_plots[exercise].append(conditional_probs[
                exercises.index(exercise)])

    # to make colors/style different for each curve
    # all_matplotlib_colors = []
    # for c_name, c_hex in matplotlib.colors.cnames.iteritems():
    # all_matplotlib_colors.append(c_name)
    cmap = plt.get_cmap('jet')
    colors = cmap(np.linspace(0, 1, len(exercises)))
    line_styles = ['-', '--', '-.', ':', ]
    # plt.style.use('ggplot')
    for idx, exercise in enumerate(exercises):
        plt.plot(abilities_to_plot, exercise_plots[exercise],
                 # color=all_matplotlib_colors[idx],
                 color=colors[idx],
                 linestyle=line_styles[idx % len(line_styles)],
                 label=exercise)
    plt.xlabel('Student Ability')
    plt.ylabel('P(Answer Correctly)')
    plt.title('Two parameter IRT model')
    plt.legend(loc='best', prop={'size': 6})
    plt.show()
Beispiel #4
0
def print_report(parameter_file):
    """Print interpretable results given a json file"""
    data = mirt_util.json_to_data(parameter_file)
    parameters = data['params']
    print 'Generating Report for %s' % parameter_file
    print "%50s\t%s\t\t" % ('Exercise', 'Bias'),
    for i in range(parameters.num_abilities):
        print 'Dim. %s\t' % (i + 1),
    print
    exercises = parameters.exercise_ind_dict.keys()
    exercises_to_parameters = [(ex, parameters.get_params_for_exercise(ex))
                               for ex in exercises]
    # Sort by the difficulty bias
    exercises_to_parameters.sort(key=lambda x: x[-1][-1])
    for ex, param in exercises_to_parameters:
        print "%50s\t%.4f\t" % (ex, param[-1]),
        for p in param[:-1]:
            print "\t%.4f\t" % p,
        print
Beispiel #5
0
def print_report(parameter_file):
    """Print interpretable results given a json file"""
    data = mirt_util.json_to_data(parameter_file)
    parameters = data['params']
    print 'Generating Report for %s' % parameter_file
    print "%50s\t%s\t\t" % ('Exercise', 'Bias'),
    for i in range(parameters.num_abilities):
        print 'Dim. %s\t' % (i + 1),
    print
    exercises = parameters.exercise_ind_dict.keys()
    exercises_to_parameters = [(ex, parameters.get_params_for_exercise(ex))
                               for ex in exercises]
    # Sort by the difficulty bias
    exercises_to_parameters.sort(key=lambda x: x[-1][-1])
    for ex, param in exercises_to_parameters:
        print "%50s\t%.4f\t" % (ex, param[-1]),
        for p in param[:-1]:
            print "\t%.4f\t" % p,
        print