-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathztrans.pl
158 lines (119 loc) · 5.58 KB
/
ztrans.pl
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
:- module(ztrans, []).
:- use_module(library(http/html_write)).
:- use_module(session).
:- use_module(table).
:- use_module(r_session).
:- use_module(library(mcclass)).
:- use_module(mathml).
:- use_module(navbar).
navbar:page(ztrans, [i(z), "-transform (1)"]).
task(ztrans).
:- discontiguous intermediate/2, expert/5, buggy/5, feedback/4, hint/4, r_hook/1.
math_hook(x, 'X').
r_hook(x).
r_hook(sigma).
r_hook(z).
r_hook(p).
r_hook('<-'/2).
render
--> { start(item(X, Mu, Sigma)) },
html(
[ div(class(card), div(class('card-body'),
[ h1(class('card-title'), "Normal distribution"),
p(class('card-text'),
[ "Let ", \mmlm([digits(0)], X), " follow a normal distribution with ",
"expectation ", \mmlm([digits(0)], Mu = r(mu)), " and ",
"standard deviation ", \mmlm([digits(0)], [Sigma = r(sigma), "."]),
" A table of the standard ",
"normal distribution is found below."
])]))]).
task(ztrans)
--> { start(item(_X, _Mu, _Sigma)),
session_data(resp(ztrans, ztrans, Resp), resp(ztrans, ztrans, '.##'))
},
html(\htmlform([ "How many realizations are ",
"below ", \mmlm([digits(0)], [r(x), "?"])], ztrans, Resp)).
% z-transformation and normal distribution
intermediate(ztrans, item).
start(item(x, mu, sigma)).
intermediate(ztrans, pnorm_).
intermediate(ztrans, zcalc).
expert(ztrans, stage(1), From, To, [step(expert, allinone, [])]) :-
From = item(X, Mu, Sigma),
To = { '<-'(z, zcalc(X, Mu, Sigma)) ;
'<-'(p, pnorm_(z))
}.
feedback(allinone, [], _Col, FB) =>
FB = [ "You correctly identified the main steps of the calculation."].
hint(allinone, [], Col, FB) =>
FB = [ "Calculate the z-value and look up the corresponding ", \mmlm(Col, hyph(phi,"value.")) ].
% Expert rule (zcalc)
expert(ztrans, stage(1), From, To, [step(expert, zcalc, [X, Mu, Sigma])]) :-
From = zcalc(X, Mu, Sigma),
To = dfrac(X - Mu, Sigma).
feedback(zcalc, [_X, _Mu, _Sigma], _Col, FB) =>
FB = [ "You correctly calculated Z." ].
hint(zcalc, [X, Mu, Sigma], Col, FB) =>
FB = [ "To calculate the z-value, use " , \mmlm(Col, [dfrac(X - Mu, Sigma), "."]) ].
% Expert rule (correct tail)
expert(ztrans, stage(2), From, To, [step(expert, correct_tail, [Z])]) :-
From = pnorm_(Z),
To = pnorm(Z).
feedback(correct_tail, [_Z], _Col, FB) =>
FB = [ "You calculated the correct tail of the distribution." ].
hint(correct_tail, [_Z], _Col, FB) =>
FB = [ "Use the lower tail of the normal distribution and select the value corresponding to the z-value." ].
% Buggy rule (wrong tail) The wrong tail of the normal distribution was selected.
buggy(ztrans, stage(2), From, To, [step(buggy, wrong_tail, [Z])]) :-
From = pnorm_(Z),
To = instead(wrong_tail, 1 - pnorm(Z), pnorm(Z)).
feedback(wrong_tail, [_Z], Col, FB) =>
FB = [ "Your answer matches the ", \mmlm(Col, color(wrong_tail, "wrong tail" )), " of the normal distribution." ].
hint(wrong_tail, [_Z], _Col, FB) =>
FB = [ "Do not use the upper tail of the normal distribution." ].
% Buggy Rule (plus) Mu was added to X, not subtracted.
buggy(ztrans, stage(2), From, To, [step(buggy, plus, [X, Mu])]) :-
From = dfrac(X - Mu, Sigma),
To = dfrac(instead(plus, X + Mu, X - Mu), Sigma).
feedback(plus, [X, Mu], Col, FB) =>
FB = [ "Subtract ", \mmlm(Col, color(plus, Mu)), " from ", \mmlm(Col, color(plus, X)),
" instead of adding them up." ].
hint(plus, [X, Mu], Col, FB) =>
FB = [ "Try using subtraction rather than addition in ",
\mmlm(Col, [color(plus, X + Mu), "."]) ].
% Buggy Rule (swap) Mu and Sigma were swapped.
buggy(ztrans, stage(1), From, To, [step(buggy, swap, [mu, sigma])]) :-
From = item(x, mu, sigma),
To = item(x, instead(swap, sigma, mu), instead(swap, mu, sigma));
From = item(x, mu, sigma^2),
To = item(x, instead(swap, sigma^2, mu), instead(swap, mu, sigma)).
feedback(swap, [Mu, Sigma], Col, FB) =>
FB = [ "You swapped ", \mmlm(Col, color(swap, Mu)), " and ",
\mmlm(Col, [color(swap, Sigma), "."]) ].
hint(swap, [Mu, Sigma], Col, FB) =>
FB = [ "Try using ", \mmlm(Col, color(swap, Mu)), " and ",
\mmlm(Col, color(swap, Sigma)), " in a different configuration." ].
% Buggy Rule (vardev swap) standard deviation was mistaken with variance.
buggy(ztrans, stage(1), From, To, [step(buggy, vardev_swap, [sigma])]) :-
From = item(x, mu, sigma),
To = item(x, mu, instead(vardev_swap, sigma^2, sigma)).
feedback(vardev_swap, [sigma], Col, FB) =>
FB = [ "You squared ", \mmlm(Col, color(vardev_swap, sigma)), " by mistake." ].
hint(vardev_swap, [sigma], Col, FB) =>
FB = [ "Use ", \mmlm(Col, color(vardev_swap, sigma)), " instead of ", \mmlm(Col, [color(vardev_swap, sigma^2), "."]) ].
% Buggy Rule (xp) (x - mu)/sigma was skipped.
buggy(ztrans, stage(2), From, To, [step(buggy, xp, []), depends(xp2)]) :-
From = dfrac(x - mu, sigma),
To = omit_right(xp, dfrac(omit_right(xp, x - mu), sigma)).
feedback(xp, [], Col, FB) =>
FB = [ "The z-value is calculated by using the formula ", \mmlm(Col, [dfrac(x - mu, sigma), "."]) ].
hint(xp, [], _Col, FB) =>
FB = [ "Remember to calculate the z-value." ].
% Buggy Rule (xp2) x/100 was taken to be phi(z).
buggy(ztrans, stage(2), From, To, [step(buggy, xp2, []), depends(xp)]) :-
From = pnorm_(z),
To = instead(xp2, z/100, pnorm(z)).
feedback(xp2, [], _Col, FB) =>
FB = [ "You mistakenly divided the z-value by 100 instead of retrieving the value from the normal distribution." ].
hint(xp2, [], _Col, FB) =>
FB = [ "Do not divide the z-value by 100, use the normal distribution instead." ].