Deming's funnel: Difference between revisions

Content added Content deleted
(julia example)
m (label plots)
Line 559: Line 559:


=={{header|Julia}}==
=={{header|Julia}}==
<lang julia>
<lang julia># Run from Julia REPL to see the plots.
# Run from Julia REPL to see the plots.
using Statistics, Distributions, Plots
using Statistics, Distributions, Plots

const racket_xdata = [-0.533, 0.270, 0.859, -0.043, -0.205, -0.127, -0.071, 0.275, 1.251, -0.231,
const racket_xdata = [-0.533, 0.270, 0.859, -0.043, -0.205, -0.127, -0.071, 0.275, 1.251, -0.231,
-0.401, 0.269, 0.491, 0.951, 1.150, 0.001, -0.382, 0.161, 0.915, 2.080, -2.337,
-0.401, 0.269, 0.491, 0.951, 1.150, 0.001, -0.382, 0.161, 0.915, 2.080, -2.337,
Line 573: Line 572:
-0.289, 0.521, 0.017, 0.281, -0.749, -0.149, -2.436, -0.909, 0.394, -0.113, -0.598,
-0.289, 0.521, 0.017, 0.281, -0.749, -0.149, -2.436, -0.909, 0.394, -0.113, -0.598,
0.443, -0.521, -0.799, 0.087]
0.443, -0.521, -0.799, 0.087]

const racket_ydata = [0.136, 0.717, 0.459, -0.225, 1.392, 0.385, 0.121, -0.395, 0.490, -0.682, -0.065,
const racket_ydata = [0.136, 0.717, 0.459, -0.225, 1.392, 0.385, 0.121, -0.395, 0.490, -0.682, -0.065,
0.242, -0.288, 0.658, 0.459, 0.000, 0.426, 0.205, -0.765, -2.188, -0.742, -0.010,
0.242, -0.288, 0.658, 0.459, 0.000, 0.426, 0.205, -0.765, -2.188, -0.742, -0.010,
Line 583: Line 582:
0.721, 0.104, -0.729, 0.650, -1.103, 0.154, -1.720, 0.051, -0.385, 0.477, 1.537,
0.721, 0.104, -0.729, 0.650, -1.103, 0.154, -1.720, 0.051, -0.385, 0.477, 1.537,
-0.901, 0.939, -0.411, 0.341, -0.411, 0.106, 0.224, -0.947, -1.424, -0.542, -1.032]
-0.901, 0.939, -0.411, 0.341, -0.411, 0.106, 0.224, -0.947, -1.424, -0.542, -1.032]

const rules = [(x, y, dx, dy) -> [0, 0], (x, y, dx, dy) -> [-dx, -dy],
const rules = [(x, y, dx, dy) -> [0, 0], (x, y, dx, dy) -> [-dx, -dy],
(x, y, dx, dy) -> [-x - dx, -y - dy], (x, y, dx, dy) -> [x + dx, y + dy]]
(x, y, dx, dy) -> [-x - dx, -y - dy], (x, y, dx, dy) -> [x + dx, y + dy]]
const colors = [:red, :green, :blue, :yellow]
const plots, colors = Any[0, 0], [:red, :green, :blue, :yellow]

function makedata()
function makedata()
radius_angles = zip(rand(Normal(), 100), rand(Uniform(-π, π), 100))
radius_angles = zip(rand(Normal(), 100), rand(Uniform(-π, π), 100))
zip([z[1] * cos(z[2]) for z in radius_angles], [z[1] * sin(z[2]) for z in radius_angles])
zip([z[1] * cos(z[2]) for z in radius_angles], [z[1] * sin(z[2]) for z in radius_angles])
end
end

function testfunnel(useracket=true)
function testfunnel(useracket=true)
for (i, rule) in enumerate(rules)
for (i, rule) in enumerate(rules)
Line 605: Line 604:
println("mean x: ", round(mean(xvec), digits=4), " std x: ", round(std(xvec, corrected=false), digits=4),
println("mean x: ", round(mean(xvec), digits=4), " std x: ", round(std(xvec, corrected=false), digits=4),
" mean y: ", round(mean(yvec), digits=4), " std y: ", round(std(yvec, corrected=false), digits=4))
" mean y: ", round(mean(yvec), digits=4), " std y: ", round(std(yvec, corrected=false), digits=4))
plt = scatter!(xvec, yvec, color=colors[i])
plots[useracket ? 1 : 2] = scatter!(xvec, yvec, color=colors[i],
title= useracket ? "Racket Data" : "Random Data", label="Rule $i")
display(plt)
end
end
end
end

println("\nUsing Racket data.")
println("\nUsing Racket data.")
testfunnel()
testfunnel()
println("\nUsing new data.")
println("\nUsing new data.")
testfunnel(false)
testfunnel(false)
plot(plots[1], plots[2], layout=2)
</lang>{{out}}
</lang>{{out}}
<pre>
<pre>
Line 636: Line 636:
mean x: -6.7132 std x: 4.5367 mean y: 1.632 std y: 2.0975
mean x: -6.7132 std x: 4.5367 mean y: 1.632 std y: 2.0975
</pre>
</pre>




=={{header|Kotlin}}==
=={{header|Kotlin}}==