WeBWorK Problems

Weighted Grader errors?

Weighted Grader errors?

by tim Payer -
Number of replies: 8
Hello Webwork folks,

Can you please let me know what I am missing in regards to using the weighted grader function? It is my first time using it and I would like to incorporate it with a number of problems.

The error message is:

But I have loaded weighted grader,

This seems like something obvious that I have missed?

The block of code is below, Many Thanks, for your help.

# DESCRIPTION   Function translations
# Translate descriptions of critical points and function
# into correct notation.
# WeBWorK problem written by TimPayer <tsp1@humboldt.edu>
# ENDDESCRIPTION

## DBsubject(Probability)
## DBchapter(Random variables)
## DBsection(Expectation)
## Institution(Humboldt State University)
## Author(Tim Payer)
## KEYWORDS(probability, translate, notation)
DOCUMENT();

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

install_weighted_grader();

#Text(beginproblem());   #uncomment

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

Context("Numeric");
Context()->flags->set(
  tolerance => 0.0001,
  tolType => "absolute",
);

# create three arrays of the same length "in parallel"
# Using "hashes":

$bird = list_random('goose', 'crow', 'starling', 'penguin','quail','hawk','finch','parrot', 'woodpecker', 'dove','lark', 'swallow', 'sparrow', 'stork','peacock', 'owl', 'jay', 'chicken', 'turtledove', 'turkey', 'magpie', 'raven', 'nightingale', 'snipe', 'heron', 'mallard', 'duck', 'pheasant', 'coot', 'plover');
%birds = (goose=>'geese', crow=>'crows', starling=>'starlings', penguin=>'penguins', quail=>'quails',hawk=>'hawks',finch=>'finches',parrot=>'parrots', woodpecker=>'woodpeckers', dove=>'doves', lark=>'larks',swallow=>'swallows', sparrow=>'sparrows', stork=>'storks', peacock=>'peacocks', owl=>'owls', jay=>'jays', chicken=>'chickens', turtledove=>'turtledoves', turkey=>'turkeys', magpie=>'magpies', raven=>'ravens', nightingale=>'nightingales', snipe=>'snipes', heron=>'herons' , mallard=>'mallards', duck=>'ducks', pheasant=>'pheasants', coot=>'coots', plover=>'plovers' );
%flock= (goose=>'gaggle', crow=>'murder', starling=>'murmuration', penguin=>'colony', quail=>'bevy',hawk=>'cast',finch=>'charm', parrot=>'company',woodpecker=>'descent', dove=>'dole', lark=>'exaltation', swallow=>'flight', sparrow=>'host', stork=>'muster', peacock=>'ostentation', owl=>'parliament', jay=>'party', chicken=>'peep', turtledove=>'pitying', turkey=>'rafter', magpie=>'tidings', raven=>'unkindness', nightingale=>'watch',  snipe=>'wisp', heron=>'siege', mallard=>'sord', duck=>'raft', pheasant=>'nye', coot=>'cover', plover=>'congregation');

$event = list_random('more than one', 'at least one', 'at most one', 'not every');


#@bird = ('goose','crow','starling');  ##This format needs Version 11 or better.
#@birds = ('geese','crows','starlings');
#@flock = ('gaggle','murder','murmuring');
#$i = random(0, 2, 1); # choose an array index at random

$popup1 = PopUp(
["probability notation", "P(V = 0)", "P(V = 1)", "P(V = 2)", "P(V  > 0)", "P(V  > 1)","P(V < 2)",], "P(V = 2)");

$popup2 = PopUp(
["probability notation", "P(V = 0)", "P(V = 1)", "P(V = 2)", "P(V  > 0)", "P(V  > 1)","P(V < 2)",], "P(V  > 0)");

$popup4 = PopUp(
["draws?", "one", "two", "three",], "two");

$popup5 = PopUp(
["draws?", "one", "two", "three",], "three");

$v = random(6,28,1);
$ans1 =Compute("$v*$v/10000");
$ans2 = Compute("1-(1-$v/100)**2");

$d3 =random(0,3,1);
if($event == "more than one"){
$ans3=($v/100)**2*(3-2*$v/100);
$popup3ans = "P(V > 1)";
}elsif ($event == "at least one") {
$ans3=1-(1-$v/100)**3;
$popup3ans = "P(V > 0)";           
} elsif ($event == "at most one") {
$ans3=(1+2*$v/100)*(1-$v/100)**2;
$popup3ans = "P(V < 2)";           
} elsif ($event == "not every") {
$ans3=1-($v/100)**3;
$popup3ans = "P(V < 3)";           
}

