WeBWorK Problems

Post-Filter answer hints to flag round-off error entries?

Post-Filter answer hints to flag round-off error entries?

by tim Payer -
Number of replies: 1
Greetings,

I would like to adapt my Post-filter answer hints to accommodate the flagging of round-off errors with a brief "Round-off error!" message. I have declared "low" and "high" interval variables to intercept these round off errors in the student's calculation of the mean for a pdf:

The tolerance for the answer is an absolute 0.0001
on lines 73-74:
$u2low = Compute("$mean -0.01, $mean-0.0002");
$u2hi = Compute("$mean + 0.0002, $mean+0.01");

I am assuming that I will use something like:
$u2low ->contains($student)
$u2hi ->contains($student)
Am I right in assuming that flagging the student entry will require a custom answer checker, and if so how do I merge a custom answer checker with an already established weighted answer checker with post filter answer hints (Lines127-130)?

Thank you for any help you can you can send my way...

Tim

# Data type identification
# WeBWorK problem written by TimPayer <tsp1@humboldt.edu>
# ENDDESCRIPTION

## DBsubject(Statistics)
## DBchapter(Exploratory data analysis/descriptive statistics)
## DBsection(Summary statistics)
## Institution(Humboldt State University)
## Author(Tim Payer)
## KEYWORDS(summations, mean, sd)

DOCUMENT();
loadMacros(
"PGstandard.pl",
"niceTables.pl",
"unionTables.pl",
"PGunion.pl",
"MathObjects.pl",
"PGML.pl",
"parserPopUp.pl",
"weightedGrader.pl",
"answerHints.pl",
"parserFormulaUpToConstant.pl"
);


install_weighted_grader();

Context("Numeric");
#install_problem_grader(~~&std_problem_grader);
$showPartialCorrectAnswers = 1;

Context()->flags->set(
tolerance => 0.0001,
tolType => "absolute",
);
##### Note: If changing the tolerance level above, be sure to make a
##### corresponding change in the interval variables of u2low and u2hi.


$h = list_random('five', 'six', 'seven', 'eight');

if($h eq "five" )
{
$win = random(250,260,2);
$wind = random(60,80,2);
} elsif ($h eq "six")
{
$win = random(500,600,5);
$wind = random(120,130,1);
} elsif ($event eq "seven")
{
$win = random(900,990,5);
$wind = random(210,220,2);
} else
{
$win = random(1400,1500,5);
$wind = random(336,350,2);
}

$windm = $wind - 1;
### Testing $win:
$win = Real($win);

$winprob = Compute(1/$wind);
$lossprob = Compute(1-$winprob);
$loss = Compute(-5);
$wl = Compute(5);

$mean = Compute("$win*$winprob+$loss*$lossprob");
### Intervals to "catch" round-off error entries: ####
$u2low = Compute("$mean-0.01, $mean-0.0002");
$u2hi = Compute("$mean+0.0002, $mean+0.01");
#####################################################
$sd = Compute(sqrt($win**2*$winprob +$loss**2*$lossprob -$mean**2));
$lb = Compute($mean -$sd);
$ub = Compute($mean +$sd);
$wm = Compute("($win+$loss)/2");

########################## Begin problem Display....
BEGIN_PGML
*Drawn from lecture notes: Week 4, Day 1*
*5.3)* A trifecta is a horse racing bet where the bettor wagers on which three horses will finish first, second, and third in a horse race. The three lead horses must finish the race in the order specified by the bettor or the bet is lost. The trifecta bet is a long shot with minimal risk but with a big pay-off, particularly if one or more unfavored horses are selected. This bet appeals to bettors who feel that they can ascertain the relative strengths of each horse in a given race. Suppose that you are such a bettor and have made a trifecta bet for three horses in a [$h] horse race. You make a $5 bet and stand to win $[$win] if your trifecta comes in, but the house has staked your probability of winning at [``\frac{1}{[$wind]}``]. Complete the pdf table below and use it to determine the expected return (the mean) for your bet. Then determine the standard deviation for the trifecta bet and the resulting first standard deviation window.



[@
DataTable(
[
[[" ", headerrow => 1],"\\(x \\)","\\(P(x)\\)"],
[["win:" ], $win->ans_rule(5) , $winprob->ans_rule(5)],
[["loss:" ], $loss->ans_rule(5), $lossprob->ans_rule(5)],
],
caption => "A PDF for Trifectas:",
midrules => 1,
align => "|p{0.5in}|p{1in}|p{1in}|",
);
@]***
*Warning!* Do not let the green feild answer boxes above signifying a correct answer lead you into making the very common Round off error fallacy: Just because you cleared [` \pm 0.0001 `] tolerance in the answers above you can not expect that tolerance to hold when you use rounded values input to subsequent calculations for the mean and sd. To avoid an amplification of round off error use exact values, (*Think: Fractions*) not rounded decimal values.
*5.3a)* Find the expected return on making this trifecta bet. (use fourth decimal accuracy):
[``\Large{\mu_x}``] = [_______]
*5.3b)* Find the expected standard deviation for the trifecta bet using fourth decimal accuracy:
[``\Large{\sigma_x}``] = [_______]
*5.3c)* Determine the first standard deviation window for the trifecta bet using fourth decimal accuracy:
Lower sd window bound = [_____]
Upper sd window bound = [_____]
END_PGML

