PREP 2014 Question Authoring - Archived

Can WEIGHTED_ANS be used with essay_cmp?

Can WEIGHTED_ANS be used with essay_cmp?

by Murphy Waggoner -
Number of replies: 3
I have a question where students do some calculations, make a conjecture on the pattern, and then test their conjecture on a few more problems.

For the conjecture I give the students an essay blank.

I want to give more weight to the conjecture and the subsequent questions thank to the first simple calculations.

But essay_cmp() is a different type of answer checker than $num->cmp (I know they are different but I don't remember the essence of the difference.)

When I try to use WEIGHTED_ANS, no matter what weight I give the essay question, it assumes a weight of 1. The weights in the problem are nonsense right now (not the weights I eventually want, but was using for testing) I got all the calculations correct and my score should be (40 + 10 x 1)/(40 + 10 x 1 + 86) = 37% but it ended up being 98% which is (40 + 10 x 1)/(40 + 10 x 1 + 1).

A related question: can I capture students' answers? I was thinking if I captured the answer, somehow passed it essay_cmp like we pass the correct answers to cmp - but then what would be the point of that? Just wondering.

(You said not to be afraid to ask questions - I'm taking you up on that. I have learned a lot just by reading the questions/answers in the other forums on the Moodle site. Thanks again for all the help. I think I would have found my work much more daunting if I felt I was alone doing this.)

DOCUMENT(); # This should be the first executable line in the problem.

loadMacros(
"PG.pl",
"PGbasicmacros.pl",
"MathObjects.pl",
"PGanswermacros.pl",
"PGauxiliaryFunctions.pl",
"PGcomplexmacros.pl",
"PGessaymacros.pl",
"weightedGrader.pl", # Don't forget to install this later
"unionLists.pl"
);

TEXT(beginproblem());

######################################
# Setup

Context("Complex");

# create random numbers
$a[0] = non_zero_random( 11, 70, 1 );
$a[1] = non_zero_random( $a[0] + 1, $a[0] + 49, 4 );
$a[2] = non_zero_random( $a[1] + 1, $a[1] + 49, 4);
$a[3] = non_zero_random( $a[2] + 1, $a[2] + 49, 4);

# Calculate the answers: first with exponents 0 through 9
for ( $n = 0; $n <= 9; $n++ )
{
$answer[$n] = Complex("i^$n");
}

# More answers: now with 4 random integers
for ( $n = 0; $n <= 3; $n++ )
{
$answer[$n + 10] = Complex("i^($a[$n])");
}

# Convert the answer to LimitedComplex context
# so that the students have to simplify their answer.
# .... so they can't enter things like i^3

Context("LimitedComplex");
for ( $n = 0; $n <= 13; $n++ )
{
$simple_ans[$n] = Compute($answer[$n]->string);
}


BEGIN_TEXT
Part 1 of 3: Calculate the following:$PAR
(1a) \(i^0\ =\) \{ans_rule(5)\} $PAR
(1b) \(i^1 =\) \{ans_rule(5)\} $PAR
(1c) \(i^2\ =\) \{ans_rule(5)\} $PAR
(1d) \(i^3\ =\) \{ans_rule(5)\} $PAR
(1e) \(i^4\ =\) \{ans_rule(5)\} $PAR
(1f) \(i^5\ =\) \{ans_rule(5)\} $PAR
(1g) \(i^6\ =\) \{ans_rule(5)\} $PAR
(1h) \(i^7\ =\) \{ans_rule(5)\} $PAR
(1i) \(i^8\ =\) \{ans_rule(5)\} $PAR
(1j) \(i^9\ =\) \{ans_rule(5)\} $PAR

$PAR
$BR
Part 2 of 3: Describe the pattern above in a way that will help you calculate \(i^n\) for any nonnegative integer \(n\).
$PAR
Try to be as mathematical as possible.
$PAR
This part will be read and graded later. You will not get immediate feedback on this answer.
$PAR
\{ essay_box(8,60) \}

$PAR
$BR
Part 3 of 3: To test your hypothesis from Part 2, use your pattern to calculate the following. Revise your answer to Part 2 if needed based on these results.$PAR

(3a) \(i^{$a[0]}\ =\) \{ans_rule(5)\} $PAR
(3b) \(i^{$a[1]}\ =\) \{ans_rule(5)\} $PAR
(3c) \(i^{$a[2]} \ =\) \{ans_rule(5)\} $PAR
(3d) \(i^{$a[3]}\ =\) \{ans_rule(5)\} $PAR


END_TEXT

#####################################################
# End Game

# Must be done so weighted grading can be done - see macro above
install_weighted_grader();

# Make the error message something easier for the students to understand
# especially since they haven't seen e^(ai) yet

Context()->{error}{msg}
{"Exponentials can only be of the form 'e^(ai)' in this context"}
= "You must enter a number in the form a + bi";
Context()->{error}{msg}
{"The constant 'i' may appear only once in your formula"}
= "You must enter a number in the form a + bi";


# Check answers - using weights
#

# Part 1 answers
for ( $n = 0; $n <= 9; $n++ )
{
WEIGHTED_ANS( ($simple_ans[$n])->cmp, 1);
}

# Part 2 answers
WEIGHTED_ANS( essay_cmp(), 86 ); # Stores the essay box input for later grading

# Part 3 answers
for ( $n = 10; $n <= 13; $n++ )
{
WEIGHTED_ANS( ($simple_ans[$n])->cmp, 10);
}


$showPartialCorrectAnswers = 1;

ENDDOCUMENT(); # This should be the last executable line in the problem.


In reply to Murphy Waggoner

Re: Can WEIGHTED_ANS be used with essay_cmp?

by Davide Cervone -
I've been out of the country since right after the course ended, and only just returned this week. I haven't gotten caught up with the questions yet.

In any case, it does appear that essay_cmp doesn't work properly with the weighted grader. The reason is that answer checkers contain an object that gets used during the grading process, and WEIGHTED_ANS() inserts the weight into that object so the grader can use it, but essay_cmp() replaces that object with a new one, and so the weight is lost.

You can get around that by using

    WEIGHTED_ANS(sub {essay_cmp()->evaluate(@_)}, 86);
instead of
    WEIGHTED_ANS(essay_cmp(), 86);
This provides an answer checker that calls the essay checker internally and returns its value. Since this is just a perl function rather than an AnswerChecker object, the WEIGHTED_ANS() treats it differently and supplies its own AnswerChecker that holds onto the weight properly.

The essay_cmp checker probably could be modified to retain the weights, but this should work for now.

In reply to Davide Cervone

Re: Can WEIGHTED_ANS be used with essay_cmp?

by Murphy Waggoner -
Works great with the work around. This is a type of question I would like to ask on a semi-regular basis and so it is great to have it working.

Thanks! (and I hope you had a good trip abroad)