$popup3 = PopUp(
["probability notation", "P(V = 0)", "P(V = 1)", "P(V = 2)", "P(V = 3)","P(V > 0)", "P(V > 1)","P(V < 2)","P(V < 3)",], $popup3ans);



BEGIN_PGML
 
1. The specific name for a flock of [@$birds{$bird}@]  is described as a "[@$flock{$bird}@]" of [@$birds{$bird}@].   
Consider the case where [$v]% of a [@$flock{$bird}@] of [@$birds{$bird}@] carry a bird flu virus. If two [@$birds{$bird}@] are drawn at random from the [@$flock{$bird}@], find the following probabilities but first complete the following event variable declaration:  

Let V = The number of [@$birds{$bird}@] with the bird flu virus taken from  [___]{$popup4} random draw(s) from the [@$flock{$bird}@]. 
 

1a.) What is the probability of randomly drawing two [@$birds{$bird}@] from the [@$flock{$bird}@] that both have the bird flu virus? Choose the correct probability notation below and then calculate its associated probability with fourth decimal accuracy.  

[___]{$popup1}  =  [______]{$ans1}
 
1b.) What is the probability of randomly drawing two [@$birds{$bird}@] such that at least one [$bird] has the bird flu virus? Choose the correct probability notation below and then calculate its associated probability with fourth decimal accuracy.  
Hint: Let N = the event of a [$bird] not having the bird flu virus. Then construct a sample space of all the possible combinations of V and N.

[___]{$popup2} = [______]{$ans2}

1c.) Consider the case where three [@$birds{$bird}@] are drawn at random from the [@$flock{$bird}@]. What is the probability that [$event] [$bird] has the bird flu virus? First complete the declaration of the event variable below:

Let V = The number of [@$birds{$bird}@] with the bird flu virus taken from  [___]{$popup5} random draw(s) from the [@$flock{$bird}@]. 

Choose the correct probability notation below and then calculate its associated probability with fourth decimal accuracy. Hint: Let N = the event of a [$bird] not having the bird flu virus. Then construct a sample space of all the possible combinations of V and N.

[___]{$popup3} = [______]{$ans3}


END_PGML

WEIGHTED_ANS( ($popup1)->cmp(), 8 );
WEIGHTED_ANS( ($popup2)->cmp(), 8 );
WEIGHTED_ANS( ($popup3)->cmp(), 8 );
WEIGHTED_ANS( ($popup4)->cmp(), 2 );
WEIGHTED_ANS( ($popup5)->cmp(), 2 );
WEIGHTED_ANS( ($ans1)->cmp(), 14 );
WEIGHTED_ANS( ($ans2)->cmp(), 24 );
WEIGHTED_ANS( ($ans3)->cmp(), 32 );

BEGIN_PGML_SOLUTION

The correct answers are coming....in 2017, Hah!



END_PGML_SOLUTION

ENDDOCUMENT();      
In reply to tim Payer

Re: Weighted Grader errors?

by Danny Glin -
The problem doesn't appear to be with your weighted answer syntax.  It is the fact that you haven't cast $ans3 as a MathObject, and therefore can't call the cmp() routine on it.  In your if statement, you will need to add Compute(...) to all of the $ans3=... lines.  I believe that if you do this it will work as expected.

Danny
In reply to Danny Glin

Re: Weighted Grader errors?

by tim Payer -
Hello,

And thanks Danny, but while that cleared up one set of errors, I have seemed to create a new batch of errors with the addition of the Compute command...?

How would this be so when I only added Compute("  "); to the $ans3 scenarios?

  • Use of uninitialized value $ans_name in hash element at /opt/webwork/pg/lib/WeBWorK/PG/Translator.pm line 1211

# DESCRIPTION   Function translations
# Translate descriptions of critical points and function
# into correct notation.
# WeBWorK problem written by TimPayer <tsp1@humboldt.edu>
# ENDDESCRIPTION

## DBsubject(Probability)
## DBchapter(Random variables)
## DBsection(Expectation)
## Institution(Humboldt State University)
## Author(Tim Payer)
## KEYWORDS(probability, translate, notation)
DOCUMENT();

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

install_weighted_grader();

#Text(beginproblem());   #uncomment

install_problem_grader(~~&std_problem_grader);
$showPartialCorrectAnswers = 1;

Context("Numeric");
Context()->flags->set(
  tolerance => 0.0001,
  tolType => "absolute",
);

