Grading functions

When you edit a question, Wiris Quizzes provides a wide range of options for comparing the student's answer to the correct answer. These involve decimal digits, units, simplification, etc. (everything in the Validation tab). However, sometimes we will find that it's necessary to create our own rule for determining when an answer is correct. This can be done via grading functions. A grading function is a user-defined formula that takes the student's answer and decides whether it is correct or not. This allows for even more specificity than with the options found on the Validation tab.

A grading function is a function of one or more variables (see grading functions and compound answers) defined in the Variables tab, that returns a number between 0 and 1. The number returned by the function in for each input corresponds to the mark out of 1.00 that will be received for that answer. In the first example, the values returned were either true or false, which is the same as 0 (no marks) or 1 (full marks). For an example using more values between 0 and 1, see custom marks.

Every time we wish to use a grading function, we must select it as the option in the Validation tab, and type the name of the function in the blank. Scroll down for more examples.

Let's suppose that we want to ask the question "Give a prime number". For this, we need to use a grading function.

First, let's create the grading function. This is done in the Variables tab. In this example, the grading function will be called g f.

Wiris CAS CalcMe

The function we've defined, g f left parenthesis x right parenthesis, returns true if x is prime, and false otherwise. To use this as the validation method, select "grading function" in the Validation tab. Then, use the name of the grading function in the blank, in this case, "gf".

As for the Correct Answer tab, anything will work. Since we've selected "grading function" as the validation method, the output of the grading function is the only thing that determines correct answers. In this case, we could input a prime number, for example.

We'll show a simple example of a grading function with several outputs. The idea will be to award more marks for every level of correctness in the answer.

We want to ask the following question in basic arithmetic:

with partial credit awarded for each correct property of the answer the student gives. Say these are young children, and we consider the hardest part to be correctly giving a number whose remainder is 2 when divided by 7. We'll award 0.4 marks for that, and 0.3 for each of the other properties. Additionally, we want to only give half marks for the rest of the properties, if the answer fails in the first one (this is the purpose of decrease_mark).

Wiris CAS CalcMe

Observe that to make a longer grading function with multiple conditionals and calculations, we need to enclose it with the begin..end statements and use return to define the output of the function.

The question is completed now. Make sure to tick the "grading function" option in the Validation tab as described earlier, and give any particular correct value in the Correct Answer tab. We can see that both of these responses are correct:

We've used a fairly simple question as an example, but we can already see that grading functions can be made to have a very customized and complex design.

LIVE DEMO

We can also create grading functions in the case of compound answer questions. All we need to do is use a separate argument for each answer blank. So, if there are three blanks to fill in, the grading function should look something like gf(x,y,z). The first argument corresponds to the first blank, the second argument corresponds to the second blank, and so on. Let's see a simple example.

The question will be a standard exercise in introductory calculus:

For this, the following grading function could be used:

Wiris CAS CalcMe

The advantage in this case, as opposed to ordinary compound answers, is that we don't need to worry about the order in which the student answers. It also allows virtually infinite answers (here any answer of the form 8 k plus 1 with k an integer, was valid). However much more intricate behavior can be programmed, as is easily seen.

LIVE DEMO

Imagine that we are working with a compound answer like in compound answers. It may happen that the student leave a box empty and just answers one question. If you want to grade the answer he had submitted you need to modify the algorithm and test that the box is not empty with the command not_null?. For instance, following the same example above

Recall that in the Correct Answer tab, we need to distribute the grade as we wish.

It is important to read this section if we wish to create questions involving vectors. The key point is that vectors are actually passed to the grading function as matrices, so we need to de-index them inside the function body to do normal vector operations with them. This should all be clear with the following basic example.

What this all essentially means is that if we pass [...] to a grading function, it will be taken as [ [...] ] (a list with the original vector as its only element). As a result, we cannot do vector operations with it. For example, the vector

Wiris CAS CalcMe

will be converted to

Wiris CAS CalcMe

How do we access the original vector? It is the first (and only) element of a list, so as with any list we may access the first element with the subindex "1", as so:

Wiris CAS CalcMe

So if "v" was the original vector given by the student and passed to the grading function, to treat it as a vector we simply need to write "v1" wherever we would like to use "v". Let's look at this with some examples.

Example 1

The matrix has rank 2, so there will be infinite solutions, meaning that we have to use a grading function if we want to allow any possible solution. The function itself is quite simple, but observe that we used the subindex as described above:

Wiris CAS CalcMe

The other case we need to cover is allowing students to answer with a row or column vectors (until now we've only assumed row vectors). We'll illustrate what needs to be done with an example. Using the same question as before, let's say the student responds like so:

This is a column vector, and it is treated differently. All we need to do, though, is transpose it and we are back to the previous case. We most likely want to allow both types of answers, so at the beginning of the original grading function, we might add the following:

Wiris CAS CalcMe

We've added an if statement that simply detects if the input is a column vector (by seeing if the number of columns is 1), and transposes it in that case. If not, then nothing is done to "v". The result is that in all cases "v" will be of the form [ [...] ], and after that, we can use subindices exactly as described previously.

LIVE DEMO

Example 2

Imagine we want to ask the students the following question:

In this example, we clearly need a grading function since there are infinite correct answers.

The first answer is a point but it is understood as a matrix with one row and two columns instead: open parentheses table row cell negative 7 end cell 7 end table close parentheses. Thus, if we want to work with the actual point, we have to retrieve the first row. Moreover, we have to tell CalcMe that it is a point (otherwise it will work with a vector). The first part of the grading function would be

The second answer is a vector, but as before it is understood as a matrix. Similarly, we have to access to its first row. The whole algorithm for this question would be