Difference between revisions of "WeightedGrader"

From WeBWorK_wiki
Jump to navigation Jump to search
m
(added historical tag and gave updated problem link)
 
(39 intermediate revisions by 2 users not shown)
Line 1: Line 1:
  +
{{historical}}
  +
  +
<p style="font-size: 120%;font-weight:bold">This problem has been replaced with [https://openwebwork.github.io/pg-docs/sample-problems/problem-techniques/WeightedGrader.html a newer version of this problem]</p>
 
<h2>Weighted Graders</h2>
 
<h2>Weighted Graders</h2>
  +
  +
<p>
  +
If a question has n answer blanks, the default grader, which is the average problem grader (avg_problem_grader), will use 1/n as the weight for each answer. We describe several different ways to weight answers differently.
  +
<ul type="square">
  +
<li>The standard problem grader assigns full credit if all answers are correct, and zero credit otherwise. This all-or-nothing grader should always be used for matching, multiple choice, and true / false questions, otherwise students will be able to deduce how many answers are correct by the partial credit reported by webwork.</li>
  +
<li>The full-partial grader gives full credit if the last answer is correct, no matter what the other answers are, and partial credit (like the average problem grader) otherwise.
  +
<li>The weighted grader allows you to assign a weight to each answer blank in a problem.</li>
  +
<li>The weighted grader with the credit answer option allows you to specify one answer blank to be the final answer which, if answered correctly, will provide full credit for all other answer blanks in the problem.</li>
  +
<li>The incremental weighted grader, which awards a certain amount of credit for answering a certain number of parts correctly, is described in Example 1 (answer evaluation section) on the page [http://webwork.maa.org/wiki/PopUpListsLong PopUpListsLong]
  +
</ul>
  +
</p>
  +
  +
   
 
<p style="background-color:#eeeeee;border:black solid 1px;padding:3px;">
 
<p style="background-color:#eeeeee;border:black solid 1px;padding:3px;">
<em>This code shows how to assign different weights (percentages) to each answer in a problem.
 
  +
<em><b>Standard Problem Grader:</b> give full credit if all answers are correct and zero credit otherwise.
 
</em>
 
</em>
 
</p>
 
</p>
Line 9: Line 25:
 
[[IndexOfProblemTechniques|Problem Techniques Index]]
 
[[IndexOfProblemTechniques|Problem Techniques Index]]
 
</p>
 
</p>
  +
  +
<table cellspacing="0" cellpadding="2" border="0">
  +
<tr valign="top">
  +
<th> PG problem file </th>
  +
<th> Explanation </th>
  +
</tr>
  +
<tr valign="top">
  +
<td style="background-color:#ffdddd;border:black 1px dashed;">
  +
<pre>
  +
#######################
  +
# Initialization
  +
loadMacros("PGstandard.pl");
  +
  +
# Usual setup and main text go here
  +
  +
#######################
  +
# Answer evaluation
  +
  +
install_problem_grader(~~&std_problem_grader);
  +
  +
$showPartialCorrectAnswers = 0;
  +
  +
ANS($a->cmp());
  +
ANS($b->cmp());
  +
ANS($c->cmp());
  +
</pre>
  +
<td style="background-color:#ffcccc;padding:7px;">
  +
<p>
  +
<b>Initialization:</b>
  +
Be sure to load <code>PGstandard.pl</code>, which automatically loads <code>PGanswermacros.pl</code> which has the standard problem grader.
  +
</p>
  +
<p>
  +
<b>Answer Evaluation:</b> We use
  +
<code>install_problem_grader(~~&std_problem_grader);</code> to give full
  +
credit only if all answers are correct, and zero credit otherwise. We should
  +
probably also hide feedback on whether answers are partially correct or
  +
not by setting <code>$showPartialCorrectAnswers=0;</code>.
  +
The standard problem grader is recommended for true / false and multiple choice
  +
questions to prevent students from guessing and receiving either feedback or
  +
partial credit that tells them whether their guess was correct.
  +
</p>
  +
</td>
  +
</tr>
  +
</table>
  +
  +
  +
  +
  +
  +
<p style="background-color:#eeeeee;border:black solid 1px;padding:3px;">
  +
<em><b>Full-Partial Grader:</b> give full credit if the last answer is correct, no matter what the other answers are, and partial credit (like the average problem grader) otherwise.
  +
</em>
  +
</p>
  +
  +
<p style="text-align:center;">
  +
[[IndexOfProblemTechniques|Problem Techniques Index]]
  +
</p>
  +
  +
<table cellspacing="0" cellpadding="2" border="0">
  +
<tr valign="top">
  +
<th> PG problem file </th>
  +
<th> Explanation </th>
  +
</tr>
  +
<tr valign="top">
  +
<td style="background-color:#ffdddd;border:black 1px dashed;">
  +
<pre>
  +
#######################
  +
# Initialization
  +
loadMacros(
  +
"PGstandard.pl",
  +
"PGgraders.pl",
  +
);
  +
  +
# Usual setup and main text go here
  +
  +
#######################
  +
# Answer evaluation
  +
  +
install_problem_grader(~~&full_partial_grader);
  +
  +
$showPartialCorrectAnswers = 1;
  +
  +
ANS($a->cmp());
  +
ANS($b->cmp());
  +
ANS($c->cmp());
  +
</pre>
  +
<td style="background-color:#ffcccc;padding:7px;">
  +
<p>
  +
<b>Initialization:</b>
  +
Be sure to load <code>PGgraders.pl</code>
  +
</p>
  +
<p>
  +
<b>Answer Evaluation:</b>
  +
Use <code>install_problem_grader(~~&full_partial_grader);</code> to install this grader. Everything else is as usual. If the student answers the third question correctly, they will receive full credit no matter what their other answers are.
  +
</p>
  +
</td>
  +
</tr>
  +
</table>
  +
  +
  +
  +
  +
  +
  +
<p style="background-color:#eeeeee;border:black solid 1px;padding:3px;">
  +
<em><b>Weighted Grader:</b> assign different weights (percentages) to each answer in a problem.
  +
</em>
  +
</p>
  +
 
<table cellspacing="0" cellpadding="2" border="0">
 
<table cellspacing="0" cellpadding="2" border="0">
 
<tr valign="top">
 
<tr valign="top">
Line 21: Line 146:
 
loadMacros(
 
loadMacros(
 
"PGstandard.pl",
 
"PGstandard.pl",
"PGcourse.pl",
 
 
"MathObjects.pl",
 
"MathObjects.pl",
 
"weightedGrader.pl",
 
"weightedGrader.pl",
  +
"PGcourse.pl",
 
);
 
);
   
 
install_weighted_grader();
 
install_weighted_grader();
   
TEXT(beginproblem);
+
TEXT(beginproblem());
 
</pre>
 
</pre>
 
</td>
 
</td>
 
<td style="background-color:#ccffcc;padding:7px;">
 
<td style="background-color:#ccffcc;padding:7px;">
 
<p>
 
<p>
Initialization: We need to include the <code>weightedGrader.pl</code> macro file and the very first thing we do should be to install it using <code>install_weighted_grader();</code>.
 
  +
<b>Initialization:</b>
  +
We need to include the <code>weightedGrader.pl</code> macro file and immediately install it using <code>install_weighted_grader();</code>.
 
</p>
 
</p>
 
</td>
 
</td>
Line 53: Line 179:
 
<td style="background-color:#ffffcc;padding:7px;">
 
<td style="background-color:#ffffcc;padding:7px;">
 
<p>
 
<p>
Set-up: To show how this works with MathObjects, we add some
 
  +
<b>Setup:</b>
  +
To show how this works with MathObjects, we add some
 
variables and strings to the context.
 
variables and strings to the context.
 
</p>
 
</p>
Line 63: Line 190:
 
Context()->texStrings;
 
Context()->texStrings;
 
BEGIN_TEXT
 
BEGIN_TEXT
 
 
Enter \( \pi $r^2 \): \{ans_rule(10)\}
 
Enter \( \pi $r^2 \): \{ans_rule(10)\}
 
Enter \( $answer2 \): \{ans_rule(10)\}
 
Enter \( $answer2 \): \{ans_rule(10)\}
 
Enter A: \{ans_rule(10)\}
 
Enter A: \{ans_rule(10)\}
 
 
END_TEXT
 
END_TEXT
 
Context()->normalStrings;
 
Context()->normalStrings;
Line 73: Line 198:
 
<td style="background-color:#ffcccc;padding:7px;">
 
<td style="background-color:#ffcccc;padding:7px;">
 
<p>
 
<p>
Main Text: Answer boxes are as usual.
 
  +
<b>Main Text:</b>
  +
Answer boxes are as usual.
 
</p>
 
</p>
 
</td>
 
</td>
Line 84: Line 210:
 
WEIGHTED_ANS( ($answer1)->cmp(), 40 );
 
WEIGHTED_ANS( ($answer1)->cmp(), 40 );
 
WEIGHTED_ANS( ($answer2)->cmp(), 40 );
 
WEIGHTED_ANS( ($answer2)->cmp(), 40 );
WEIGHTED_ANS( ($answer2)->cmp(), 20 );
+
WEIGHTED_ANS( ($answer3)->cmp(), 20 );
   
 
ENDDOCUMENT();
 
ENDDOCUMENT();
Line 90: Line 216:
 
<td style="background-color:#eeccff;padding:7px;">
 
<td style="background-color:#eeccff;padding:7px;">
 
<p>
 
<p>
Answer Evaluation: Use <code>WEIGHTED_ANS( evaluator, weight );</code> instead of <code>ANS( evaluator );</code>.
 
  +
<b>Answer Evaluation:</b>
  +
Use <code>WEIGHTED_ANS( evaluator, weight );</code> instead of <code>ANS( evaluator );</code>.
 
The code given assigns 40% to each of the first two answers, and 20% to the last answer.
 
The code given assigns 40% to each of the first two answers, and 20% to the last answer.
 
The weights should be positive integers that sum to 100.
 
The weights should be positive integers that sum to 100.
Line 97: Line 224:
 
</tr>
 
</tr>
 
</table>
 
</table>
  +
  +
  +
  +
  +
  +
  +
  +
  +
  +
  +
  +
  +
<p style="background-color:#eeeeee;border:black solid 1px;padding:3px;">
  +
<em><b>Weighted Grader with Credit Answer Option:</b> assign different weights (percentages) to each answer in a problem, and provide one answer blank that, if correct, will supersede all other answer blanks and award full credit.
  +
</em>
  +
</p>
  +
  +
<table cellspacing="0" cellpadding="2" border="0">
  +
<tr valign="top">
  +
<th> PG problem file </th>
  +
<th> Explanation </th>
  +
</tr>
  +
<tr valign="top">
  +
<td style="background-color:#ddffdd;border:black 1px dashed;">
  +
<pre>
  +
DOCUMENT();
  +
  +
loadMacros(
  +
"PGchoicemacros.pl",
  +
"PGanswermacros.pl",
  +
"PGauxiliaryFunctions.pl",
  +
"weightedGrader.pl"
  +
);
  +
  +
install_weighted_grader();
  +
$showPartialCorrectAnswers = 1;
  +
  +
TEXT(beginproblem());
  +
</pre>
  +
</td>
  +
<td style="background-color:#ccffcc;padding:7px;">
  +
<p>
  +
<b>Initialization:</b>
  +
We need to include the <code>weightedGrader.pl</code> macro file and immediately install it using <code>install_weighted_grader();</code>.
  +
</p>
  +
</td>
  +
</tr>
  +
<tr valign="top">
  +
<td style="background-color:#ffffdd;border:black 1px dashed;">
  +
<pre>
  +
# problem set up
  +
$a = random(2,9,1);
  +
# $region will already be in displaymath mode
  +
$region = "x = $a y, \quad y^3 = x \quad (\mbox{with } y\geq 0)";
  +
$lineofrotation = "the y-axis";
  +
</pre>
  +
</td>
  +
<td style="background-color:#ffffcc;padding:7px;">
  +
<p>
  +
<b>Setup:</b> Everything is as usual.
  +
</p>
  +
</td>
  +
</tr>
  +
<tr valign="top">
  +
<td style="background-color:#ffdddd;border:black 1px dashed;">
  +
<pre>
  +
BEGIN_TEXT
  +
The volume of the solid obtained by rotating the region enclosed by
  +
\[
  +
$region
  +
\]
  +
about $lineofrotation can be computed using the method of disks or
  +
washers via an integral
  +
$BR
  +
$BCENTER
  +
\( \displaystyle V = \int_a^b \)
  +
\{NAMED_ANS_RULE('optional1',50)\}
  +
\{NAMED_POP_UP_LIST('optional2',''=>'?','dx'=>'dx','dy'=>'dy')\}
  +
$ECENTER
  +
$BR
  +
with limits of integration
  +
\( a = \) \{NAMED_ANS_RULE('optional3',10)\} and
  +
\( b = \) \{NAMED_ANS_RULE('optional4',10)\}.
  +
$BR
  +
$BR
  +
The volume is \( V = \) \{ans_rule(50)\} cubic units.
  +
  +
$PAR
  +
${BITALIC}
  +
Note: You can earn full credit if the last question
  +
is correct and all other questions are either blank
  +
or correct.
  +
${EITALIC}
  +
END_TEXT
  +
</pre>
  +
<td style="background-color:#ffcccc;padding:7px;">
  +
<p>
  +
<b>Main Text:</b>
  +
The answer box for the credit answer (the actual volume) is as usual; however, the other answer boxes are not as usual. In particular, you must use <code>\{ NAMED_ANS_RULE( 'label', width ) \}</code> or an appropriate variation for all answer boxes other than the credit answer.
  +
</p>
  +
<p>
  +
The second argument ' '=>'?' in <code> NAMED_POP_UP_LIST('optional2', ...)</code> is a "value=>tag" pair which ensures that if the tag '?' is selected the pop-up returns a blank value, so '?' doesn't count as an incorrect answer when CREDIT_ANS is evaluated.
  +
</p>
  +
<p>
  +
At the bottom of the text of the problem, include a note to students that explains how they can earn credit.
  +
</p>
  +
</td>
  +
</tr>
  +
<tr valign="top">
  +
<td style="background-color:#eeddff;border:black 1px dashed;">
  +
<pre>
  +
# answers below are incorrect to maintain
  +
# the integrity of the original problem
  +
$integrand="pi*x**2";
  +
$differential="dx";
  +
$lowerlimit="3";
  +
$upperlimit="5";
  +
$volume = pi*$a**3;
  +
  +
NAMED_WEIGHTED_ANS( 'optional1', fun_cmp($integrand, vars=>['x','y'],
  +
limits=>[[1,2],[1,2]]), 50 );
  +
  +
NAMED_WEIGHTED_ANS( 'optional2', str_cmp($differential), 2 );
  +
  +
NAMED_WEIGHTED_ANS( 'optional3', num_cmp($lowerlimit), 4 );
  +
  +
NAMED_WEIGHTED_ANS( 'optional4', num_cmp($upperlimit), 4 );
  +
  +
CREDIT_ANS( num_cmp($volume),
  +
['optional1','optional2','optional3','optional4'], 40 );
  +
  +
COMMENT('Gives partial credit for correct answers to initial questions
  +
or full credit for answering only the the final question correctly.');
  +
  +
ENDDOCUMENT();
  +
</pre>
  +
<td style="background-color:#eeccff;padding:7px;">
  +
<p>
  +
<b>Answer Evaluation:</b>
  +
For the non-credit answers, use <code>NAMED_WEIGHTED_ANS( 'label', evaluator, weight );</code> instead of <code>ANS( evaluator );</code>. For the credit answer, use <code>CREDIT_ANS( evaluator, [list of names of answer blanks to provide credit for], weight );</code>. The code given assigns 50% to the integrand, 2% to the differential, 4% to each of the limits of integration, and 40% to the value of the integral. If the student correctly calculates the volume and either enters only the volume or all other answer blanks are correct, then full credit is awarded. The weights should be positive integers that sum to 100.
  +
</p>
  +
<p>
  +
Since weighted answers with the credit answer option are non-standard, insert a <code>COMMENT()</code> that explains how answers are evaluated. This comment is only visible to professors browsing the problem library.
  +
</p>
  +
</td>
  +
</tr>
  +
</table>
  +
  +
   
   

Latest revision as of 10:27, 28 June 2023

This article has been retained as a historical document. It is not up-to-date and the formatting may be lacking. Use the information herein with caution.

This problem has been replaced with a newer version of this problem

Weighted Graders

If a question has n answer blanks, the default grader, which is the average problem grader (avg_problem_grader), will use 1/n as the weight for each answer. We describe several different ways to weight answers differently.

  • The standard problem grader assigns full credit if all answers are correct, and zero credit otherwise. This all-or-nothing grader should always be used for matching, multiple choice, and true / false questions, otherwise students will be able to deduce how many answers are correct by the partial credit reported by webwork.
  • The full-partial grader gives full credit if the last answer is correct, no matter what the other answers are, and partial credit (like the average problem grader) otherwise.
  • The weighted grader allows you to assign a weight to each answer blank in a problem.
  • The weighted grader with the credit answer option allows you to specify one answer blank to be the final answer which, if answered correctly, will provide full credit for all other answer blanks in the problem.
  • The incremental weighted grader, which awards a certain amount of credit for answering a certain number of parts correctly, is described in Example 1 (answer evaluation section) on the page PopUpListsLong


Standard Problem Grader: give full credit if all answers are correct and zero credit otherwise.

Problem Techniques Index

PG problem file Explanation
#######################
#  Initialization
loadMacros("PGstandard.pl");

#  Usual setup and main text go here

#######################
#  Answer evaluation

install_problem_grader(~~&std_problem_grader);

$showPartialCorrectAnswers = 0;

ANS($a->cmp());
ANS($b->cmp());
ANS($c->cmp());

Initialization: Be sure to load PGstandard.pl, which automatically loads PGanswermacros.pl which has the standard problem grader.

Answer Evaluation: We use install_problem_grader(~~&std_problem_grader); to give full credit only if all answers are correct, and zero credit otherwise. We should probably also hide feedback on whether answers are partially correct or not by setting $showPartialCorrectAnswers=0;. The standard problem grader is recommended for true / false and multiple choice questions to prevent students from guessing and receiving either feedback or partial credit that tells them whether their guess was correct.



Full-Partial Grader: give full credit if the last answer is correct, no matter what the other answers are, and partial credit (like the average problem grader) otherwise.

Problem Techniques Index

PG problem file Explanation
#######################
#  Initialization
loadMacros(
"PGstandard.pl",
"PGgraders.pl",
);

#  Usual setup and main text go here

#######################
#  Answer evaluation

install_problem_grader(~~&full_partial_grader);

$showPartialCorrectAnswers = 1;

ANS($a->cmp());
ANS($b->cmp());
ANS($c->cmp());

Initialization: Be sure to load PGgraders.pl

Answer Evaluation: Use install_problem_grader(~~&full_partial_grader); to install this grader. Everything else is as usual. If the student answers the third question correctly, they will receive full credit no matter what their other answers are.




Weighted Grader: assign different weights (percentages) to each answer in a problem.

PG problem file Explanation
DOCUMENT();

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"weightedGrader.pl",
"PGcourse.pl",
);

install_weighted_grader();

TEXT(beginproblem());

Initialization: We need to include the weightedGrader.pl macro file and immediately install it using install_weighted_grader();.

Context("Numeric");
Context()->variables->add(t=>"Real");
Context()->strings->add(A=>{},B=>{});

$r = random(2,4,1);
$answer1 = Real("pi * $r**2");
$answer2 = Formula("($r - 1) * x**2 * t") -> reduce;
$answer3 = String("A");

Setup: To show how this works with MathObjects, we add some variables and strings to the context.

Context()->texStrings;
BEGIN_TEXT
Enter \( \pi $r^2 \): \{ans_rule(10)\}
Enter \( $answer2 \): \{ans_rule(10)\}
Enter A: \{ans_rule(10)\}
END_TEXT
Context()->normalStrings;

Main Text: Answer boxes are as usual.

$showPartialCorrectAnswers = 0;

WEIGHTED_ANS( ($answer1)->cmp(), 40 );
WEIGHTED_ANS( ($answer2)->cmp(), 40 );
WEIGHTED_ANS( ($answer3)->cmp(), 20 );

ENDDOCUMENT();

Answer Evaluation: Use WEIGHTED_ANS( evaluator, weight ); instead of ANS( evaluator );. The code given assigns 40% to each of the first two answers, and 20% to the last answer. The weights should be positive integers that sum to 100.







Weighted Grader with Credit Answer Option: assign different weights (percentages) to each answer in a problem, and provide one answer blank that, if correct, will supersede all other answer blanks and award full credit.

PG problem file Explanation
DOCUMENT();

loadMacros(
"PGchoicemacros.pl",
"PGanswermacros.pl",
"PGauxiliaryFunctions.pl",
"weightedGrader.pl"
);

install_weighted_grader();
$showPartialCorrectAnswers = 1;

TEXT(beginproblem());

Initialization: We need to include the weightedGrader.pl macro file and immediately install it using install_weighted_grader();.

# problem set up
$a = random(2,9,1);
# $region will already be in displaymath mode
$region = "x = $a y, \quad y^3 = x \quad (\mbox{with } y\geq 0)"; 
$lineofrotation = "the y-axis"; 

Setup: Everything is as usual.

BEGIN_TEXT
The volume of the solid obtained by rotating the region enclosed by 
\[
$region
\] 
about $lineofrotation can be computed using the method of disks or 
washers via an integral
$BR
$BCENTER
\( \displaystyle V = \int_a^b \) 
\{NAMED_ANS_RULE('optional1',50)\}  
\{NAMED_POP_UP_LIST('optional2',''=>'?','dx'=>'dx','dy'=>'dy')\}
$ECENTER
$BR
with limits of integration 
\( a = \) \{NAMED_ANS_RULE('optional3',10)\} and 
\( b = \) \{NAMED_ANS_RULE('optional4',10)\}.
$BR
$BR
The volume is \( V = \) \{ans_rule(50)\} cubic units.

$PAR
${BITALIC}
Note: You can earn full credit if the last question   
is correct and all other questions are either blank 
or correct.
${EITALIC}
END_TEXT

Main Text: The answer box for the credit answer (the actual volume) is as usual; however, the other answer boxes are not as usual. In particular, you must use \{ NAMED_ANS_RULE( 'label', width ) \} or an appropriate variation for all answer boxes other than the credit answer.

The second argument ' '=>'?' in NAMED_POP_UP_LIST('optional2', ...) is a "value=>tag" pair which ensures that if the tag '?' is selected the pop-up returns a blank value, so '?' doesn't count as an incorrect answer when CREDIT_ANS is evaluated.

At the bottom of the text of the problem, include a note to students that explains how they can earn credit.

# answers below are incorrect to maintain 
# the integrity of the original problem
$integrand="pi*x**2";
$differential="dx";
$lowerlimit="3";
$upperlimit="5";
$volume = pi*$a**3;

NAMED_WEIGHTED_ANS( 'optional1', fun_cmp($integrand, vars=>['x','y'], 
limits=>[[1,2],[1,2]]), 50 );

NAMED_WEIGHTED_ANS( 'optional2', str_cmp($differential), 2 );

NAMED_WEIGHTED_ANS( 'optional3', num_cmp($lowerlimit), 4 );

NAMED_WEIGHTED_ANS( 'optional4', num_cmp($upperlimit), 4 );

CREDIT_ANS( num_cmp($volume), 
['optional1','optional2','optional3','optional4'], 40 );

COMMENT('Gives partial credit for correct answers to initial questions
or full credit for answering only the the final question correctly.');

ENDDOCUMENT();

Answer Evaluation: For the non-credit answers, use NAMED_WEIGHTED_ANS( 'label', evaluator, weight ); instead of ANS( evaluator );. For the credit answer, use CREDIT_ANS( evaluator, [list of names of answer blanks to provide credit for], weight );. The code given assigns 50% to the integrand, 2% to the differential, 4% to each of the limits of integration, and 40% to the value of the integral. If the student correctly calculates the volume and either enters only the volume or all other answer blanks are correct, then full credit is awarded. The weights should be positive integers that sum to 100.

Since weighted answers with the credit answer option are non-standard, insert a COMMENT() that explains how answers are evaluated. This comment is only visible to professors browsing the problem library.




Problem Techniques Index