# create three arrays of the same length "in parallel"
# Using "hashes":

$bird = list_random('goose', 'crow', 'starling', 'penguin','quail','hawk','finch','parrot', 'woodpecker', 'dove','lark', 'swallow', 'sparrow', 'stork','peacock', 'owl', 'jay', 'chicken', 'turtledove', 'turkey', 'magpie', 'raven', 'nightingale', 'snipe', 'heron', 'mallard', 'duck', 'pheasant', 'coot', 'plover');
%birds = (goose=>'geese', crow=>'crows', starling=>'starlings', penguin=>'penguins', quail=>'quails',hawk=>'hawks',finch=>'finches',parrot=>'parrots', woodpecker=>'woodpeckers', dove=>'doves', lark=>'larks',swallow=>'swallows', sparrow=>'sparrows', stork=>'storks', peacock=>'peacocks', owl=>'owls', jay=>'jays', chicken=>'chickens', turtledove=>'turtledoves', turkey=>'turkeys', magpie=>'magpies', raven=>'ravens', nightingale=>'nightingales', snipe=>'snipes', heron=>'herons' , mallard=>'mallards', duck=>'ducks', pheasant=>'pheasants', coot=>'coots', plover=>'plovers' );
%flock= (goose=>'gaggle', crow=>'murder', starling=>'murmuration', penguin=>'colony', quail=>'bevy',hawk=>'cast',finch=>'charm', parrot=>'company',woodpecker=>'descent', dove=>'dole', lark=>'exaltation', swallow=>'flight', sparrow=>'host', stork=>'muster', peacock=>'ostentation', owl=>'parliament', jay=>'party', chicken=>'peep', turtledove=>'pitying', turkey=>'rafter', magpie=>'tidings', raven=>'unkindness', nightingale=>'watch',  snipe=>'wisp', heron=>'siege', mallard=>'sord', duck=>'raft', pheasant=>'nye', coot=>'cover', plover=>'congregation');

$event = list_random('more than one', 'at least one', 'at most one', 'not every');


#@bird = ('goose','crow','starling');  ##This format needs Version 11 or better.
#@birds = ('geese','crows','starlings');
#@flock = ('gaggle','murder','murmuring');
#$i = random(0, 2, 1); # choose an array index at random

$popup1 = PopUp(
["probability notation", "P(V = 0)", "P(V = 1)", "P(V = 2)", "P(V  > 0)", "P(V  > 1)","P(V < 2)",], "P(V = 2)");

$popup2 = PopUp(
["probability notation", "P(V = 0)", "P(V = 1)", "P(V = 2)", "P(V  > 0)", "P(V  > 1)","P(V < 2)",], "P(V  > 0)");

$popup4 = PopUp(
["draws?", "one", "two", "three",], "two");

$popup5 = PopUp(
["draws?", "one", "two", "three",], "three");

$v = random(6,28,1);
$ans1 =Compute("$v*$v/10000");
$ans2 = Compute("1-(1-$v/100)**2");


if($event == "more than one"){
$ans3=Compute("($v/100)**2*(3-2*$v/100)");
$popup3ans = "P(V > 1)";
}elsif ($event == "at least one") {
$ans3=Compute("1-(1-$v/100)**3");
$popup3ans = "P(V > 0)";           
} elsif ($event == "at most one") {
$ans3=Compute("(1+2*$v/100)*(1-$v/100)**2");
$popup3ans = "P(V < 2)";           
} elsif ($event == "not every") {
$ans3=Compute("1-($v/100)**3");
$popup3ans = "P(V < 3)";           
}

$popup3 = PopUp(
["probability notation", "P(V = 0)", "P(V = 1)", "P(V = 2)", "P(V = 3)","P(V > 0)", "P(V > 1)","P(V < 2)","P(V < 3)",], $popup3ans);



BEGIN_PGML
 
1. The specific name for a flock of [@$birds{$bird}@]  is described as a "[@$flock{$bird}@]" of [@$birds{$bird}@].   
Consider the case where [$v]% of a [@$flock{$bird}@] of [@$birds{$bird}@] carry a bird flu virus. If two [@$birds{$bird}@] are drawn at random from the [@$flock{$bird}@], find the following probabilities but first complete the following event variable declaration:  

Let V = The number of [@$birds{$bird}@] with the bird flu virus taken from  [___]{$popup4} random draw(s) from the [@$flock{$bird}@]. 
 

