generated from lambda-feedback/evaluation-function-boilerplate-wolfram
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevaluation_function.wl
More file actions
68 lines (56 loc) · 1.96 KB
/
evaluation_function.wl
File metadata and controls
68 lines (56 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
(* A function to test whether a response is equal to an answer, \
including to within a given tolerance; input and output as
Associations *)
equalQAssociation =
Function[input,
Module[{data, tolerance, correctQ, error, answer, response, params, feedback},
(*Get the evaluation parameters from the incoming request*)
data = input["params"];
answer = data["answer"];
response = data["response"];
params = data["params"];
Print["Loaded Data"];
Print[data];
Print["Processing Response and Answer"];
If[NumericQ[answer],
tolerance =
If[TrueQ[params["tolerance_is_absolute"]],
params["tolerance"],
params["tolerance"] * answer
];
error = Abs[answer - response];
correctQ = TrueQ[error <= tolerance],
error = "not applicable";
correctQ = TrueQ[answer == response]
];
Print["Deciding Feedback"];
feedback =
If[correctQ,
params["correct_response_feedback"],
params["incorrect_response_feedback"]
];
Print["Outputting Response"];
<|
"command" -> "eval",
"result" -> <|
"is_correct" -> correctQ,
"feedback" -> feedback
|>
|>
]
];
(* A function to test whether a response is equal to an answer, \
including to within a given tolerance; input and output as
JSON strings
Calls equalQAssociation *)
equalQJSON = Function[ExportString[equalQAssociation[ImportString[#,
"JSON"] //. List :> Association], "JSON", "Compact" -> True]];
(* A function to test whether a response is equal to an answer, \
including to within a given tolerance; input and output read in from \
external JSON files
Calls equalQAssociation *)
equalQIO = Function[Export[#2, equalQAssociation[Import[#1, "JSON"] //.
List :> Association], "JSON", "Compact" -> True]];
argv = Rest[$ScriptCommandLine];
Print["Running Evaluation"];
equalQIO[argv[[1]], argv[[2]]]