#################### Weighted Answers:
#$win->ans_rule(5)
WEIGHTED_ANS( ($win)->cmp, 5 );
WEIGHTED_ANS( ($winprob)->cmp, 5 );
WEIGHTED_ANS( $loss->cmp() ->withPostFilter(AnswerHints(
$loss => "Yes!",
$wl => "Not Quite. How would you distinguish between winning 5 dollars and losing 5 dollars?",
)),10 );
WEIGHTED_ANS( ($lossprob)->cmp, 5 );

WEIGHTED_ANS( $mean->cmp() ->withPostFilter(AnswerHints(
$mean => "Yes!",
$wm => "No, Your mean calculation did not account for differing likelihoods.",
)),10 );
WEIGHTED_ANS( ($sd)->cmp, 30 );
WEIGHTED_ANS( ($lb)->cmp, 5 );
WEIGHTED_ANS( ($ub)->cmp, 5 );


BEGIN_PGML_SOLUTION
*SOLUTION*

*5.3)* First complete the table to determine the respective probabilities:


[@
DataTable(
[
[[" ", headerrow => 1],"\\(x \\)","\\(P(x)\\)"],
[["win:" ], "\\(\\displaystyle{$win } \\)", "\\(\\displaystyle{ \\frac{1}{$wind} =$winprob }\\)"],
[["loss:" ], "\\(\\displaystyle{$loss} \\)", "\\( \\displaystyle{\\frac{$windm}{$wind} = $lossprob } \\)"],
],
caption => "A PDF for Trifectas:",
midrules => 1,
align => "|p{0.5in}|p{0.5in}|p{1.5in}|",
);
@]***

*5.3a)* Find the expected return on making this trifecta bet. (use fourth decimal accuracy):
[``\Large{\mu_x}``] [``\displaystyle{ = [$win] \cdot \frac{1}{[$wind]} + ([$loss]) \cdot \frac{[$windm]}{[$wind]} }``]
[``\Large{\mu_x}``] = [``[$mean] ``]

*5.3b)* Find the expected standard deviation for the trifecta bet using fourth decimal accuracy:
[``\Large{\sigma_x}``] [`` = \displaystyle{\sqrt{[$win]^2 \cdot \frac{1}{[$wind]} + ([$loss])^2 \cdot \frac{[$windm]}{[$wind]}- ([$mean])^2}} ``]
[``\Large{\sigma_x}``] = [``[$sd] ``]
*5.3c)* Determine the first standard deviation window for the trifecta bet using fourth decimal accuracy:
Lower bound for the first sd window = [``\Large{\mu_x} - \Large{\sigma_x}``]
[``\mu_x - \sigma_x = [$mean] - [$sd] ``]
[``\mu_x - \sigma_x = [$lb] ``]
Upper bound for the first sd window = [``\Large{\mu_x} + \Large{\sigma_x}``]
[``\mu_x + \sigma_x = [$mean] + [$sd] ``]
[``\mu_x + \sigma_x = [$ub] ``]

END_PGML_SOLUTION

ENDDOCUMENT();




In reply to tim Payer

Re: Post-Filter answer hints to flag round-off error entries?

by tim Payer -
With some help from co-worker, Tim Lauck, we were able to arrive at a custom answer checker for weighted answers involving round-off error.

For any who might want to use something similar here is the code block:

########################
#### Custom Weighted Answer Checker for Round-off error:
########################
## The correct value: $c
## The student's entry: $s
## The returned score: $ans
## Note: Be sure that the tolerance in the settings (0.0001)
## do not restrict the custom answer checker.

WEIGHTED_ANS($mean->cmp(
checker => sub {
my ($c, $s, $ans) = @_;
$diff = abs($mean -$s); ## establishing the error
if(($diff <= 0.01) && ($diff >= 0.0002))
{
$score = 0; ## has round-off error
$ans->{ans_message} = "You have round-off error. Try using exact values (think: Fractions) in your calculation." ;
} elsif($s == $wm) {
$score = 0; ## Using a geometric mean in error.
$ans->{ans_message} = "No, Your mean calculation did not account for differing likelihoods." ;
} elsif($s == $mean) {
$score = 1; ## a correct calculation within 0.0001
$ans->{ans_message} = "Yes!" ;
} else {
$ans->{ans_message} = "Nope! But, Keep Trying!";
$score= 0; ### All other scenarios
}
return $score;
}
),10); ## 10pts is the weighted value of this problem.

Tim