1a.) What is the probability of randomly drawing two [@$birds{$bird}@] from the [@$flock{$bird}@] that both have the bird flu virus? Choose the correct probability notation below and then calculate its associated probability with fourth decimal accuracy.  

[___]{$popup1}  =  [______]{$ans1}
 
1b.) What is the probability of randomly drawing two [@$birds{$bird}@] such that at least one [$bird] has the bird flu virus? Choose the correct probability notation below and then calculate its associated probability with fourth decimal accuracy.  
Hint: Let N = the event of a [$bird] not having the bird flu virus. Then construct a sample space of all the possible combinations of V and N.

[___]{$popup2} = [______]{$ans2}

1c.) Consider the case where three [@$birds{$bird}@] are drawn at random from the [@$flock{$bird}@]. What is the probability that [$event] [$bird] has the bird flu virus? First complete the declaration of the event variable below:

Let V = The number of [@$birds{$bird}@] with the bird flu virus taken from  [___]{$popup5} random draw(s) from the [@$flock{$bird}@]. 

Choose the correct probability notation below and then calculate its associated probability with fourth decimal accuracy. Hint: Let N = the event of a [$bird] not having the bird flu virus. Then construct a sample space of all the possible combinations of V and N.

[___]{$popup3} = [______]{$ans3}


END_PGML

WEIGHTED_ANS( ($popup1)->cmp(), 8 );
WEIGHTED_ANS( ($popup2)->cmp(), 8 );
WEIGHTED_ANS( ($popup3)->cmp(), 8 );
WEIGHTED_ANS( ($popup4)->cmp(), 2 );
WEIGHTED_ANS( ($popup5)->cmp(), 2 );
WEIGHTED_ANS( ($ans1)->cmp(), 14 );
WEIGHTED_ANS( ($ans2)->cmp(), 24 );
WEIGHTED_ANS( ($ans3)->cmp(), 32 );

BEGIN_PGML_SOLUTION

The correct answers are coming....in 2017, Hah!



END_PGML_SOLUTION

ENDDOCUMENT();              

In reply to tim Payer

Re: Weighted Grader errors?

by Davide Cervone -
In addition to the problem with $ans3 that Danny points out, there is a problem with how you are using the weighted grader.

The WEIGHTED_ANS() calls are a replacement for the standard ANS() calls, but since you are using PGML, you don't make the ANS() calls yourself; they are inserted automatically by PGML. So when you do something like

    [_________]{$popup1} = [_______}{$ans1}
this effectively already inserts the answer checkers for the menu and the type-in area using ANS(). So doing
WEIGHTED_ANS( $ppopup1->cmp, 8);
means you are trying to make new answer checker that is tied to the next unassigned answer blank, but since all the blanks are already assigned answer checkers, this checker is tied to nothing. (I believe that is the source of most of the error messages, but I didn't actually track them down to find out specifically which issue generated them).

Unfortunately, PGML doesn't have a direct mechanism for overriding its use of ANS internally. Instead, you need to not have it supply the answer checker at all, and do it yourself afterward. The usual way to do this would be to not provide an answer, and just use [_____] by itself (with no {$ans} after it).

Since you are using menus, however, you have to do a little more work. Using [_____] by itself always creates a type-in blank, but you want to have a menu not a type-in area. So you need to use [$popup1->menu]* instead of [______]{$popup1}, and after the PGML block, add

 WEIGHTED_AMS($popup1->cmp, 8);

It is also possible to put the WEIGHTED_ANS() call into the PGML at the location f the menu,

   [$popup1->menu]*[@ WEIGHTED_ANS($popup1->cmp,8) @]
though that makes the text of the problem harder to read.

If you put the WEIGHED_ANS() calls after the END_PGML, then you need to list the answer checkers in the same order as their answer blanks, since it is the order that determines which checker goes with with blank. (It is possible to use named answer blanks, even in PGML, and use NAMED_WEIGHTED_ANS(), but that is probably more work than necessary).

In reply to Davide Cervone

Re: Weighted Grader errors?

by tim Payer -
Thank you, Davide

That helped a lot, but I seem to have not executed the code changes completely correct.

For while I am not getting any reported errors now that I have taken out the calls of ans(), My if-else condition is not reporting on the correct selection.

I had thought that perhaps the order was wrong, but no I have written the order correctly.

Something else is causing the wrong selections for $popup3, and $ans3 

Can you see this too?

Thanks for your persistence with this...

Tim

# DESCRIPTION   Function translations
# Translate descriptions of critical points and function
# into correct notation.
# WeBWorK problem written by TimPayer <tsp1@humboldt.edu>
# ENDDESCRIPTION

## DBsubject(Probability)
## DBchapter(Random variables)
## DBsection(Expectation)
## Institution(Humboldt State University)
## Author(Tim Payer)
## KEYWORDS(probability, translate, notation)
DOCUMENT();

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

install_weighted_grader();

#Text(beginproblem());   #uncomment

install_problem_grader(~~&std_problem_grader);
$showPartialCorrectAnswers = 1;

Context("Numeric");
Context()->flags->set(
  tolerance => 0.0001,
  tolType => "absolute",
);

# create three arrays of the same length "in parallel"
# Using "hashes":

$bird = list_random('goose', 'crow', 'starling', 'penguin','quail','hawk','finch','parrot', 'woodpecker', 'dove','lark', 'swallow', 'sparrow', 'stork','peacock', 'owl', 'jay', 'chicken', 'turtledove', 'turkey', 'magpie', 'raven', 'nightingale', 'snipe', 'heron', 'mallard', 'duck', 'pheasant', 'coot', 'plover');
%birds = (goose=>'geese', crow=>'crows', starling=>'starlings', penguin=>'penguins', quail=>'quails',hawk=>'hawks',finch=>'finches',parrot=>'parrots', woodpecker=>'woodpeckers', dove=>'doves', lark=>'larks',swallow=>'swallows', sparrow=>'sparrows', stork=>'storks', peacock=>'peacocks', owl=>'owls', jay=>'jays', chicken=>'chickens', turtledove=>'turtledoves', turkey=>'turkeys', magpie=>'magpies', raven=>'ravens', nightingale=>'nightingales', snipe=>'snipes', heron=>'herons' , mallard=>'mallards', duck=>'ducks', pheasant=>'pheasants', coot=>'coots', plover=>'plovers' );
%flock= (goose=>'gaggle', crow=>'murder', starling=>'murmuration', penguin=>'colony', quail=>'bevy',hawk=>'cast',finch=>'charm', parrot=>'company',woodpecker=>'descent', dove=>'dole', lark=>'exaltation', swallow=>'flight', sparrow=>'host', stork=>'muster', peacock=>'ostentation', owl=>'parliament', jay=>'party', chicken=>'peep', turtledove=>'pitying', turkey=>'rafter', magpie=>'tidings', raven=>'unkindness', nightingale=>'watch',  snipe=>'wisp', heron=>'siege', mallard=>'sord', duck=>'raft', pheasant=>'nye', coot=>'cover', plover=>'congregation');



#@bird = ('goose','crow','starling');  ##This format needs Version 11 or better.
#@birds = ('geese','crows','starlings');
#@flock = ('gaggle','murder','murmuring');
#$i = random(0, 2, 1); # choose an array index at random

$popup1 = PopUp(
["probability notation", "P(V = 0)", "P(V = 1)", "P(V = 2)", "P(V  > 0)", "P(V  > 1)","P(V < 2)",], "P(V = 2)");

$popup2 = PopUp(
["probability notation", "P(V = 0)", "P(V = 1)", "P(V = 2)", "P(V  > 0)", "P(V  > 1)","P(V < 2)",], "P(V  > 0)");

$popup4 = PopUp(
["draws?", "one", "two", "three",], "two");

$popup5 = PopUp(
["draws?", "one", "two", "three",], "three");

#$v = random(6,28,1);
$v = 17;
$ans1 =Compute("$v*$v/10000");
$ans2 = Compute("1-(1-$v/100)**2");

#$ev = random(0,3,1)
$event = list_random("more than one", "at least one", "at most one", "not every");

if($event == "more than one"){
$ans3=Compute("($v/100)**2*(3-2*$v/100)");
$popup3ans = "P(V > 1)";
}elsif ($event == "at least one") {
$ans3=Compute("1-(1-$v/100)**3");
$popup3ans = "P(V > 0)";           
} elsif ($event == "at most one") {
$ans3=Compute("(1+2*$v/100)*(1-$v/100)**2");
$popup3ans = "P(V < 2)";           
} else {
$ans3=Compute("1-($v/100)**3");
$popup3ans = "P(V < 3)";           
}

# } elsif ($event == "not every") {
#$ans3=Compute("1-($v/100)**3");
#$popup3ans = "P(V < 3)";           
#}


$popup3 = PopUp(
["probability notation", "P(V = 0)", "P(V = 1)", "P(V = 2)", "P(V = 3)","P(V > 0)", "P(V > 1)","P(V < 2)","P(V < 3)",], $popup3ans);

#[___]{$popup1}  =  [______]{$ans1}

BEGIN_PGML
 
4.1) The specific name for a flock of [@$birds{$bird}@]  is described as a "[@$flock{$bird}@]" of [@$birds{$bird}@].   
Consider the case where [$v]% of a [@$flock{$bird}@] of [@$birds{$bird}@] carry a bird flu virus. If two [@$birds{$bird}@] are drawn at random from the [@$flock{$bird}@], find the following probabilities but first complete the following event variable declaration:  

Let V = The number of [@$birds{$bird}@] with the bird flu virus taken from  [$popup4->menu]* random draw(s) from the [@$flock{$bird}@]. 
 

4.1a.) What is the probability of randomly drawing two [@$birds{$bird}@] from the [@$flock{$bird}@] that both have the bird flu virus? Choose the correct probability notation below and then calculate its associated probability with fourth decimal accuracy.  

[$popup1->menu]* = [____]
 
4.1b.) What is the probability of randomly drawing two [@$birds{$bird}@] such that at least one [$bird] has the bird flu virus? Choose the correct probability notation below and then calculate its associated probability with fourth decimal accuracy.  
Hint: Let N = the event of a [$bird] not having the bird flu virus. Then construct a sample space of all the possible combinations of V and N.

[$popup2->menu]* = [____]

4.1c.) Consider the case where three [@$birds{$bird}@] are drawn at random from the [@$flock{$bird}@]. What is the probability that [$event] [$bird] has the bird flu virus? First complete the declaration of the event variable below:

Let V = The number of [@$birds{$bird}@] with the bird flu virus taken from  [$popup5->menu]* random draw(s) from the [@$flock{$bird}@]. 

Choose the correct probability notation below and then calculate its associated probability with fourth decimal accuracy. Hint: Let N = the event of a [$bird] not having the bird flu virus. Then construct a sample space of all the possible combinations of V and N.

[$popup3->menu]* = [____]


END_PGML

#These weighted values cause errors:  

WEIGHTED_ANS( ($popup4)->cmp, 2 );
WEIGHTED_ANS( ($popup1)->cmp, 8 );
WEIGHTED_ANS( ($ans1)->cmp, 14 );
WEIGHTED_ANS( ($popup2)->cmp, 8 );
WEIGHTED_ANS( ($ans2)->cmp, 24 );
WEIGHTED_ANS( ($popup5)->cmp, 2 );
WEIGHTED_ANS( ($popup3)->cmp, 8 );
WEIGHTED_ANS( ($ans3)->cmp, 34 ); 

# Original form before using popups in PGML
#WEIGHTED_ANS( ($popup4)->cmp(), 2 );
#WEIGHTED_ANS( ($popup1)->cmp(), 8 );
#WEIGHTED_ANS( ($ans1)->cmp(), 14 );
#WEIGHTED_ANS( ($popup2)->cmp(), 8 );
#WEIGHTED_ANS( ($ans2)->cmp(), 24 );
#WEIGHTED_ANS( ($popup5)->cmp(), 2 );
#WEIGHTED_ANS( ($popup3)->cmp(), 8 );
#WEIGHTED_ANS( ($ans3)->cmp(), 32 ); 

BEGIN_PGML_SOLUTION

event = [$event] 

popup3ans = [$popup3ans]
ans3 = [$ans3]

The correct answers are coming....in 2017, Hah!



END_PGML_SOLUTION

ENDDOCUMENT();              

In reply to tim Payer

Re: Weighted Grader errors?

by tim Payer -
An Update on weighted Graders problems:

The specific problem I am having is that after I have successfully used the weighted problem grader, somehow the if-else conditional is grabbing only the first condition, regardless of what the given condition is for the if-else assignment for $ans3 and $popup3ans:

Can you tell why this is happening?

# DESCRIPTION   Function translations
# Translate descriptions of critical points and function
# into correct notation.
# WeBWorK problem written by TimPayer <tsp1@humboldt.edu>
# ENDDESCRIPTION

## DBsubject(Probability)
## DBchapter(Random variables)
## DBsection(Expectation)
## Institution(Humboldt State University)
## Author(Tim Payer)
## KEYWORDS(probability, translate, notation)
DOCUMENT();

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

install_weighted_grader();

#Text(beginproblem());   #uncomment

install_problem_grader(~~&std_problem_grader);
$showPartialCorrectAnswers = 1;

Context("Numeric");
Context()->flags->set(
  tolerance => 0.0001,
  tolType => "absolute",
);

# create three arrays of the same length "in parallel"
# Using "hashes":

$bird = list_random('goose', 'crow', 'starling', 'penguin','quail','hawk','finch','parrot', 'woodpecker', 'dove','lark', 'swallow', 'sparrow', 'stork','peacock', 'owl', 'jay', 'chicken', 'turtledove', 'turkey', 'magpie', 'raven', 'nightingale', 'snipe', 'heron', 'mallard', 'duck', 'pheasant', 'coot', 'plover');

%birds = (goose=>'geese', crow=>'crows', starling=>'starlings', penguin=>'penguins', quail=>'quails',hawk=>'hawks', finch=>'finches', parrot=>'parrots', woodpecker=>'woodpeckers', dove=>'doves', lark=>'larks',swallow=>'swallows', sparrow=>'sparrows', stork=>'storks', peacock=>'peacocks', owl=>'owls', jay=>'jays', chicken=>'chickens', turtledove=>'turtledoves', turkey=>'turkeys', magpie=>'magpies', raven=>'ravens', nightingale=>'nightingales', snipe=>'snipes', heron=>'herons' , mallard=>'mallards', duck=>'ducks', pheasant=>'pheasants', coot=>'coots', plover=>'plovers' );

%flock= (goose=>'gaggle', crow=>'murder', starling=>'murmuration', penguin=>'colony', quail=>'bevy',hawk=>'cast',finch=>'charm', parrot=>'company',woodpecker=>'descent', dove=>'dole', lark=>'exaltation', swallow=>'flight', sparrow=>'host', stork=>'muster', peacock=>'ostentation', owl=>'parliament', jay=>'party', chicken=>'peep', turtledove=>'pitying', turkey=>'rafter', magpie=>'tidings', raven=>'unkindness', nightingale=>'watch',  snipe=>'wisp', heron=>'siege', mallard=>'sord', duck=>'raft', pheasant=>'nye', coot=>'cover', plover=>'congregation');



#@bird = ('goose','crow','starling');  ##This format needs Version 11 or better.
#@birds = ('geese','crows','starlings');
#@flock = ('gaggle','murder','murmuring');
#$i = random(0, 2, 1); # choose an array index at random

$popup1 = PopUp(
["probability notation", "P(V = 0)", "P(V = 1)", "P(V = 2)", "P(V  > 0)", "P(V  > 1)","P(V < 2)",], "P(V = 2)");

$popup2 = PopUp(
["probability notation", "P(V = 0)", "P(V = 1)", "P(V = 2)", "P(V  > 0)", "P(V  > 1)","P(V < 2)",], "P(V  > 0)");

$popup4 = PopUp(
["draws?", "one", "two", "three",], "two");

$popup5 = PopUp(
["draws?", "one", "two", "three",], "three");

#$v = random(6,28,1);
$v = 17;
$ans1 =Compute("$v*$v/10000");
$ans2 = Compute("1-(1-$v/100)**2");

#$ev = random(0,3,1)
$event = list_random('more than one', 'at least one', 'at most one', 'not every');

#$event = "blank";

if($event == "more than one" )
{
$ans3=Compute("($v/100)**2*(3-2*$v/100)");
$popup3ans = "P(V > 1)";
#$event = "more than one";
} elsif ($event = "at least one")
{
$ans3=Compute("1-(1-$v/100)**3");
$popup3ans = "P(V > 0)";
#$event = "at least one";           
} elsif ($event = "at most one")
{
$ans3=Compute("(1+2*$v/100)*(1-$v/100)**2");
$popup3ans = "P(V < 2)";
#$event = "at most one";
} else
{
$ans3=Compute("1-($v/100)**3");
$popup3ans = "P(V < 3)";
#$event = "not every";           
}

# } elsif ($event == "not every") {
#$ans3=Compute("1-($v/100)**3");
#$popup3ans = "P(V < 3)";           
#}


$popup3 = PopUp(
["probability notation", "P(V = 0)", "P(V = 1)", "P(V = 2)", "P(V = 3)","P(V > 0)", "P(V > 1)","P(V < 2)","P(V < 3)",], $popup3ans);

#[___]{$popup1}  =  [______]{$ans1}

BEGIN_PGML
 
4.1) The specific name for a flock of [@$birds{$bird}@]  is described as a "[@$flock{$bird}@]" of [@$birds{$bird}@].   
Consider the case where [$v]% of a [@$flock{$bird}@] of [@$birds{$bird}@] carry a bird flu virus. If two [@$birds{$bird}@] are drawn at random from the [@$flock{$bird}@], find the following probabilities but first complete the following event variable declaration:  

Let V = The number of [@$birds{$bird}@] with the bird flu virus taken from  [$popup4->menu]* random draw(s) from the [@$flock{$bird}@]. 
 

4.1a.) What is the probability of randomly drawing two [@$birds{$bird}@] from the [@$flock{$bird}@] that both have the bird flu virus? Choose the correct probability notation below and then calculate its associated probability with fourth decimal accuracy.  

[$popup1->menu]* = [____]
 
4.1b.) What is the probability of randomly drawing two [@$birds{$bird}@] such that at least one [$bird] has the bird flu virus? Choose the correct probability notation below and then calculate its associated probability with fourth decimal accuracy.  
Hint: Let N = the event of a [$bird] not having the bird flu virus. Then construct a sample space of all the possible combinations of V and N.

[$popup2->menu]* = [____]

4.1c.) Consider the case where three [@$birds{$bird}@] are drawn at random from the [@$flock{$bird}@]. What is the probability that [$event] [$bird] has the bird flu virus? First complete the declaration of the event variable below:

Let V = The number of [@$birds{$bird}@] with the bird flu virus taken from  [$popup5->menu]* random draw(s) from the [@$flock{$bird}@]. 

Choose the correct probability notation below and then calculate its associated probability with fourth decimal accuracy. Hint: Let N = the event of a [$bird] not having the bird flu virus. Then construct a sample space of all the possible combinations of V and N.

[$popup3->menu]* = [____]


END_PGML

#These weighted values cause errors:  

WEIGHTED_ANS( ($popup4)->cmp, 2 );
WEIGHTED_ANS( ($popup1)->cmp, 8 );
WEIGHTED_ANS( ($ans1)->cmp, 14 );
WEIGHTED_ANS( ($popup2)->cmp, 8 );
WEIGHTED_ANS( ($ans2)->cmp, 24 );
WEIGHTED_ANS( ($popup5)->cmp, 2 );
WEIGHTED_ANS( ($popup3)->cmp, 8 );
WEIGHTED_ANS( ($ans3)->cmp, 34 ); 

# Original form before using popups in PGML
#WEIGHTED_ANS( ($popup4)->cmp(), 2 );
#WEIGHTED_ANS( ($popup1)->cmp(), 8 );
#WEIGHTED_ANS( ($ans1)->cmp(), 14 );
#WEIGHTED_ANS( ($popup2)->cmp(), 8 );
#WEIGHTED_ANS( ($ans2)->cmp(), 24 );
#WEIGHTED_ANS( ($popup5)->cmp(), 2 );
#WEIGHTED_ANS( ($popup3)->cmp(), 8 );
#WEIGHTED_ANS( ($ans3)->cmp(), 32 ); 

BEGIN_PGML_SOLUTION

event = [$event] 

popup3ans = [$popup3ans]
ans3 = [$ans3]

The correct answers are coming....in 2017, Hah!



END_PGML_SOLUTION

ENDDOCUMENT();              

In reply to tim Payer

Re: Weighted Grader errors?

by Davide Cervone -
In perl, string comparisons are performed using different operators than numeric comparisons (this is because numbers in perl are stored as strings and conversion between the two is automatic, so to tell the difference between string and numeric comparisons, they have different operators).

You are using numeric operations where you need to use string ones. Change $event == "more than one" to $event eq "more than one" (and similar for the other comparisons) and you should be in business.

As is stands, you have asked for the two strings to be compared as numbers, and when converted to numbers they are both zero, so the comparison always succeeds.
In reply to tim Payer

Re: Weighted Grader errors?

by Davide Cervone -
You could simplify the the PGML a bit by using [$birds{$bird}] rather than [@$birds{$bird}@] if you have a current version of PGML.pl (you can always download one and put it in your course templates/macros directory if not).

Alternatively, you could do

$birds = $birds{$bird};
$flock = $flock{$bird};
and then use [$birds] and [$flock] in the PGML rather than dereferencing the hashes multiple times.

Just a thought.

In reply to Davide Cervone

Re: Weighted Grader errors?

by tim Payer -
Thank You Davide!

I will try both suggestions.

I really appreciate the detailed feedback from you.

Tim