Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
2
Task/Demings-funnel/00-META.yaml
Normal file
2
Task/Demings-funnel/00-META.yaml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
from: http://rosettacode.org/wiki/Deming's_funnel
|
||||
20
Task/Demings-funnel/00-TASK.txt
Normal file
20
Task/Demings-funnel/00-TASK.txt
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
[[wp:W. Edwards Deming|W Edwards Deming]] was an American statistician and management guru who used physical demonstrations to illuminate his teachings. In one demonstration Deming repeatedly dropped marbles through a funnel at a target, marking where they landed, and observing the resulting pattern. He applied a sequence of "rules" to try to improve performance. In each case the experiment begins with the funnel positioned directly over the target.
|
||||
|
||||
* '''Rule 1''': The funnel remains directly above the target.
|
||||
* '''Rule 2''': Adjust the funnel position by shifting the target to compensate after each drop. E.g. If the last drop missed 1 cm east, move the funnel 1 cm to the west of its current position.
|
||||
* '''Rule 3''': As rule 2, but first move the funnel back over the target, before making the adjustment. E.g. If the funnel is 2 cm north, and the marble lands 3 cm north, move the funnel 3 cm south of the target.
|
||||
* '''Rule 4''': The funnel is moved directly over the last place a marble landed.
|
||||
|
||||
Apply the four rules to the set of 50 pseudorandom displacements provided (e.g in the Racket solution) for the dxs and dys. '''Output''': calculate the mean and standard-deviations of the resulting x and y values for each rule.
|
||||
|
||||
Note that rules 2, 3, and 4 give successively worse results. Trying to deterministically compensate for a random process is counter-productive, but -- according to Deming -- quite a popular pastime: see the Further Information, below for examples.
|
||||
|
||||
'''Stretch goal 1''': Generate fresh pseudorandom data. The radial displacement of the drop from the funnel position is given by a Gaussian distribution (standard deviation is 1.0) and the angle of displacement is uniformly distributed.
|
||||
|
||||
'''Stretch goal 2''': Show scatter plots of all four results.
|
||||
|
||||
|
||||
;Further information:
|
||||
* Further [http://blog.newsystemsthinking.com/w-edwards-deming-and-the-funnel-experiment/ explanation and interpretation]
|
||||
* [https://www.youtube.com/watch?v=2VogtYRc9dA Video demonstration] of the funnel experiment at the Mayo Clinic.
|
||||
|
||||
49
Task/Demings-funnel/11l/demings-funnel.11l
Normal file
49
Task/Demings-funnel/11l/demings-funnel.11l
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
V dxs = [-0.533, 0.27, 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.15, 0.001, -0.382, 0.161, 0.915,
|
||||
2.08, -2.337, 0.034, -0.126, 0.014, 0.709, 0.129, -1.093, -0.483, -1.193,
|
||||
0.02, -0.051, 0.047, -0.095, 0.695, 0.34, -0.182, 0.287, 0.213, -0.423,
|
||||
-0.021, -0.134, 1.798, 0.021, -1.099, -0.361, 1.636, -1.134, 1.315, 0.201,
|
||||
0.034, 0.097, -0.17, 0.054, -0.553, -0.024, -0.181, -0.7, -0.361, -0.789,
|
||||
0.279, -0.174, -0.009, -0.323, -0.658, 0.348, -0.528, 0.881, 0.021, -0.853,
|
||||
0.157, 0.648, 1.774, -1.043, 0.051, 0.021, 0.247, -0.31, 0.171, 0.0, 0.106,
|
||||
0.024, -0.386, 0.962, 0.765, -0.125, -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]
|
||||
|
||||
V dys = [0.136, 0.717, 0.459, -0.225, 1.392, 0.385, 0.121, -0.395, 0.49, -0.682,
|
||||
-0.065, 0.242, -0.288, 0.658, 0.459, 0.0, 0.426, 0.205, -0.765, -2.188,
|
||||
-0.742, -0.01, 0.089, 0.208, 0.585, 0.633, -0.444, -0.351, -1.087, 0.199,
|
||||
0.701, 0.096, -0.025, -0.868, 1.051, 0.157, 0.216, 0.162, 0.249, -0.007,
|
||||
0.009, 0.508, -0.79, 0.723, 0.881, -0.508, 0.393, -0.226, 0.71, 0.038,
|
||||
-0.217, 0.831, 0.48, 0.407, 0.447, -0.295, 1.126, 0.38, 0.549, -0.445,
|
||||
-0.046, 0.428, -0.074, 0.217, -0.822, 0.491, 1.347, -0.141, 1.23, -0.044,
|
||||
0.079, 0.219, 0.698, 0.275, 0.056, 0.031, 0.421, 0.064, 0.721, 0.104,
|
||||
-0.729, 0.65, -1.103, 0.154, -1.72, 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]
|
||||
|
||||
F funnel(dxs, rule)
|
||||
V x = 0.0
|
||||
[Float] rxs
|
||||
L(dx) dxs
|
||||
rxs.append(x + dx)
|
||||
x = rule(x, dx)
|
||||
R rxs
|
||||
|
||||
F mean(xs)
|
||||
R sum(xs) / xs.len
|
||||
|
||||
F stddev(xs)
|
||||
V m = mean(xs)
|
||||
R sqrt(sum(xs.map(x -> (x - @m) ^ 2)) / xs.len)
|
||||
|
||||
F experiment(label, rule)
|
||||
V (rxs, rys) = (funnel(:dxs, rule), funnel(:dys, rule))
|
||||
print(label)
|
||||
print(‘Mean x, y : #.4, #.4’.format(mean(rxs), mean(rys)))
|
||||
print(‘Std dev x, y : #.4, #.4’.format(stddev(rxs), stddev(rys)))
|
||||
print()
|
||||
|
||||
experiment(‘Rule 1:’, (z, dz) -> 0)
|
||||
experiment(‘Rule 2:’, (z, dz) -> -dz)
|
||||
experiment(‘Rule 3:’, (z, dz) -> -(z + dz))
|
||||
experiment(‘Rule 4:’, (z, dz) -> z + dz)
|
||||
105
Task/Demings-funnel/Ada/demings-funnel.ada
Normal file
105
Task/Demings-funnel/Ada/demings-funnel.ada
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
with Ada.Numerics.Elementary_Functions;
|
||||
with Ada.Text_IO;
|
||||
|
||||
procedure Demings_Funnel is
|
||||
|
||||
type Float_List is array (Positive range <>) of Float;
|
||||
|
||||
Dxs : constant Float_List :=
|
||||
(-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.034, -0.126, 0.014,
|
||||
0.709, 0.129, -1.093, -0.483, -1.193, 0.020, -0.051, 0.047,
|
||||
-0.095, 0.695, 0.340, -0.182, 0.287, 0.213, -0.423, -0.021,
|
||||
-0.134, 1.798, 0.021, -1.099, -0.361, 1.636, -1.134, 1.315,
|
||||
0.201, 0.034, 0.097, -0.170, 0.054, -0.553, -0.024, -0.181,
|
||||
-0.700, -0.361, -0.789, 0.279, -0.174, -0.009, -0.323, -0.658,
|
||||
0.348, -0.528, 0.881, 0.021, -0.853, 0.157, 0.648, 1.774,
|
||||
-1.043, 0.051, 0.021, 0.247, -0.310, 0.171, 0.000, 0.106,
|
||||
0.024, -0.386, 0.962, 0.765, -0.125, -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);
|
||||
|
||||
Dys : constant Float_List :=
|
||||
( 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.089, 0.208,
|
||||
0.585, 0.633, -0.444, -0.351, -1.087, 0.199, 0.701, 0.096,
|
||||
-0.025, -0.868, 1.051, 0.157, 0.216, 0.162, 0.249, -0.007,
|
||||
0.009, 0.508, -0.790, 0.723, 0.881, -0.508, 0.393, -0.226,
|
||||
0.710, 0.038, -0.217, 0.831, 0.480, 0.407, 0.447, -0.295,
|
||||
1.126, 0.380, 0.549, -0.445, -0.046, 0.428, -0.074, 0.217,
|
||||
-0.822, 0.491, 1.347, -0.141, 1.230, -0.044, 0.079, 0.219,
|
||||
0.698, 0.275, 0.056, 0.031, 0.421, 0.064, 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);
|
||||
|
||||
type Rule_Access is access function (Z, Dz : Float) return Float;
|
||||
|
||||
function Funnel (List : in Float_List;
|
||||
Rule : in Rule_Access)
|
||||
return Float_List
|
||||
is
|
||||
Correc : Float := 0.0;
|
||||
Result : Float_List (List'Range);
|
||||
begin
|
||||
for I in List'Range loop
|
||||
Result (I) := Correc + List (I);
|
||||
Correc := Rule (Correc, List (I));
|
||||
end loop;
|
||||
return Result;
|
||||
end Funnel;
|
||||
|
||||
function Mean (List : in Float_List)
|
||||
return Float
|
||||
is
|
||||
Sum : Float := 0.0;
|
||||
begin
|
||||
for Value of List loop
|
||||
Sum := Sum + Value;
|
||||
end loop;
|
||||
return Sum / Float (List'Length);
|
||||
end Mean;
|
||||
|
||||
function Stddev (List : in Float_List)
|
||||
return Float
|
||||
is
|
||||
use Ada.Numerics.Elementary_Functions;
|
||||
M : constant Float := Mean (List);
|
||||
Sum : Float := 0.0;
|
||||
begin
|
||||
for F of List loop
|
||||
Sum := Sum + (F - M) * (F - M);
|
||||
end loop;
|
||||
return Sqrt (Sum / Float (List'Length));
|
||||
end Stddev;
|
||||
|
||||
procedure Experiment (Label : in String;
|
||||
Rule : in Rule_Access)
|
||||
is
|
||||
package Float_IO is new Ada.Text_IO.Float_IO (Float);
|
||||
use Ada.Text_IO;
|
||||
use Float_IO;
|
||||
Rxs : constant Float_List := Funnel (Dxs, Rule);
|
||||
Rys : constant Float_List := Funnel (Dys, Rule);
|
||||
begin
|
||||
Default_Exp := 0;
|
||||
Default_Fore := 4;
|
||||
Default_Aft := 4;
|
||||
Put_Line (Label & " : x y");
|
||||
Put ("Mean: "); Put (Mean (Rxs)); Put (Mean (Rys)); New_Line;
|
||||
Put ("StdDev: "); Put (Stddev (Rxs)); Put (Stddev (Rys)); New_Line;
|
||||
New_Line;
|
||||
end Experiment;
|
||||
|
||||
function Rule_1 (Z, Dz : Float) return Float is (0.0);
|
||||
function Rule_2 (Z, Dz : Float) return Float is (-Dz);
|
||||
function Rule_3 (Z, Dz : Float) return Float is (-Z - Dz);
|
||||
function Rule_4 (Z, Dz : Float) return Float is (Z + Dz);
|
||||
begin
|
||||
Experiment ("Rule 1", Rule_1'Access);
|
||||
Experiment ("Rule 2", Rule_2'Access);
|
||||
Experiment ("Rule 3", Rule_3'Access);
|
||||
Experiment ("Rule 4", Rule_4'Access);
|
||||
end Demings_Funnel;
|
||||
60
Task/Demings-funnel/Arturo/demings-funnel.arturo
Normal file
60
Task/Demings-funnel/Arturo/demings-funnel.arturo
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
Dxs: @[
|
||||
neg 0.533, 0.270, 0.859, neg 0.043, neg 0.205, neg 0.127, neg 0.071, 0.275,
|
||||
1.251, neg 0.231, neg 0.401, 0.269, 0.491, 0.951, 1.150, 0.001,
|
||||
neg 0.382, 0.161, 0.915, 2.080, neg 2.337, 0.034, neg 0.126, 0.014,
|
||||
0.709, 0.129, neg 1.093, neg 0.483, neg 1.193, 0.020, neg 0.051, 0.047,
|
||||
neg 0.095, 0.695, 0.340, neg 0.182, 0.287, 0.213, neg 0.423, neg 0.021,
|
||||
neg 0.134, 1.798, 0.021, neg 1.099, neg 0.361, 1.636, neg 1.134, 1.315,
|
||||
0.201, 0.034, 0.097, neg 0.170, 0.054, neg 0.553, neg 0.024, neg 0.181,
|
||||
neg 0.700, neg 0.361, neg 0.789, 0.279, neg 0.174, neg 0.009, neg 0.323, neg 0.658,
|
||||
0.348, neg 0.528, 0.881, 0.021, neg 0.853, 0.157, 0.648, 1.774,
|
||||
neg 1.043, 0.051, 0.021, 0.247, neg 0.310, 0.171, 0.000, 0.106,
|
||||
0.024, neg 0.386, 0.962, 0.765, neg 0.125, neg 0.289, 0.521, 0.017,
|
||||
0.281, neg 0.749, neg 0.149, neg 2.436, neg 0.909, 0.394, neg 0.113, neg 0.598,
|
||||
0.443, neg 0.521, neg 0.799, 0.087
|
||||
]
|
||||
|
||||
Dys: @[
|
||||
0.136, 0.717, 0.459, neg 0.225, 1.392, 0.385, 0.121, neg 0.395,
|
||||
0.490, neg 0.682, neg 0.065, 0.242, neg 0.288, 0.658, 0.459, 0.000,
|
||||
0.426, 0.205, neg 0.765, neg 2.188, neg 0.742, neg 0.010, 0.089, 0.208,
|
||||
0.585, 0.633, neg 0.444, neg 0.351, neg 1.087, 0.199, 0.701, 0.096,
|
||||
neg 0.025, neg 0.868, 1.051, 0.157, 0.216, 0.162, 0.249, neg 0.007,
|
||||
0.009, 0.508, neg 0.790, 0.723, 0.881, neg 0.508, 0.393, neg 0.226,
|
||||
0.710, 0.038, neg 0.217, 0.831, 0.480, 0.407, 0.447, neg 0.295,
|
||||
1.126, 0.380, 0.549, neg 0.445, neg 0.046, 0.428, neg 0.074, 0.217,
|
||||
neg 0.822, 0.491, 1.347, neg 0.141, 1.230, neg 0.044, 0.079, 0.219,
|
||||
0.698, 0.275, 0.056, 0.031, 0.421, 0.064, 0.721, 0.104,
|
||||
neg 0.729, 0.650, neg 1.103, 0.154, neg 1.720, 0.051, neg 0.385, 0.477,
|
||||
1.537, neg 0.901, 0.939, neg 0.411, 0.341, neg 0.411, 0.106, 0.224,
|
||||
neg 0.947, neg 1.424, neg 0.542, neg 1.032
|
||||
]
|
||||
|
||||
funnel: function [a, rule][
|
||||
x: 0.0
|
||||
result: []
|
||||
loop a 'val [
|
||||
'result ++ x + val
|
||||
x: do rule
|
||||
]
|
||||
return result
|
||||
]
|
||||
|
||||
formatFloat: function [f]->
|
||||
to :string .format:"7.4f" f
|
||||
|
||||
experiment: function [label, rule][
|
||||
rxs: funnel Dxs rule
|
||||
rys: funnel Dys rule
|
||||
|
||||
print label
|
||||
print repeat "=" 30
|
||||
print ["Mean x,y :" formatFloat average rxs, formatFloat average rys]
|
||||
print ["Std.dev x,y :" formatFloat deviation rxs, formatFloat deviation rys]
|
||||
print ""
|
||||
]
|
||||
|
||||
experiment "Rule 1" [0.0]
|
||||
experiment "Rule 2" [neg val]
|
||||
experiment "Rule 3" [neg x + val]
|
||||
experiment "Rule 4" [x + val]
|
||||
77
Task/Demings-funnel/D/demings-funnel.d
Normal file
77
Task/Demings-funnel/D/demings-funnel.d
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
import std.stdio, std.math, std.algorithm, std.range, std.typecons;
|
||||
|
||||
auto mean(T)(in T[] xs) pure nothrow @nogc {
|
||||
return xs.sum / xs.length;
|
||||
}
|
||||
|
||||
auto stdDev(T)(in T[] xs) pure nothrow {
|
||||
immutable m = xs.mean;
|
||||
return sqrt(xs.map!(x => (x - m) ^^ 2).sum / xs.length);
|
||||
}
|
||||
|
||||
alias TF = double function(in double, in double) pure nothrow @nogc;
|
||||
|
||||
auto funnel(T)(in T[] dxs, in T[] dys, in TF rule) {
|
||||
T x = 0, y = 0;
|
||||
immutable(T)[] rxs, rys;
|
||||
|
||||
foreach (const dx, const dy; zip(dxs, dys)) {
|
||||
immutable rx = x + dx;
|
||||
immutable ry = y + dy;
|
||||
x = rule(x, dx);
|
||||
y = rule(y, dy);
|
||||
rxs ~= rx;
|
||||
rys ~= ry;
|
||||
}
|
||||
|
||||
return tuple!("x", "y")(rxs, rys);
|
||||
}
|
||||
|
||||
void experiment(T)(in string label,
|
||||
in T[] dxs, in T[] dys, in TF rule) {
|
||||
//immutable (rxs, rys) = funnel(dxs, dys, rule);
|
||||
immutable rs = funnel(dxs, dys, rule);
|
||||
label.writeln;
|
||||
writefln("Mean x, y: %.4f, %.4f", rs.x.mean, rs.y.mean);
|
||||
writefln("Std dev x, y: %.4f, %.4f", rs.x.stdDev, rs.y.stdDev);
|
||||
writeln;
|
||||
}
|
||||
|
||||
void main() {
|
||||
immutable dxs = [
|
||||
-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.034, -0.126, 0.014,
|
||||
0.709, 0.129, -1.093, -0.483, -1.193, 0.020, -0.051, 0.047,
|
||||
-0.095, 0.695, 0.340, -0.182, 0.287, 0.213, -0.423, -0.021,
|
||||
-0.134, 1.798, 0.021, -1.099, -0.361, 1.636, -1.134, 1.315,
|
||||
0.201, 0.034, 0.097, -0.170, 0.054, -0.553, -0.024, -0.181,
|
||||
-0.700, -0.361, -0.789, 0.279, -0.174, -0.009, -0.323, -0.658,
|
||||
0.348, -0.528, 0.881, 0.021, -0.853, 0.157, 0.648, 1.774,
|
||||
-1.043, 0.051, 0.021, 0.247, -0.310, 0.171, 0.000, 0.106,
|
||||
0.024, -0.386, 0.962, 0.765, -0.125, -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];
|
||||
|
||||
immutable dys = [
|
||||
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.089, 0.208,
|
||||
0.585, 0.633, -0.444, -0.351, -1.087, 0.199, 0.701, 0.096,
|
||||
-0.025, -0.868, 1.051, 0.157, 0.216, 0.162, 0.249, -0.007,
|
||||
0.009, 0.508, -0.790, 0.723, 0.881, -0.508, 0.393, -0.226,
|
||||
0.710, 0.038, -0.217, 0.831, 0.480, 0.407, 0.447, -0.295,
|
||||
1.126, 0.380, 0.549, -0.445, -0.046, 0.428, -0.074, 0.217,
|
||||
-0.822, 0.491, 1.347, -0.141, 1.230, -0.044, 0.079, 0.219,
|
||||
0.698, 0.275, 0.056, 0.031, 0.421, 0.064, 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];
|
||||
|
||||
static assert(dxs.length == dys.length);
|
||||
|
||||
experiment("Rule 1:", dxs, dys, (z, dz) => 0.0);
|
||||
experiment("Rule 2:", dxs, dys, (z, dz) => -dz);
|
||||
experiment("Rule 3:", dxs, dys, (z, dz) => -(z + dz));
|
||||
experiment("Rule 4:", dxs, dys, (z, dz) => z + dz);
|
||||
}
|
||||
56
Task/Demings-funnel/Elixir/demings-funnel.elixir
Normal file
56
Task/Demings-funnel/Elixir/demings-funnel.elixir
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
defmodule Deming do
|
||||
def funnel(dxs, rule) do
|
||||
{_, rxs} = Enum.reduce(dxs, {0, []}, fn dx,{x,rxs} ->
|
||||
{rule.(x, dx), [x + dx | rxs]}
|
||||
end)
|
||||
rxs
|
||||
end
|
||||
|
||||
def mean(xs), do: Enum.sum(xs) / length(xs)
|
||||
|
||||
def stddev(xs) do
|
||||
m = mean(xs)
|
||||
Enum.reduce(xs, 0.0, fn x,sum -> sum + (x-m)*(x-m) / length(xs) end)
|
||||
|> :math.sqrt
|
||||
end
|
||||
|
||||
def experiment(label, dxs, dys, rule) do
|
||||
{rxs, rys} = {funnel(dxs, rule), funnel(dys, rule)}
|
||||
IO.puts label
|
||||
:io.format "Mean x, y : ~7.4f, ~7.4f~n", [mean(rxs), mean(rys)]
|
||||
:io.format "Std dev x, y : ~7.4f, ~7.4f~n~n", [stddev(rxs), stddev(rys)]
|
||||
end
|
||||
end
|
||||
|
||||
dxs = [ -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.034, -0.126, 0.014,
|
||||
0.709, 0.129, -1.093, -0.483, -1.193, 0.020, -0.051, 0.047,
|
||||
-0.095, 0.695, 0.340, -0.182, 0.287, 0.213, -0.423, -0.021,
|
||||
-0.134, 1.798, 0.021, -1.099, -0.361, 1.636, -1.134, 1.315,
|
||||
0.201, 0.034, 0.097, -0.170, 0.054, -0.553, -0.024, -0.181,
|
||||
-0.700, -0.361, -0.789, 0.279, -0.174, -0.009, -0.323, -0.658,
|
||||
0.348, -0.528, 0.881, 0.021, -0.853, 0.157, 0.648, 1.774,
|
||||
-1.043, 0.051, 0.021, 0.247, -0.310, 0.171, 0.000, 0.106,
|
||||
0.024, -0.386, 0.962, 0.765, -0.125, -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]
|
||||
|
||||
dys = [ 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.089, 0.208,
|
||||
0.585, 0.633, -0.444, -0.351, -1.087, 0.199, 0.701, 0.096,
|
||||
-0.025, -0.868, 1.051, 0.157, 0.216, 0.162, 0.249, -0.007,
|
||||
0.009, 0.508, -0.790, 0.723, 0.881, -0.508, 0.393, -0.226,
|
||||
0.710, 0.038, -0.217, 0.831, 0.480, 0.407, 0.447, -0.295,
|
||||
1.126, 0.380, 0.549, -0.445, -0.046, 0.428, -0.074, 0.217,
|
||||
-0.822, 0.491, 1.347, -0.141, 1.230, -0.044, 0.079, 0.219,
|
||||
0.698, 0.275, 0.056, 0.031, 0.421, 0.064, 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]
|
||||
|
||||
Deming.experiment("Rule 1:", dxs, dys, fn _z, _dz -> 0 end)
|
||||
Deming.experiment("Rule 2:", dxs, dys, fn _z, dz -> -dz end)
|
||||
Deming.experiment("Rule 3:", dxs, dys, fn z, dz -> -(z+dz) end)
|
||||
Deming.experiment("Rule 4:", dxs, dys, fn z, dz -> z+dz end)
|
||||
44
Task/Demings-funnel/Factor/demings-funnel.factor
Normal file
44
Task/Demings-funnel/Factor/demings-funnel.factor
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
USING: combinators formatting generalizations grouping.extras io
|
||||
kernel math math.statistics sequences ;
|
||||
|
||||
: show ( seq1 seq2 -- )
|
||||
[ [ mean ] bi@ ] [ [ population-std ] bi@ ] 2bi
|
||||
"Mean x, y : %.4f, %.4f\nStd dev x, y : %.4f, %.4f\n"
|
||||
printf ;
|
||||
|
||||
{
|
||||
-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.034 -0.126 0.014
|
||||
0.709 0.129 -1.093 -0.483 -1.193 0.020 -0.051 0.047
|
||||
-0.095 0.695 0.340 -0.182 0.287 0.213 -0.423 -0.021
|
||||
-0.134 1.798 0.021 -1.099 -0.361 1.636 -1.134 1.315
|
||||
0.201 0.034 0.097 -0.170 0.054 -0.553 -0.024 -0.181
|
||||
-0.700 -0.361 -0.789 0.279 -0.174 -0.009 -0.323 -0.658
|
||||
0.348 -0.528 0.881 0.021 -0.853 0.157 0.648 1.774
|
||||
-1.043 0.051 0.021 0.247 -0.310 0.171 0.000 0.106
|
||||
0.024 -0.386 0.962 0.765 -0.125 -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.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.089 0.208
|
||||
0.585 0.633 -0.444 -0.351 -1.087 0.199 0.701 0.096
|
||||
-0.025 -0.868 1.051 0.157 0.216 0.162 0.249 -0.007
|
||||
0.009 0.508 -0.790 0.723 0.881 -0.508 0.393 -0.226
|
||||
0.710 0.038 -0.217 0.831 0.480 0.407 0.447 -0.295
|
||||
1.126 0.380 0.549 -0.445 -0.046 0.428 -0.074 0.217
|
||||
-0.822 0.491 1.347 -0.141 1.230 -0.044 0.079 0.219
|
||||
0.698 0.275 0.056 0.031 0.421 0.064 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
|
||||
}
|
||||
{
|
||||
[ "Rule 1:" print ]
|
||||
[ "Rule 2:" print [ [ [ swap neg + ] 2clump-map ] [ first suffix ] bi ] bi@ ]
|
||||
[ "Rule 3:" print [ 0 [ - neg ] accumulate* ] bi@ ]
|
||||
[ "Rule 4:" print [ cum-sum ] bi@ ]
|
||||
} [ show ] map-compose 2cleave
|
||||
91
Task/Demings-funnel/Go/demings-funnel.go
Normal file
91
Task/Demings-funnel/Go/demings-funnel.go
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
)
|
||||
|
||||
type rule func(float64, float64) float64
|
||||
|
||||
var dxs = []float64{
|
||||
-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.034, -0.126, 0.014,
|
||||
0.709, 0.129, -1.093, -0.483, -1.193, 0.020, -0.051, 0.047,
|
||||
-0.095, 0.695, 0.340, -0.182, 0.287, 0.213, -0.423, -0.021,
|
||||
-0.134, 1.798, 0.021, -1.099, -0.361, 1.636, -1.134, 1.315,
|
||||
0.201, 0.034, 0.097, -0.170, 0.054, -0.553, -0.024, -0.181,
|
||||
-0.700, -0.361, -0.789, 0.279, -0.174, -0.009, -0.323, -0.658,
|
||||
0.348, -0.528, 0.881, 0.021, -0.853, 0.157, 0.648, 1.774,
|
||||
-1.043, 0.051, 0.021, 0.247, -0.310, 0.171, 0.000, 0.106,
|
||||
0.024, -0.386, 0.962, 0.765, -0.125, -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,
|
||||
}
|
||||
|
||||
var dys = []float64{
|
||||
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.089, 0.208,
|
||||
0.585, 0.633, -0.444, -0.351, -1.087, 0.199, 0.701, 0.096,
|
||||
-0.025, -0.868, 1.051, 0.157, 0.216, 0.162, 0.249, -0.007,
|
||||
0.009, 0.508, -0.790, 0.723, 0.881, -0.508, 0.393, -0.226,
|
||||
0.710, 0.038, -0.217, 0.831, 0.480, 0.407, 0.447, -0.295,
|
||||
1.126, 0.380, 0.549, -0.445, -0.046, 0.428, -0.074, 0.217,
|
||||
-0.822, 0.491, 1.347, -0.141, 1.230, -0.044, 0.079, 0.219,
|
||||
0.698, 0.275, 0.056, 0.031, 0.421, 0.064, 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,
|
||||
}
|
||||
|
||||
func funnel(fa []float64, r rule) []float64 {
|
||||
x := 0.0
|
||||
result := make([]float64, len(fa))
|
||||
for i, f := range fa {
|
||||
result[i] = x + f
|
||||
x = r(x, f)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func mean(fa []float64) float64 {
|
||||
sum := 0.0
|
||||
for _, f := range fa {
|
||||
sum += f
|
||||
}
|
||||
return sum / float64(len(fa))
|
||||
}
|
||||
|
||||
func stdDev(fa []float64) float64 {
|
||||
m := mean(fa)
|
||||
sum := 0.0
|
||||
for _, f := range fa {
|
||||
sum += (f - m) * (f - m)
|
||||
}
|
||||
return math.Sqrt(sum / float64(len(fa)))
|
||||
}
|
||||
|
||||
func experiment(label string, r rule) {
|
||||
rxs := funnel(dxs, r)
|
||||
rys := funnel(dys, r)
|
||||
fmt.Println(label, " : x y")
|
||||
fmt.Printf("Mean : %7.4f, %7.4f\n", mean(rxs), mean(rys))
|
||||
fmt.Printf("Std Dev : %7.4f, %7.4f\n", stdDev(rxs), stdDev(rys))
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
func main() {
|
||||
experiment("Rule 1", func(_, _ float64) float64 {
|
||||
return 0.0
|
||||
})
|
||||
experiment("Rule 2", func(_, dz float64) float64 {
|
||||
return -dz
|
||||
})
|
||||
experiment("Rule 3", func(z, dz float64) float64 {
|
||||
return -(z + dz)
|
||||
})
|
||||
experiment("Rule 4", func(z, dz float64) float64 {
|
||||
return z + dz
|
||||
})
|
||||
}
|
||||
57
Task/Demings-funnel/Haskell/demings-funnel.hs
Normal file
57
Task/Demings-funnel/Haskell/demings-funnel.hs
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
import Data.List (mapAccumL, genericLength)
|
||||
import Text.Printf
|
||||
|
||||
funnel :: (Num a) => (a -> a -> a) -> [a] -> [a]
|
||||
funnel rule = snd . mapAccumL (\x dx -> (rule x dx, x + dx)) 0
|
||||
|
||||
mean :: (Fractional a) => [a] -> a
|
||||
mean xs = sum xs / genericLength xs
|
||||
|
||||
stddev :: (Floating a) => [a] -> a
|
||||
stddev xs = sqrt $ sum [(x-m)**2 | x <- xs] / genericLength xs where
|
||||
m = mean xs
|
||||
|
||||
experiment :: String -> [Double] -> [Double] -> (Double -> Double -> Double) -> IO ()
|
||||
experiment label dxs dys rule = do
|
||||
let rxs = funnel rule dxs
|
||||
rys = funnel rule dys
|
||||
putStrLn label
|
||||
printf "Mean x, y : %7.4f, %7.4f\n" (mean rxs) (mean rys)
|
||||
printf "Std dev x, y : %7.4f, %7.4f\n" (stddev rxs) (stddev rys)
|
||||
putStrLn ""
|
||||
|
||||
|
||||
dxs = [ -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.034, -0.126, 0.014,
|
||||
0.709, 0.129, -1.093, -0.483, -1.193, 0.020, -0.051, 0.047,
|
||||
-0.095, 0.695, 0.340, -0.182, 0.287, 0.213, -0.423, -0.021,
|
||||
-0.134, 1.798, 0.021, -1.099, -0.361, 1.636, -1.134, 1.315,
|
||||
0.201, 0.034, 0.097, -0.170, 0.054, -0.553, -0.024, -0.181,
|
||||
-0.700, -0.361, -0.789, 0.279, -0.174, -0.009, -0.323, -0.658,
|
||||
0.348, -0.528, 0.881, 0.021, -0.853, 0.157, 0.648, 1.774,
|
||||
-1.043, 0.051, 0.021, 0.247, -0.310, 0.171, 0.000, 0.106,
|
||||
0.024, -0.386, 0.962, 0.765, -0.125, -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]
|
||||
|
||||
dys = [ 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.089, 0.208,
|
||||
0.585, 0.633, -0.444, -0.351, -1.087, 0.199, 0.701, 0.096,
|
||||
-0.025, -0.868, 1.051, 0.157, 0.216, 0.162, 0.249, -0.007,
|
||||
0.009, 0.508, -0.790, 0.723, 0.881, -0.508, 0.393, -0.226,
|
||||
0.710, 0.038, -0.217, 0.831, 0.480, 0.407, 0.447, -0.295,
|
||||
1.126, 0.380, 0.549, -0.445, -0.046, 0.428, -0.074, 0.217,
|
||||
-0.822, 0.491, 1.347, -0.141, 1.230, -0.044, 0.079, 0.219,
|
||||
0.698, 0.275, 0.056, 0.031, 0.421, 0.064, 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]
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
experiment "Rule 1:" dxs dys (\_ _ -> 0)
|
||||
experiment "Rule 2:" dxs dys (\_ dz -> -dz)
|
||||
experiment "Rule 3:" dxs dys (\z dz -> -(z+dz))
|
||||
experiment "Rule 4:" dxs dys (\z dz -> z+dz)
|
||||
52
Task/Demings-funnel/J/demings-funnel.j
Normal file
52
Task/Demings-funnel/J/demings-funnel.j
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
dx=:".0 :0-.LF
|
||||
_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.034 _0.126 0.014
|
||||
0.709 0.129 _1.093 _0.483 _1.193 0.020 _0.051 0.047
|
||||
_0.095 0.695 0.340 _0.182 0.287 0.213 _0.423 _0.021
|
||||
_0.134 1.798 0.021 _1.099 _0.361 1.636 _1.134 1.315
|
||||
0.201 0.034 0.097 _0.170 0.054 _0.553 _0.024 _0.181
|
||||
_0.700 _0.361 _0.789 0.279 _0.174 _0.009 _0.323 _0.658
|
||||
0.348 _0.528 0.881 0.021 _0.853 0.157 0.648 1.774
|
||||
_1.043 0.051 0.021 0.247 _0.310 0.171 0.000 0.106
|
||||
0.024 _0.386 0.962 0.765 _0.125 _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
|
||||
)
|
||||
|
||||
dy=:".0 :0-.LF
|
||||
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.089 0.208
|
||||
0.585 0.633 _0.444 _0.351 _1.087 0.199 0.701 0.096
|
||||
_0.025 _0.868 1.051 0.157 0.216 0.162 0.249 _0.007
|
||||
0.009 0.508 _0.790 0.723 0.881 _0.508 0.393 _0.226
|
||||
0.710 0.038 _0.217 0.831 0.480 0.407 0.447 _0.295
|
||||
1.126 0.380 0.549 _0.445 _0.046 0.428 _0.074 0.217
|
||||
_0.822 0.491 1.347 _0.141 1.230 _0.044 0.079 0.219
|
||||
0.698 0.275 0.056 0.031 0.421 0.064 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
|
||||
)
|
||||
|
||||
Rule1=: ]
|
||||
Rule2=: -/\.&.|.
|
||||
Rule3=: ]-0,}:
|
||||
Rule4=: ]+0,}:
|
||||
|
||||
smoutput ' Rule 1 (x,y):'
|
||||
smoutput ' Mean: ',":dx ,&mean&Rule1 dy
|
||||
smoutput ' Std dev: ',":dx ,&stddev&Rule1 dy
|
||||
smoutput ' '
|
||||
smoutput ' Rule 2 (x,y):'
|
||||
smoutput ' Mean: ',":dx ,&mean&Rule2 dy
|
||||
smoutput ' Std dev: ',":dx ,&stddev&Rule2 dy
|
||||
smoutput ' '
|
||||
smoutput ' Rule 3 (x,y):'
|
||||
smoutput ' Mean: ',":dx ,&mean&Rule3 dy
|
||||
smoutput ' Std dev: ',":dx ,&stddev&Rule3 dy
|
||||
smoutput ' '
|
||||
smoutput ' Rule 4 (x,y):'
|
||||
smoutput ' Mean: ',":dx ,&mean&Rule4 dy
|
||||
smoutput ' Std dev: ',":dx ,&stddev&Rule4 dy
|
||||
75
Task/Demings-funnel/Java/demings-funnel.java
Normal file
75
Task/Demings-funnel/Java/demings-funnel.java
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
import static java.lang.Math.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public class DemingsFunnel {
|
||||
|
||||
public static void main(String[] args) {
|
||||
double[] dxs = {
|
||||
-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.034, -0.126, 0.014,
|
||||
0.709, 0.129, -1.093, -0.483, -1.193, 0.020, -0.051, 0.047,
|
||||
-0.095, 0.695, 0.340, -0.182, 0.287, 0.213, -0.423, -0.021,
|
||||
-0.134, 1.798, 0.021, -1.099, -0.361, 1.636, -1.134, 1.315,
|
||||
0.201, 0.034, 0.097, -0.170, 0.054, -0.553, -0.024, -0.181,
|
||||
-0.700, -0.361, -0.789, 0.279, -0.174, -0.009, -0.323, -0.658,
|
||||
0.348, -0.528, 0.881, 0.021, -0.853, 0.157, 0.648, 1.774,
|
||||
-1.043, 0.051, 0.021, 0.247, -0.310, 0.171, 0.000, 0.106,
|
||||
0.024, -0.386, 0.962, 0.765, -0.125, -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};
|
||||
|
||||
double[] dys = {
|
||||
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.089, 0.208,
|
||||
0.585, 0.633, -0.444, -0.351, -1.087, 0.199, 0.701, 0.096,
|
||||
-0.025, -0.868, 1.051, 0.157, 0.216, 0.162, 0.249, -0.007,
|
||||
0.009, 0.508, -0.790, 0.723, 0.881, -0.508, 0.393, -0.226,
|
||||
0.710, 0.038, -0.217, 0.831, 0.480, 0.407, 0.447, -0.295,
|
||||
1.126, 0.380, 0.549, -0.445, -0.046, 0.428, -0.074, 0.217,
|
||||
-0.822, 0.491, 1.347, -0.141, 1.230, -0.044, 0.079, 0.219,
|
||||
0.698, 0.275, 0.056, 0.031, 0.421, 0.064, 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};
|
||||
|
||||
experiment("Rule 1:", dxs, dys, (z, dz) -> 0.0);
|
||||
experiment("Rule 2:", dxs, dys, (z, dz) -> -dz);
|
||||
experiment("Rule 3:", dxs, dys, (z, dz) -> -(z + dz));
|
||||
experiment("Rule 4:", dxs, dys, (z, dz) -> z + dz);
|
||||
}
|
||||
|
||||
static void experiment(String label, double[] dxs, double[] dys,
|
||||
BiFunction<Double, Double, Double> rule) {
|
||||
|
||||
double[] resx = funnel(dxs, rule);
|
||||
double[] resy = funnel(dys, rule);
|
||||
System.out.println(label);
|
||||
System.out.printf("Mean x, y: %.4f, %.4f%n", mean(resx), mean(resy));
|
||||
System.out.printf("Std dev x, y: %.4f, %.4f%n", stdDev(resx), stdDev(resy));
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
static double[] funnel(double[] input, BiFunction<Double, Double, Double> rule) {
|
||||
double x = 0;
|
||||
double[] result = new double[input.length];
|
||||
|
||||
for (int i = 0; i < input.length; i++) {
|
||||
double rx = x + input[i];
|
||||
x = rule.apply(x, input[i]);
|
||||
result[i] = rx;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static double mean(double[] xs) {
|
||||
return Arrays.stream(xs).sum() / xs.length;
|
||||
}
|
||||
|
||||
static double stdDev(double[] xs) {
|
||||
double m = mean(xs);
|
||||
return sqrt(Arrays.stream(xs).map(x -> pow((x - m), 2)).sum() / xs.length);
|
||||
}
|
||||
}
|
||||
13
Task/Demings-funnel/Jq/demings-funnel-1.jq
Normal file
13
Task/Demings-funnel/Jq/demings-funnel-1.jq
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
def lpad($len): tostring | ($len - length) as $l | (" " * $l)[:$l] + .;
|
||||
|
||||
# Simplistic approach:
|
||||
def round($ndec): pow(10;$ndec) as $p | . * $p | round / $p;
|
||||
|
||||
# Emit {mean, ssdev, std} where std is (ssdev/length|sqrt)
|
||||
def basic_statistics:
|
||||
. as $in
|
||||
| length as $length
|
||||
| (add / $length) as $mean
|
||||
| { $mean,
|
||||
ssdev: (reduce $in[] as $x (0; . + (($x - $mean) | .*.))) }
|
||||
| .std = ((.ssdev / $length ) | sqrt);
|
||||
59
Task/Demings-funnel/Jq/demings-funnel-2.jq
Normal file
59
Task/Demings-funnel/Jq/demings-funnel-2.jq
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
def dxs: [
|
||||
-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.034, -0.126, 0.014,
|
||||
0.709, 0.129, -1.093, -0.483, -1.193, 0.020, -0.051, 0.047,
|
||||
-0.095, 0.695, 0.340, -0.182, 0.287, 0.213, -0.423, -0.021,
|
||||
-0.134, 1.798, 0.021, -1.099, -0.361, 1.636, -1.134, 1.315,
|
||||
0.201, 0.034, 0.097, -0.170, 0.054, -0.553, -0.024, -0.181,
|
||||
-0.700, -0.361, -0.789, 0.279, -0.174, -0.009, -0.323, -0.658,
|
||||
0.348, -0.528, 0.881, 0.021, -0.853, 0.157, 0.648, 1.774,
|
||||
-1.043, 0.051, 0.021, 0.247, -0.310, 0.171, 0.000, 0.106,
|
||||
0.024, -0.386, 0.962, 0.765, -0.125, -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
|
||||
];
|
||||
|
||||
def dys: [
|
||||
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.089, 0.208,
|
||||
0.585, 0.633, -0.444, -0.351, -1.087, 0.199, 0.701, 0.096,
|
||||
-0.025, -0.868, 1.051, 0.157, 0.216, 0.162, 0.249, -0.007,
|
||||
0.009, 0.508, -0.790, 0.723, 0.881, -0.508, 0.393, -0.226,
|
||||
0.710, 0.038, -0.217, 0.831, 0.480, 0.407, 0.447, -0.295,
|
||||
1.126, 0.380, 0.549, -0.445, -0.046, 0.428, -0.074, 0.217,
|
||||
-0.822, 0.491, 1.347, -0.141, 1.230, -0.044, 0.079, 0.219,
|
||||
0.698, 0.275, 0.056, 0.031, 0.421, 0.064, 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
|
||||
];
|
||||
|
||||
# fa is an array
|
||||
# r is an expression that expects [x,f] as input
|
||||
def funnel(fa; r):
|
||||
{ x: 0, res: []}
|
||||
| reduce range(0;fa|length) as $i (.;
|
||||
fa[$i] as $f
|
||||
| .res[$i] = .x + $f
|
||||
| .x |= ([., $f] | r ) )
|
||||
| .res;
|
||||
|
||||
# r is an expression as per `funnel`
|
||||
def experiment(alabel; r):
|
||||
def pp: round(4) | lpad(8);
|
||||
|
||||
(funnel(dxs; r) | basic_statistics) as $x
|
||||
| (funnel(dys; r) | basic_statistics) as $y
|
||||
| "\(alabel) : x y",
|
||||
"Mean : \($x.mean|pp) \($y.mean|pp)",
|
||||
"Std Dev : \($x.std|pp) \($y.std|pp)" ;
|
||||
|
||||
def task:
|
||||
experiment("\nRule 1"; 0 ),
|
||||
experiment("\nRule 2"; -.[1] ),
|
||||
experiment("\nRule 3"; - add),
|
||||
experiment("\nRule 4"; add ) ;
|
||||
|
||||
task
|
||||
55
Task/Demings-funnel/Julia/demings-funnel.julia
Normal file
55
Task/Demings-funnel/Julia/demings-funnel.julia
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
# Run from Julia REPL to see the 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,
|
||||
-0.401, 0.269, 0.491, 0.951, 1.150, 0.001, -0.382, 0.161, 0.915, 2.080, -2.337,
|
||||
0.034, -0.126, 0.014, 0.709, 0.129, -1.093, -0.483, -1.193, 0.020, -0.051,
|
||||
0.047, -0.095, 0.695, 0.340, -0.182, 0.287, 0.213, -0.423, -0.021, -0.134, 1.798,
|
||||
0.021, -1.099, -0.361, 1.636, -1.134, 1.315, 0.201, 0.034, 0.097, -0.170, 0.054,
|
||||
-0.553, -0.024, -0.181, -0.700, -0.361, -0.789, 0.279, -0.174, -0.009, -0.323,
|
||||
-0.658, 0.348, -0.528, 0.881, 0.021, -0.853, 0.157, 0.648, 1.774, -1.043, 0.051,
|
||||
0.021, 0.247, -0.310, 0.171, 0.000, 0.106, 0.024, -0.386, 0.962, 0.765, -0.125,
|
||||
-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]
|
||||
|
||||
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.089, 0.208, 0.585, 0.633, -0.444, -0.351, -1.087, 0.199, 0.701, 0.096, -0.025,
|
||||
-0.868, 1.051, 0.157, 0.216, 0.162, 0.249, -0.007, 0.009, 0.508, -0.790, 0.723,
|
||||
0.881, -0.508, 0.393, -0.226, 0.710, 0.038, -0.217, 0.831, 0.480, 0.407, 0.447,
|
||||
-0.295, 1.126, 0.380, 0.549, -0.445, -0.046, 0.428, -0.074, 0.217, -0.822, 0.491,
|
||||
1.347, -0.141, 1.230, -0.044, 0.079, 0.219, 0.698, 0.275, 0.056, 0.031, 0.421, 0.064,
|
||||
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]
|
||||
|
||||
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]]
|
||||
const plots, colors = plot(layout=(1,2)), [:red, :green, :blue, :yellow]
|
||||
|
||||
function makedata()
|
||||
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])
|
||||
end
|
||||
|
||||
function testfunnel(useracket=true)
|
||||
for (i, rule) in enumerate(rules)
|
||||
origin = [0.0, 0.0]
|
||||
xvec, yvec = Float64[], Float64[]
|
||||
for point in (useracket ? zip(racket_xdata, racket_ydata) : makedata())
|
||||
push!(xvec, origin[1] + point[1])
|
||||
push!(yvec, origin[2] + point[2])
|
||||
origin .= rule(origin[1], origin[2], point[1], point[2])
|
||||
end
|
||||
println("Rule $i results:")
|
||||
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))
|
||||
scatter!(xvec, yvec, color=colors[i], subplot=(useracket ? 1 : 2),
|
||||
title= useracket ? "Racket Data" : "Random Data", label="Rule $i")
|
||||
end
|
||||
end
|
||||
|
||||
println("\nUsing Racket data.")
|
||||
testfunnel()
|
||||
println("\nUsing new data.")
|
||||
testfunnel(false)
|
||||
display(plots)
|
||||
68
Task/Demings-funnel/Kotlin/demings-funnel.kotlin
Normal file
68
Task/Demings-funnel/Kotlin/demings-funnel.kotlin
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
// version 1.1.3
|
||||
|
||||
typealias Rule = (Double, Double) -> Double
|
||||
|
||||
val dxs = doubleArrayOf(
|
||||
-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.034, -0.126, 0.014,
|
||||
0.709, 0.129, -1.093, -0.483, -1.193, 0.020, -0.051, 0.047,
|
||||
-0.095, 0.695, 0.340, -0.182, 0.287, 0.213, -0.423, -0.021,
|
||||
-0.134, 1.798, 0.021, -1.099, -0.361, 1.636, -1.134, 1.315,
|
||||
0.201, 0.034, 0.097, -0.170, 0.054, -0.553, -0.024, -0.181,
|
||||
-0.700, -0.361, -0.789, 0.279, -0.174, -0.009, -0.323, -0.658,
|
||||
0.348, -0.528, 0.881, 0.021, -0.853, 0.157, 0.648, 1.774,
|
||||
-1.043, 0.051, 0.021, 0.247, -0.310, 0.171, 0.000, 0.106,
|
||||
0.024, -0.386, 0.962, 0.765, -0.125, -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
|
||||
)
|
||||
|
||||
val dys = doubleArrayOf(
|
||||
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.089, 0.208,
|
||||
0.585, 0.633, -0.444, -0.351, -1.087, 0.199, 0.701, 0.096,
|
||||
-0.025, -0.868, 1.051, 0.157, 0.216, 0.162, 0.249, -0.007,
|
||||
0.009, 0.508, -0.790, 0.723, 0.881, -0.508, 0.393, -0.226,
|
||||
0.710, 0.038, -0.217, 0.831, 0.480, 0.407, 0.447, -0.295,
|
||||
1.126, 0.380, 0.549, -0.445, -0.046, 0.428, -0.074, 0.217,
|
||||
-0.822, 0.491, 1.347, -0.141, 1.230, -0.044, 0.079, 0.219,
|
||||
0.698, 0.275, 0.056, 0.031, 0.421, 0.064, 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
|
||||
)
|
||||
|
||||
fun funnel(da: DoubleArray, rule: Rule): DoubleArray {
|
||||
var x = 0.0
|
||||
val result = DoubleArray(da.size)
|
||||
for ((i, d) in da.withIndex()) {
|
||||
result[i] = x + d
|
||||
x = rule(x, d)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
fun mean(da: DoubleArray) = da.average()
|
||||
|
||||
fun stdDev(da: DoubleArray): Double {
|
||||
val m = mean(da)
|
||||
return Math.sqrt(da.map { (it - m) * (it - m) }.average())
|
||||
}
|
||||
|
||||
fun experiment(label: String, rule: Rule) {
|
||||
val rxs = funnel(dxs, rule)
|
||||
val rys = funnel(dys, rule)
|
||||
println("$label : x y")
|
||||
println("Mean : ${"%7.4f, %7.4f".format(mean(rxs), mean(rys))}")
|
||||
println("Std Dev : ${"%7.4f, %7.4f".format(stdDev(rxs), stdDev(rys))}")
|
||||
println()
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
experiment("Rule 1") { _, _ -> 0.0 }
|
||||
experiment("Rule 2") { _, dz -> -dz }
|
||||
experiment("Rule 3") { z, dz -> -(z + dz) }
|
||||
experiment("Rule 4") { z, dz -> z + dz }
|
||||
}
|
||||
50
Task/Demings-funnel/Mathematica/demings-funnel-1.math
Normal file
50
Task/Demings-funnel/Mathematica/demings-funnel-1.math
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
dxs = {-0.533, 0.27, 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.15, 0.001, -0.382,
|
||||
0.161, 0.915, 2.08, -2.337, 0.034, -0.126, 0.014, 0.709,
|
||||
0.129, -1.093, -0.483, -1.193, 0.02, -0.051, 0.047, -0.095, 0.695,
|
||||
0.34, -0.182, 0.287, 0.213, -0.423, -0.021, -0.134, 1.798,
|
||||
0.021, -1.099, -0.361, 1.636, -1.134, 1.315, 0.201, 0.034,
|
||||
0.097, -0.17, 0.054, -0.553, -0.024, -0.181, -0.7, -0.361, -0.789,
|
||||
0.279, -0.174, -0.009, -0.323, -0.658, 0.348, -0.528, 0.881,
|
||||
0.021, -0.853, 0.157, 0.648, 1.774, -1.043, 0.051, 0.021,
|
||||
0.247, -0.31, 0.171, 0., 0.106, 0.024, -0.386, 0.962,
|
||||
0.765, -0.125, -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};
|
||||
dys = {0.136, 0.717, 0.459, -0.225, 1.392, 0.385, 0.121, -0.395,
|
||||
0.49, -0.682, -0.065, 0.242, -0.288, 0.658, 0.459, 0., 0.426,
|
||||
0.205, -0.765, -2.188, -0.742, -0.01, 0.089, 0.208, 0.585,
|
||||
0.633, -0.444, -0.351, -1.087, 0.199, 0.701, 0.096, -0.025, -0.868,
|
||||
1.051, 0.157, 0.216, 0.162, 0.249, -0.007, 0.009, 0.508, -0.79,
|
||||
0.723, 0.881, -0.508, 0.393, -0.226, 0.71, 0.038, -0.217, 0.831,
|
||||
0.48, 0.407, 0.447, -0.295, 1.126, 0.38, 0.549, -0.445, -0.046,
|
||||
0.428, -0.074, 0.217, -0.822, 0.491, 1.347, -0.141, 1.23, -0.044,
|
||||
0.079, 0.219, 0.698, 0.275, 0.056, 0.031, 0.421, 0.064, 0.721,
|
||||
0.104, -0.729, 0.65, -1.103, 0.154, -1.72, 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};
|
||||
|
||||
(*Mathematica's StandardDeviation function computes the unbiased standard deviation. The solutions seem to be using the biased standard deviation, so I'll create a custom function for that.*)
|
||||
BiasedStandardDeviation[data_] :=
|
||||
With[
|
||||
{mean = Mean@data},
|
||||
Sqrt[Total[(# - mean)^2 & /@ data]/Length[data]]
|
||||
]
|
||||
|
||||
(*Mathematica's FoldPair functionality will work well with this if we provide a properly defined function to fold with.*)
|
||||
DemingRule[1][funnelPosition_, diff_] := {funnelPosition + diff, 0};
|
||||
DemingRule[2][funnelPosition_, diff_] := {funnelPosition + diff, -diff};
|
||||
DemingRule[3][funnelPosition_, diff_] := {funnelPosition + diff, -funnelPosition - diff};
|
||||
DemingRule[4][funnelPosition_, diff_] := {funnelPosition + diff, funnelPosition + diff};
|
||||
|
||||
(*The core implementation.*)
|
||||
MarblePositions[rule_][diffs_] := FoldPairList[DemingRule[rule], 0, diffs];
|
||||
|
||||
(*This is to help format the output.*)
|
||||
Results[rule_, diffData_] :=
|
||||
With[
|
||||
{positions = MarblePositions[rule][diffData]},
|
||||
StringForm["Rule `1`\nmean: `2`\nstd dev: `3`", rule, Mean[positions], BiasedStandardDeviation[positions]]
|
||||
];
|
||||
|
||||
TableForm[Results[#, Transpose[{dxs, dys}]] & /@ Range[4], TableSpacing -> 5]
|
||||
13
Task/Demings-funnel/Mathematica/demings-funnel-2.math
Normal file
13
Task/Demings-funnel/Mathematica/demings-funnel-2.math
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
RadiusDistribution = NormalDistribution[0, 1];
|
||||
AngleDistribution = UniformDistribution[{0, Pi}];
|
||||
|
||||
(*Mathematica has built in transformation functions, but this seems clearer given the way the instructions were written.*)
|
||||
ToCartesian[{r_, a_}] := ToCartesian[{Abs@r, a - Pi}] /; Negative[r];
|
||||
ToCartesian[{r_, a_}] := FromPolarCoordinates[{r, a}];
|
||||
|
||||
newData =
|
||||
ToCartesian /@
|
||||
Transpose[{RandomVariate[RadiusDistribution, 100],
|
||||
RandomVariate[AngleDistribution, 100]}];
|
||||
|
||||
TableForm[Results[#, newData] & /@ Range[4], TableSpacing -> 5]
|
||||
1
Task/Demings-funnel/Mathematica/demings-funnel-3.math
Normal file
1
Task/Demings-funnel/Mathematica/demings-funnel-3.math
Normal file
|
|
@ -0,0 +1 @@
|
|||
ListPlot[MarblePositions[#][Transpose[{dxs,dys}]]&/@Range[4],PlotLegends->PointLegend[{1,2,3,4}],AspectRatio->Automatic,ImageSize->600]
|
||||
54
Task/Demings-funnel/Nim/demings-funnel.nim
Normal file
54
Task/Demings-funnel/Nim/demings-funnel.nim
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
import stats, strformat
|
||||
|
||||
type Rule = proc(x, y: float): float
|
||||
|
||||
const Dxs = [-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.034, -0.126, 0.014,
|
||||
0.709, 0.129, -1.093, -0.483, -1.193, 0.020, -0.051, 0.047,
|
||||
-0.095, 0.695, 0.340, -0.182, 0.287, 0.213, -0.423, -0.021,
|
||||
-0.134, 1.798, 0.021, -1.099, -0.361, 1.636, -1.134, 1.315,
|
||||
0.201, 0.034, 0.097, -0.170, 0.054, -0.553, -0.024, -0.181,
|
||||
-0.700, -0.361, -0.789, 0.279, -0.174, -0.009, -0.323, -0.658,
|
||||
0.348, -0.528, 0.881, 0.021, -0.853, 0.157, 0.648, 1.774,
|
||||
-1.043, 0.051, 0.021, 0.247, -0.310, 0.171, 0.000, 0.106,
|
||||
0.024, -0.386, 0.962, 0.765, -0.125, -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]
|
||||
|
||||
const Dys = [ 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.089, 0.208,
|
||||
0.585, 0.633, -0.444, -0.351, -1.087, 0.199, 0.701, 0.096,
|
||||
-0.025, -0.868, 1.051, 0.157, 0.216, 0.162, 0.249, -0.007,
|
||||
0.009, 0.508, -0.790, 0.723, 0.881, -0.508, 0.393, -0.226,
|
||||
0.710, 0.038, -0.217, 0.831, 0.480, 0.407, 0.447, -0.295,
|
||||
1.126, 0.380, 0.549, -0.445, -0.046, 0.428, -0.074, 0.217,
|
||||
-0.822, 0.491, 1.347, -0.141, 1.230, -0.044, 0.079, 0.219,
|
||||
0.698, 0.275, 0.056, 0.031, 0.421, 0.064, 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]
|
||||
|
||||
func funnel(a: openArray[float]; rule: Rule): seq[float] =
|
||||
var x = 0.0
|
||||
result.setlen(a.len)
|
||||
for i, val in a:
|
||||
result[i] = x + val
|
||||
x = rule(x, val)
|
||||
|
||||
proc experiment(label: string; r: Rule) =
|
||||
let rxs = funnel(Dxs, r)
|
||||
let rys = funnel(Dys, r)
|
||||
echo label
|
||||
echo fmt"Mean x, y : {rxs.mean:7.4f} {rys.mean:7.4f}"
|
||||
echo fmt"Std dev x, y : {rxs.standardDeviation:7.4f} {rys.standardDeviation:7.4f}"
|
||||
echo ""
|
||||
|
||||
experiment("Rule 1", proc(z, dz: float): float = 0.0)
|
||||
|
||||
experiment("Rule 2", proc(z, dz: float): float = -dz)
|
||||
|
||||
experiment("Rule 3", proc(z, dz: float): float = -(z + dz))
|
||||
|
||||
experiment("Rule 4", proc(z, dz: float): float = z + dz)
|
||||
26
Task/Demings-funnel/PARI-GP/demings-funnel.parigp
Normal file
26
Task/Demings-funnel/PARI-GP/demings-funnel.parigp
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
drop(drops, rule, rnd)={
|
||||
my(v=vector(drops),target=0);
|
||||
v[1]=rule(target, 0);
|
||||
for(i=2,drops,
|
||||
target=rule(target, v[i-1]);
|
||||
v[i]=rnd(n)+target
|
||||
);
|
||||
v
|
||||
};
|
||||
R=[-.533-.136*I,.27-.717*I,.859-.459*I,-.043+.225*I,-.205-1.39*I,-.127-.385*I,-.071-.121*I,.275+.395*I,1.25-.490*I,-.231+.682*I,-.401+.0650*I,.269-.242*I,.491+.288*I,.951-.658*I,1.15-.459*I,.001,-.382-.426*I,.161-.205*I,.915+.765*I,2.08+2.19*I,-2.34+.742*I,.034+.0100*I,-.126-.0890*I,.014-.208*I,.709-.585*I,.129-.633*I,-1.09+.444*I,-.483+.351*I,-1.19+1.09*I,.02-.199*I,-.051-.701*I,.047-.0960*I,-.095+.0250*I,.695+.868*I,.34-1.05*I,-.182-.157*I,.287-.216*I,.213-.162*I,-.423-.249*I,-.021+.00700*I,-0.134-.00900*I,1.8-.508*I,.021+.790*I,-1.1-.723*I,-.361-.881*I,1.64+.508*I,-1.13-.393*I,1.32+.226*I,.201-.710*I,.034-.0380*I,.097+.217*I,-.17-.831*I,.054-.480*I,-.553-.407*I,-.024-.447*I,-.181+.295*I,-.7-1.13*I,-.361-.380*I,-.789-.549*I,.279+.445*I,-.174+.0460*I,-.009-.428*I,-.323+.0740*I,-.658-.217*I,.348+.822*I,-.528-.491*I,.881-1.35*I,.021+.141*I,-.853-1.23*I,.157+.0440*I,.648-.0790*I,1.77-.219*I,-1.04-.698*I,.051-.275*I,.021-.0560*I,.247-.0310*I,-.31-.421*I,.171-.0640*I,-.721*I,.106-.104*I,.024+.729*I,-.386-.650*I,.962+1.10*I,.765-.154*I,-.125+1.72*I,-.289-.0510*I,.521+.385*I,.017-.477*I,.281-1.54*I,-.749+.901*I,-.149-.939*I,-2.44+.411*I,-.909-.341*I,.394+.411*I,-.113-.106*I,-.598-.224*I,.443+.947*I,-.521+1.42*I,-.799+.542*I,.087+1.03*I];
|
||||
rule1(target, result)=0;
|
||||
rule2(target, result)=target-result;
|
||||
rule3(target, result)=-result;
|
||||
rule4(target, result)=result;
|
||||
mean(v)=sum(i=1,#v,v[i])/#v;
|
||||
stdev(v,mu=mean(v))=sqrt(sum(i=1,#v,(v[i]-mu)^2)/#v);
|
||||
main()={
|
||||
my(V);
|
||||
V=apply(f->drop(100,f,n->R[n]), [rule1, rule2, rule3, rule4]);
|
||||
for(i=1,4,
|
||||
print("Method #"i);
|
||||
print("Means: ", mean(real(V[i])), "\t", mean(imag(V[i])));
|
||||
print("StDev: ", stdev(real(V[i])), "\t", stdev(imag(V[i])));
|
||||
print()
|
||||
)
|
||||
}
|
||||
51
Task/Demings-funnel/Perl/demings-funnel.pl
Normal file
51
Task/Demings-funnel/Perl/demings-funnel.pl
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
@dx = qw<
|
||||
-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.034 -0.126 0.014
|
||||
0.709 0.129 -1.093 -0.483 -1.193 0.020 -0.051 0.047
|
||||
-0.095 0.695 0.340 -0.182 0.287 0.213 -0.423 -0.021
|
||||
-0.134 1.798 0.021 -1.099 -0.361 1.636 -1.134 1.315
|
||||
0.201 0.034 0.097 -0.170 0.054 -0.553 -0.024 -0.181
|
||||
-0.700 -0.361 -0.789 0.279 -0.174 -0.009 -0.323 -0.658
|
||||
0.348 -0.528 0.881 0.021 -0.853 0.157 0.648 1.774
|
||||
-1.043 0.051 0.021 0.247 -0.310 0.171 0.000 0.106
|
||||
0.024 -0.386 0.962 0.765 -0.125 -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>;
|
||||
|
||||
@dy = qw<
|
||||
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.089 0.208
|
||||
0.585 0.633 -0.444 -0.351 -1.087 0.199 0.701 0.096
|
||||
-0.025 -0.868 1.051 0.157 0.216 0.162 0.249 -0.007
|
||||
0.009 0.508 -0.790 0.723 0.881 -0.508 0.393 -0.226
|
||||
0.710 0.038 -0.217 0.831 0.480 0.407 0.447 -0.295
|
||||
1.126 0.380 0.549 -0.445 -0.046 0.428 -0.074 0.217
|
||||
-0.822 0.491 1.347 -0.141 1.230 -0.044 0.079 0.219
|
||||
0.698 0.275 0.056 0.031 0.421 0.064 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>;
|
||||
|
||||
sub mean { my $s; $s += $_ for @_; $s / @_ }
|
||||
sub stddev { sqrt( mean(map { $_**2 } @_) - mean(@_)**2) }
|
||||
|
||||
@rules = (
|
||||
sub { 0 },
|
||||
sub { -$_[1] },
|
||||
sub { -$_[0] - $_[1] },
|
||||
sub { $_[0] + $_[1] }
|
||||
);
|
||||
|
||||
for (@rules) {
|
||||
print "Rule " . ++$cnt . "\n";
|
||||
|
||||
my @ddx; my $tx = 0;
|
||||
for my $x (@dx) { push @ddx, $tx + $x; $tx = &$_($tx, $x) }
|
||||
my @ddy; my $ty = 0;
|
||||
for my $y (@dy) { push @ddy, $ty + $y; $ty = &$_($ty, $y) }
|
||||
|
||||
printf "Mean x, y : %7.4f %7.4f\n", mean(@ddx), mean(@ddy);
|
||||
printf "Std dev x, y : %7.4f %7.4f\n", stddev(@ddx), stddev(@ddy);
|
||||
}
|
||||
65
Task/Demings-funnel/Phix/demings-funnel.phix
Normal file
65
Task/Demings-funnel/Phix/demings-funnel.phix
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
(phixonline)-->
|
||||
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
|
||||
<span style="color: #008080;">function</span> <span style="color: #000000;">funnel</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">dxs</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">integer</span> <span style="color: #000000;">rule</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #004080;">atom</span> <span style="color: #000000;">x</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0.0</span>
|
||||
<span style="color: #004080;">sequence</span> <span style="color: #000000;">rxs</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{}</span>
|
||||
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">dxs</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
|
||||
<span style="color: #004080;">atom</span> <span style="color: #000000;">dx</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">dxs</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]</span>
|
||||
<span style="color: #000000;">rxs</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">append</span><span style="color: #0000FF;">(</span><span style="color: #000000;">rxs</span><span style="color: #0000FF;">,</span><span style="color: #000000;">x</span> <span style="color: #0000FF;">+</span> <span style="color: #000000;">dx</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">switch</span> <span style="color: #000000;">rule</span>
|
||||
<span style="color: #008080;">case</span> <span style="color: #000000;">2</span><span style="color: #0000FF;">:</span> <span style="color: #000000;">x</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">dx</span>
|
||||
<span style="color: #008080;">case</span> <span style="color: #000000;">3</span><span style="color: #0000FF;">:</span> <span style="color: #000000;">x</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">-(</span><span style="color: #000000;">x</span><span style="color: #0000FF;">+</span><span style="color: #000000;">dx</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">case</span> <span style="color: #000000;">4</span><span style="color: #0000FF;">:</span> <span style="color: #000000;">x</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">x</span><span style="color: #0000FF;">+</span><span style="color: #000000;">dx</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">switch</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
|
||||
<span style="color: #008080;">return</span> <span style="color: #000000;">rxs</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
|
||||
|
||||
<span style="color: #008080;">function</span> <span style="color: #000000;">mean</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">xs</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">return</span> <span style="color: #7060A8;">sum</span><span style="color: #0000FF;">(</span><span style="color: #000000;">xs</span><span style="color: #0000FF;">)/</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">xs</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
|
||||
|
||||
<span style="color: #008080;">function</span> <span style="color: #000000;">stddev</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">xs</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #004080;">atom</span> <span style="color: #000000;">m</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">mean</span><span style="color: #0000FF;">(</span><span style="color: #000000;">xs</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">return</span> <span style="color: #7060A8;">sqrt</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">sum</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">sq_power</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">sq_sub</span><span style="color: #0000FF;">(</span><span style="color: #000000;">xs</span><span style="color: #0000FF;">,</span><span style="color: #000000;">m</span><span style="color: #0000FF;">),</span><span style="color: #000000;">2</span><span style="color: #0000FF;">))/</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">xs</span><span style="color: #0000FF;">))</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
|
||||
|
||||
<span style="color: #008080;">procedure</span> <span style="color: #000000;">experiment</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">sequence</span> <span style="color: #000000;">dxs</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">dys</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #004080;">sequence</span> <span style="color: #000000;">rxs</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">funnel</span><span style="color: #0000FF;">(</span><span style="color: #000000;">dxs</span><span style="color: #0000FF;">,</span><span style="color: #000000;">n</span><span style="color: #0000FF;">),</span>
|
||||
<span style="color: #000000;">rys</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">funnel</span><span style="color: #0000FF;">(</span><span style="color: #000000;">dys</span><span style="color: #0000FF;">,</span><span style="color: #000000;">n</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Mean x, y : %7.4f, %7.4f\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">mean</span><span style="color: #0000FF;">(</span><span style="color: #000000;">rxs</span><span style="color: #0000FF;">),</span> <span style="color: #000000;">mean</span><span style="color: #0000FF;">(</span><span style="color: #000000;">rys</span><span style="color: #0000FF;">)})</span>
|
||||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Std dev x, y : %7.4f, %7.4f\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">stddev</span><span style="color: #0000FF;">(</span><span style="color: #000000;">rxs</span><span style="color: #0000FF;">),</span> <span style="color: #000000;">stddev</span><span style="color: #0000FF;">(</span><span style="color: #000000;">rys</span><span style="color: #0000FF;">)})</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
|
||||
|
||||
<span style="color: #008080;">constant</span> <span style="color: #000000;">dxs</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{-</span><span style="color: #000000;">0.533</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.270</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.859</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.043</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.205</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.127</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.071</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.275</span><span style="color: #0000FF;">,</span>
|
||||
<span style="color: #000000;">1.251</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.231</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.401</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.269</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.491</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.951</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">1.150</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.001</span><span style="color: #0000FF;">,</span>
|
||||
<span style="color: #0000FF;">-</span><span style="color: #000000;">0.382</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.161</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.915</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">2.080</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">2.337</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.034</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.126</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.014</span><span style="color: #0000FF;">,</span>
|
||||
<span style="color: #000000;">0.709</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.129</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">1.093</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.483</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">1.193</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.020</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.051</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.047</span><span style="color: #0000FF;">,</span>
|
||||
<span style="color: #0000FF;">-</span><span style="color: #000000;">0.095</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.695</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.340</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.182</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.287</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.213</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.423</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.021</span><span style="color: #0000FF;">,</span>
|
||||
<span style="color: #0000FF;">-</span><span style="color: #000000;">0.134</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">1.798</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.021</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">1.099</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.361</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">1.636</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">1.134</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">1.315</span><span style="color: #0000FF;">,</span>
|
||||
<span style="color: #000000;">0.201</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.034</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.097</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.170</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.054</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.553</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.024</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.181</span><span style="color: #0000FF;">,</span>
|
||||
<span style="color: #0000FF;">-</span><span style="color: #000000;">0.700</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.361</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.789</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.279</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.174</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.009</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.323</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.658</span><span style="color: #0000FF;">,</span>
|
||||
<span style="color: #000000;">0.348</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.528</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.881</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.021</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.853</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.157</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.648</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">1.774</span><span style="color: #0000FF;">,</span>
|
||||
<span style="color: #0000FF;">-</span><span style="color: #000000;">1.043</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.051</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.021</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.247</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.310</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.171</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.000</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.106</span><span style="color: #0000FF;">,</span>
|
||||
<span style="color: #000000;">0.024</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.386</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.962</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.765</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.125</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.289</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.521</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.017</span><span style="color: #0000FF;">,</span>
|
||||
<span style="color: #000000;">0.281</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.749</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.149</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">2.436</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.909</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.394</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.113</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.598</span><span style="color: #0000FF;">,</span>
|
||||
<span style="color: #000000;">0.443</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.521</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.799</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.087</span><span style="color: #0000FF;">}</span>
|
||||
|
||||
<span style="color: #008080;">constant</span> <span style="color: #000000;">dys</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span> <span style="color: #000000;">0.136</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.717</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.459</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.225</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">1.392</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.385</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.121</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.395</span><span style="color: #0000FF;">,</span>
|
||||
<span style="color: #000000;">0.490</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.682</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.065</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.242</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.288</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.658</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.459</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.000</span><span style="color: #0000FF;">,</span>
|
||||
<span style="color: #000000;">0.426</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.205</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.765</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">2.188</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.742</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.010</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.089</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.208</span><span style="color: #0000FF;">,</span>
|
||||
<span style="color: #000000;">0.585</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.633</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.444</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.351</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">1.087</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.199</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.701</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.096</span><span style="color: #0000FF;">,</span>
|
||||
<span style="color: #0000FF;">-</span><span style="color: #000000;">0.025</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.868</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">1.051</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.157</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.216</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.162</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.249</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.007</span><span style="color: #0000FF;">,</span>
|
||||
<span style="color: #000000;">0.009</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.508</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.790</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.723</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.881</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.508</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.393</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.226</span><span style="color: #0000FF;">,</span>
|
||||
<span style="color: #000000;">0.710</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.038</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.217</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.831</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.480</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.407</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.447</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.295</span><span style="color: #0000FF;">,</span>
|
||||
<span style="color: #000000;">1.126</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.380</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.549</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.445</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.046</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.428</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.074</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.217</span><span style="color: #0000FF;">,</span>
|
||||
<span style="color: #0000FF;">-</span><span style="color: #000000;">0.822</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.491</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">1.347</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.141</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">1.230</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.044</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.079</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.219</span><span style="color: #0000FF;">,</span>
|
||||
<span style="color: #000000;">0.698</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.275</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.056</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.031</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.421</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.064</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.721</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.104</span><span style="color: #0000FF;">,</span>
|
||||
<span style="color: #0000FF;">-</span><span style="color: #000000;">0.729</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.650</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">1.103</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.154</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">1.720</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.051</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.385</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.477</span><span style="color: #0000FF;">,</span>
|
||||
<span style="color: #000000;">1.537</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.901</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.939</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.411</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.341</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.411</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.106</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.224</span><span style="color: #0000FF;">,</span>
|
||||
<span style="color: #0000FF;">-</span><span style="color: #000000;">0.947</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">1.424</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">0.542</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">1.032</span><span style="color: #0000FF;">}</span>
|
||||
|
||||
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">4</span> <span style="color: #008080;">do</span>
|
||||
<span style="color: #000000;">experiment</span><span style="color: #0000FF;">(</span><span style="color: #000000;">i</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">dxs</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">dys</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
|
||||
<!--
|
||||
50
Task/Demings-funnel/Python/demings-funnel-1.py
Normal file
50
Task/Demings-funnel/Python/demings-funnel-1.py
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
import math
|
||||
|
||||
dxs = [-0.533, 0.27, 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.15, 0.001, -0.382, 0.161, 0.915,
|
||||
2.08, -2.337, 0.034, -0.126, 0.014, 0.709, 0.129, -1.093, -0.483, -1.193,
|
||||
0.02, -0.051, 0.047, -0.095, 0.695, 0.34, -0.182, 0.287, 0.213, -0.423,
|
||||
-0.021, -0.134, 1.798, 0.021, -1.099, -0.361, 1.636, -1.134, 1.315, 0.201,
|
||||
0.034, 0.097, -0.17, 0.054, -0.553, -0.024, -0.181, -0.7, -0.361, -0.789,
|
||||
0.279, -0.174, -0.009, -0.323, -0.658, 0.348, -0.528, 0.881, 0.021, -0.853,
|
||||
0.157, 0.648, 1.774, -1.043, 0.051, 0.021, 0.247, -0.31, 0.171, 0.0, 0.106,
|
||||
0.024, -0.386, 0.962, 0.765, -0.125, -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]
|
||||
|
||||
dys = [0.136, 0.717, 0.459, -0.225, 1.392, 0.385, 0.121, -0.395, 0.49, -0.682,
|
||||
-0.065, 0.242, -0.288, 0.658, 0.459, 0.0, 0.426, 0.205, -0.765, -2.188,
|
||||
-0.742, -0.01, 0.089, 0.208, 0.585, 0.633, -0.444, -0.351, -1.087, 0.199,
|
||||
0.701, 0.096, -0.025, -0.868, 1.051, 0.157, 0.216, 0.162, 0.249, -0.007,
|
||||
0.009, 0.508, -0.79, 0.723, 0.881, -0.508, 0.393, -0.226, 0.71, 0.038,
|
||||
-0.217, 0.831, 0.48, 0.407, 0.447, -0.295, 1.126, 0.38, 0.549, -0.445,
|
||||
-0.046, 0.428, -0.074, 0.217, -0.822, 0.491, 1.347, -0.141, 1.23, -0.044,
|
||||
0.079, 0.219, 0.698, 0.275, 0.056, 0.031, 0.421, 0.064, 0.721, 0.104,
|
||||
-0.729, 0.65, -1.103, 0.154, -1.72, 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]
|
||||
|
||||
def funnel(dxs, rule):
|
||||
x, rxs = 0, []
|
||||
for dx in dxs:
|
||||
rxs.append(x + dx)
|
||||
x = rule(x, dx)
|
||||
return rxs
|
||||
|
||||
def mean(xs): return sum(xs) / len(xs)
|
||||
|
||||
def stddev(xs):
|
||||
m = mean(xs)
|
||||
return math.sqrt(sum((x-m)**2 for x in xs) / len(xs))
|
||||
|
||||
def experiment(label, rule):
|
||||
rxs, rys = funnel(dxs, rule), funnel(dys, rule)
|
||||
print label
|
||||
print 'Mean x, y : %.4f, %.4f' % (mean(rxs), mean(rys))
|
||||
print 'Std dev x, y : %.4f, %.4f' % (stddev(rxs), stddev(rys))
|
||||
print
|
||||
|
||||
|
||||
experiment('Rule 1:', lambda z, dz: 0)
|
||||
experiment('Rule 2:', lambda z, dz: -dz)
|
||||
experiment('Rule 3:', lambda z, dz: -(z+dz))
|
||||
experiment('Rule 4:', lambda z, dz: z+dz)
|
||||
75
Task/Demings-funnel/Python/demings-funnel-2.py
Normal file
75
Task/Demings-funnel/Python/demings-funnel-2.py
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
from random import gauss
|
||||
from math import sqrt
|
||||
from pprint import pprint as pp
|
||||
|
||||
NMAX=50
|
||||
|
||||
def statscreator():
|
||||
sum_ = sum2 = n = 0
|
||||
def stats(x):
|
||||
nonlocal sum_, sum2, n
|
||||
|
||||
sum_ += x
|
||||
sum2 += x*x
|
||||
n += 1.0
|
||||
return sum_/n, sqrt(sum2/n - sum_*sum_/n/n)
|
||||
return stats
|
||||
|
||||
def drop(target, sigma=1.0):
|
||||
'Drop ball at target'
|
||||
return gauss(target, sigma)
|
||||
|
||||
def deming(rule, nmax=NMAX):
|
||||
''' Simulate Demings funnel in 1D. '''
|
||||
|
||||
stats = statscreator()
|
||||
target = 0
|
||||
for i in range(nmax):
|
||||
value = drop(target)
|
||||
mean, sdev = stats(value)
|
||||
target = rule(target, value)
|
||||
if i == nmax - 1:
|
||||
return mean, sdev
|
||||
|
||||
def d1(target, value):
|
||||
''' Keep Funnel over target. '''
|
||||
|
||||
return target
|
||||
|
||||
|
||||
def d2(target, value):
|
||||
''' The new target starts at the center, 0,0 then is adjusted to
|
||||
be the previous target _minus_ the offset of the new drop from the
|
||||
previous target. '''
|
||||
|
||||
return -value # - (target - (target - value)) = - value
|
||||
|
||||
def d3(target, value):
|
||||
''' The new target starts at the center, 0,0 then is adjusted to
|
||||
be the previous target _minus_ the offset of the new drop from the
|
||||
center, 0.0. '''
|
||||
|
||||
return target - value
|
||||
|
||||
def d4(target, value):
|
||||
''' (Dumb). The new target is where it last dropped. '''
|
||||
|
||||
return value
|
||||
|
||||
|
||||
def printit(rule, trials=5):
|
||||
print('\nDeming simulation. %i trials using rule %s:\n %s'
|
||||
% (trials, rule.__name__.upper(), rule.__doc__))
|
||||
for i in range(trials):
|
||||
print(' Mean: %7.3f, Sdev: %7.3f' % deming(rule))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
rcomments = [ (d1, 'Should have smallest deviations ~1.0, and be centered on 0.0'),
|
||||
(d2, 'Should be centred on 0.0 with larger deviations than D1'),
|
||||
(d3, 'Should be centred on 0.0 with larger deviations than D1'),
|
||||
(d4, 'Center wanders all over the place, with deviations to match!'),
|
||||
]
|
||||
for rule, comment in rcomments:
|
||||
printit(rule)
|
||||
print(' %s\n' % comment)
|
||||
51
Task/Demings-funnel/Racket/demings-funnel.rkt
Normal file
51
Task/Demings-funnel/Racket/demings-funnel.rkt
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
#lang racket
|
||||
(require math/distributions math/statistics plot)
|
||||
|
||||
(define dxs '(-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.034 -0.126 0.014 0.709 0.129 -1.093 -0.483 -1.193 0.020 -0.051
|
||||
0.047 -0.095 0.695 0.340 -0.182 0.287 0.213 -0.423 -0.021 -0.134 1.798
|
||||
0.021 -1.099 -0.361 1.636 -1.134 1.315 0.201 0.034 0.097 -0.170 0.054
|
||||
-0.553 -0.024 -0.181 -0.700 -0.361 -0.789 0.279 -0.174 -0.009 -0.323
|
||||
-0.658 0.348 -0.528 0.881 0.021 -0.853 0.157 0.648 1.774 -1.043 0.051
|
||||
0.021 0.247 -0.310 0.171 0.000 0.106 0.024 -0.386 0.962 0.765 -0.125
|
||||
-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))
|
||||
|
||||
(define dys '(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.089 0.208 0.585 0.633 -0.444 -0.351 -1.087 0.199 0.701 0.096 -0.025
|
||||
-0.868 1.051 0.157 0.216 0.162 0.249 -0.007 0.009 0.508 -0.790 0.723
|
||||
0.881 -0.508 0.393 -0.226 0.710 0.038 -0.217 0.831 0.480 0.407 0.447
|
||||
-0.295 1.126 0.380 0.549 -0.445 -0.046 0.428 -0.074 0.217 -0.822 0.491
|
||||
1.347 -0.141 1.230 -0.044 0.079 0.219 0.698 0.275 0.056 0.031 0.421 0.064
|
||||
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))
|
||||
|
||||
;(define radii (map abs (sample (normal-dist 0 1) 100)))
|
||||
;(define angles (sample (uniform-dist (- pi) pi) 100))
|
||||
;(define dxs (map (λ (r theta) (* r (cos theta))) radii angles))
|
||||
;(define dys (map (λ (r theta) (* r (sin theta))) radii angles))
|
||||
|
||||
(define (funnel dxs rule)
|
||||
(let ([x 0])
|
||||
(for/fold ([rxs null])
|
||||
([dx dxs])
|
||||
(let ([rx (+ x dx)])
|
||||
(set! x (rule x dx))
|
||||
(cons rx rxs)))))
|
||||
|
||||
(define (experiment label rule)
|
||||
(define (p s) (real->decimal-string s 4))
|
||||
(let ([rxs (funnel dxs rule)]
|
||||
[rys (funnel dys rule)])
|
||||
(displayln label)
|
||||
(printf "Mean x, y : ~a, ~a\n" (p (mean rxs)) (p (mean rys)))
|
||||
(printf "Std dev x, y: ~a, ~a\n\n" (p (stddev rxs)) (p (stddev rys)))
|
||||
#;(plot (points (map vector rxs rys)
|
||||
#:x-min -15 #:x-max 15 #:y-min -15 #:y-max 15))))
|
||||
|
||||
(experiment "Rule 1:" (λ (z dz) 0))
|
||||
(experiment "Rule 2:" (λ (z dz) (- dz)))
|
||||
(experiment "Rule 3:" (λ (z dz) (- (+ z dz))))
|
||||
(experiment "Rule 4:" (λ (z dz) (+ z dz)))
|
||||
53
Task/Demings-funnel/Raku/demings-funnel.raku
Normal file
53
Task/Demings-funnel/Raku/demings-funnel.raku
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
sub mean { @_ R/ [+] @_ }
|
||||
sub stddev {
|
||||
# <(x - <x>)²> = <x²> - <x>²
|
||||
sqrt( mean(@_ »**» 2) - mean(@_)**2 )
|
||||
}
|
||||
|
||||
constant @dz = <
|
||||
-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.034 -0.126 0.014
|
||||
0.709 0.129 -1.093 -0.483 -1.193 0.020 -0.051 0.047
|
||||
-0.095 0.695 0.340 -0.182 0.287 0.213 -0.423 -0.021
|
||||
-0.134 1.798 0.021 -1.099 -0.361 1.636 -1.134 1.315
|
||||
0.201 0.034 0.097 -0.170 0.054 -0.553 -0.024 -0.181
|
||||
-0.700 -0.361 -0.789 0.279 -0.174 -0.009 -0.323 -0.658
|
||||
0.348 -0.528 0.881 0.021 -0.853 0.157 0.648 1.774
|
||||
-1.043 0.051 0.021 0.247 -0.310 0.171 0.000 0.106
|
||||
0.024 -0.386 0.962 0.765 -0.125 -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
|
||||
> Z+ (1i X* <
|
||||
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.089 0.208
|
||||
0.585 0.633 -0.444 -0.351 -1.087 0.199 0.701 0.096
|
||||
-0.025 -0.868 1.051 0.157 0.216 0.162 0.249 -0.007
|
||||
0.009 0.508 -0.790 0.723 0.881 -0.508 0.393 -0.226
|
||||
0.710 0.038 -0.217 0.831 0.480 0.407 0.447 -0.295
|
||||
1.126 0.380 0.549 -0.445 -0.046 0.428 -0.074 0.217
|
||||
-0.822 0.491 1.347 -0.141 1.230 -0.044 0.079 0.219
|
||||
0.698 0.275 0.056 0.031 0.421 0.064 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
|
||||
>);
|
||||
|
||||
constant @rule =
|
||||
-> \z, \dz { 0 },
|
||||
-> \z, \dz { -dz },
|
||||
-> \z, \dz { -z - dz },
|
||||
-> \z, \dz { z + dz },
|
||||
;
|
||||
|
||||
for @rule {
|
||||
say "Rule $(++$):";
|
||||
my $target = 0i;
|
||||
my @z = gather for @dz -> $dz {
|
||||
take $target + $dz;
|
||||
$target = .($target, $dz)
|
||||
}
|
||||
printf "Mean x, y : %7.4f %7.4f\n", mean(@z».re), mean(@z».im);
|
||||
printf "Std dev x, y : %7.4f %7.4f\n", stddev(@z».re), stddev(@z».im);
|
||||
}
|
||||
56
Task/Demings-funnel/Ruby/demings-funnel.rb
Normal file
56
Task/Demings-funnel/Ruby/demings-funnel.rb
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
def funnel(dxs, &rule)
|
||||
x, rxs = 0, []
|
||||
for dx in dxs
|
||||
rxs << (x + dx)
|
||||
x = rule[x, dx]
|
||||
end
|
||||
rxs
|
||||
end
|
||||
|
||||
def mean(xs) xs.inject(:+) / xs.size end
|
||||
|
||||
def stddev(xs)
|
||||
m = mean(xs)
|
||||
Math.sqrt(xs.inject(0.0){|sum,x| sum + (x-m)**2} / xs.size)
|
||||
end
|
||||
|
||||
def experiment(label, dxs, dys, &rule)
|
||||
rxs, rys = funnel(dxs, &rule), funnel(dys, &rule)
|
||||
puts label
|
||||
puts 'Mean x, y : %7.4f, %7.4f' % [mean(rxs), mean(rys)]
|
||||
puts 'Std dev x, y : %7.4f, %7.4f' % [stddev(rxs), stddev(rys)]
|
||||
puts
|
||||
end
|
||||
|
||||
dxs = [ -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.034, -0.126, 0.014,
|
||||
0.709, 0.129, -1.093, -0.483, -1.193, 0.020, -0.051, 0.047,
|
||||
-0.095, 0.695, 0.340, -0.182, 0.287, 0.213, -0.423, -0.021,
|
||||
-0.134, 1.798, 0.021, -1.099, -0.361, 1.636, -1.134, 1.315,
|
||||
0.201, 0.034, 0.097, -0.170, 0.054, -0.553, -0.024, -0.181,
|
||||
-0.700, -0.361, -0.789, 0.279, -0.174, -0.009, -0.323, -0.658,
|
||||
0.348, -0.528, 0.881, 0.021, -0.853, 0.157, 0.648, 1.774,
|
||||
-1.043, 0.051, 0.021, 0.247, -0.310, 0.171, 0.000, 0.106,
|
||||
0.024, -0.386, 0.962, 0.765, -0.125, -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]
|
||||
|
||||
dys = [ 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.089, 0.208,
|
||||
0.585, 0.633, -0.444, -0.351, -1.087, 0.199, 0.701, 0.096,
|
||||
-0.025, -0.868, 1.051, 0.157, 0.216, 0.162, 0.249, -0.007,
|
||||
0.009, 0.508, -0.790, 0.723, 0.881, -0.508, 0.393, -0.226,
|
||||
0.710, 0.038, -0.217, 0.831, 0.480, 0.407, 0.447, -0.295,
|
||||
1.126, 0.380, 0.549, -0.445, -0.046, 0.428, -0.074, 0.217,
|
||||
-0.822, 0.491, 1.347, -0.141, 1.230, -0.044, 0.079, 0.219,
|
||||
0.698, 0.275, 0.056, 0.031, 0.421, 0.064, 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]
|
||||
|
||||
experiment('Rule 1:', dxs, dys) {|z, dz| 0}
|
||||
experiment('Rule 2:', dxs, dys) {|z, dz| -dz}
|
||||
experiment('Rule 3:', dxs, dys) {|z, dz| -(z+dz)}
|
||||
experiment('Rule 4:', dxs, dys) {|z, dz| z+dz}
|
||||
57
Task/Demings-funnel/Sidef/demings-funnel.sidef
Normal file
57
Task/Demings-funnel/Sidef/demings-funnel.sidef
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
func x̄(a) {
|
||||
a.sum / a.len
|
||||
}
|
||||
|
||||
func σ(a) {
|
||||
sqrt(x̄(a.map{.**2}) - x̄(a)**2)
|
||||
}
|
||||
|
||||
const Δ = (%n<
|
||||
-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.034 -0.126 0.014
|
||||
0.709 0.129 -1.093 -0.483 -1.193 0.020 -0.051 0.047
|
||||
-0.095 0.695 0.340 -0.182 0.287 0.213 -0.423 -0.021
|
||||
-0.134 1.798 0.021 -1.099 -0.361 1.636 -1.134 1.315
|
||||
0.201 0.034 0.097 -0.170 0.054 -0.553 -0.024 -0.181
|
||||
-0.700 -0.361 -0.789 0.279 -0.174 -0.009 -0.323 -0.658
|
||||
0.348 -0.528 0.881 0.021 -0.853 0.157 0.648 1.774
|
||||
-1.043 0.051 0.021 0.247 -0.310 0.171 0.000 0.106
|
||||
0.024 -0.386 0.962 0.765 -0.125 -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
|
||||
> ~Z+ %n<
|
||||
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.089 0.208
|
||||
0.585 0.633 -0.444 -0.351 -1.087 0.199 0.701 0.096
|
||||
-0.025 -0.868 1.051 0.157 0.216 0.162 0.249 -0.007
|
||||
0.009 0.508 -0.790 0.723 0.881 -0.508 0.393 -0.226
|
||||
0.710 0.038 -0.217 0.831 0.480 0.407 0.447 -0.295
|
||||
1.126 0.380 0.549 -0.445 -0.046 0.428 -0.074 0.217
|
||||
-0.822 0.491 1.347 -0.141 1.230 -0.044 0.079 0.219
|
||||
0.698 0.275 0.056 0.031 0.421 0.064 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
|
||||
>.map{ .i })
|
||||
|
||||
const rules = [
|
||||
{ 0 },
|
||||
{|_,dz| -dz },
|
||||
{|z,dz| -z - dz },
|
||||
{|z,dz| z + dz },
|
||||
]
|
||||
|
||||
for i,v in (rules.kv) {
|
||||
say "Rule #{i+1}:"
|
||||
var target = 0
|
||||
var z = gather {
|
||||
Δ.each { |d|
|
||||
take(target + d)
|
||||
target = v.run(target, d)
|
||||
}
|
||||
}
|
||||
printf("Mean x, y : %.4f %.4f\n", x̄(z.map{.re}), x̄(z.map{.im}))
|
||||
printf("Std dev x, y : %.4f %.4f\n", σ(z.map{.re}), σ(z.map{.im}))
|
||||
}
|
||||
76
Task/Demings-funnel/Swift/demings-funnel.swift
Normal file
76
Task/Demings-funnel/Swift/demings-funnel.swift
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
import Foundation
|
||||
|
||||
let dxs = [
|
||||
-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.034, -0.126, 0.014,
|
||||
0.709, 0.129, -1.093, -0.483, -1.193, 0.020, -0.051, 0.047,
|
||||
-0.095, 0.695, 0.340, -0.182, 0.287, 0.213, -0.423, -0.021,
|
||||
-0.134, 1.798, 0.021, -1.099, -0.361, 1.636, -1.134, 1.315,
|
||||
0.201, 0.034, 0.097, -0.170, 0.054, -0.553, -0.024, -0.181,
|
||||
-0.700, -0.361, -0.789, 0.279, -0.174, -0.009, -0.323, -0.658,
|
||||
0.348, -0.528, 0.881, 0.021, -0.853, 0.157, 0.648, 1.774,
|
||||
-1.043, 0.051, 0.021, 0.247, -0.310, 0.171, 0.000, 0.106,
|
||||
0.024, -0.386, 0.962, 0.765, -0.125, -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
|
||||
]
|
||||
|
||||
let dys = [
|
||||
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.089, 0.208,
|
||||
0.585, 0.633, -0.444, -0.351, -1.087, 0.199, 0.701, 0.096,
|
||||
-0.025, -0.868, 1.051, 0.157, 0.216, 0.162, 0.249, -0.007,
|
||||
0.009, 0.508, -0.790, 0.723, 0.881, -0.508, 0.393, -0.226,
|
||||
0.710, 0.038, -0.217, 0.831, 0.480, 0.407, 0.447, -0.295,
|
||||
1.126, 0.380, 0.549, -0.445, -0.046, 0.428, -0.074, 0.217,
|
||||
-0.822, 0.491, 1.347, -0.141, 1.230, -0.044, 0.079, 0.219,
|
||||
0.698, 0.275, 0.056, 0.031, 0.421, 0.064, 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
|
||||
]
|
||||
|
||||
extension Collection where Element: FloatingPoint {
|
||||
@inlinable
|
||||
public func mean() -> Element {
|
||||
return reduce(0, +) / Element(count)
|
||||
}
|
||||
|
||||
@inlinable
|
||||
public func stdDev() -> Element {
|
||||
let m = mean()
|
||||
|
||||
return map({ ($0 - m) * ($0 - m) }).mean().squareRoot()
|
||||
}
|
||||
}
|
||||
|
||||
typealias Rule = (Double, Double) -> Double
|
||||
|
||||
func funnel(_ arr: [Double], rule: Rule) -> [Double] {
|
||||
var x = 0.0
|
||||
var res = [Double](repeating: 0, count: arr.count)
|
||||
|
||||
for (i, d) in arr.enumerated() {
|
||||
res[i] = x + d
|
||||
x = rule(x, d)
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
func experiment(label: String, rule: Rule) {
|
||||
let rxs = funnel(dxs, rule: rule)
|
||||
let rys = funnel(dys, rule: rule)
|
||||
|
||||
print("\(label)\t: x y")
|
||||
print("Mean\t:\(String(format: "%7.4f, %7.4f", rxs.mean(), rys.mean()))")
|
||||
print("Std Dev\t:\(String(format: "%7.4f, %7.4f", rxs.stdDev(), rys.stdDev()))")
|
||||
print()
|
||||
}
|
||||
|
||||
experiment(label: "Rule 1", rule: {_, _ in 0 })
|
||||
experiment(label: "Rule 2", rule: {_, dz in -dz })
|
||||
experiment(label: "Rule 3", rule: {z, dz in -(z + dz) })
|
||||
experiment(label: "Rule 4", rule: {z, dz in z + dz })
|
||||
59
Task/Demings-funnel/Tcl/demings-funnel-1.tcl
Normal file
59
Task/Demings-funnel/Tcl/demings-funnel-1.tcl
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
package require Tcl 8.6
|
||||
namespace path {tcl::mathop tcl::mathfunc}
|
||||
|
||||
proc funnel {items rule} {
|
||||
set x 0.0
|
||||
set result {}
|
||||
foreach item $items {
|
||||
lappend result [+ $x $item]
|
||||
set x [apply $rule $x $item]
|
||||
}
|
||||
return $result
|
||||
}
|
||||
|
||||
proc mean {items} {
|
||||
/ [+ {*}$items] [double [llength $items]]
|
||||
}
|
||||
proc stddev {items} {
|
||||
set m [mean $items]
|
||||
sqrt [mean [lmap x $items {** [- $x $m] 2}]]
|
||||
}
|
||||
|
||||
proc experiment {label dxs dys rule} {
|
||||
set rxs [funnel $dxs $rule]
|
||||
set rys [funnel $dys $rule]
|
||||
puts $label
|
||||
puts [format "Mean x, y : %7.4f, %7.4f" [mean $rxs] [mean $rys]]
|
||||
puts [format "Std dev x, y : %7.4f, %7.4f" [stddev $rxs] [stddev $rys]]
|
||||
puts ""
|
||||
}
|
||||
|
||||
set dxs {
|
||||
-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.034
|
||||
-0.126 0.014 0.709 0.129 -1.093 -0.483 -1.193 0.020 -0.051 0.047 -0.095
|
||||
0.695 0.340 -0.182 0.287 0.213 -0.423 -0.021 -0.134 1.798 0.021 -1.099
|
||||
-0.361 1.636 -1.134 1.315 0.201 0.034 0.097 -0.170 0.054 -0.553 -0.024
|
||||
-0.181 -0.700 -0.361 -0.789 0.279 -0.174 -0.009 -0.323 -0.658 0.348
|
||||
-0.528 0.881 0.021 -0.853 0.157 0.648 1.774 -1.043 0.051 0.021 0.247
|
||||
-0.310 0.171 0.000 0.106 0.024 -0.386 0.962 0.765 -0.125 -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
|
||||
}
|
||||
set dys {
|
||||
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.089 0.208 0.585 0.633 -0.444 -0.351 -1.087 0.199 0.701 0.096 -0.025
|
||||
-0.868 1.051 0.157 0.216 0.162 0.249 -0.007 0.009 0.508 -0.790 0.723
|
||||
0.881 -0.508 0.393 -0.226 0.710 0.038 -0.217 0.831 0.480 0.407 0.447
|
||||
-0.295 1.126 0.380 0.549 -0.445 -0.046 0.428 -0.074 0.217 -0.822 0.491
|
||||
1.347 -0.141 1.230 -0.044 0.079 0.219 0.698 0.275 0.056 0.031 0.421 0.064
|
||||
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
|
||||
}
|
||||
|
||||
puts "USING STANDARD DATA"
|
||||
experiment "Rule 1:" $dxs $dys {{z dz} {expr {0}}}
|
||||
experiment "Rule 2:" $dxs $dys {{z dz} {expr {-$dz}}}
|
||||
experiment "Rule 3:" $dxs $dys {{z dz} {expr {-($z+$dz)}}}
|
||||
experiment "Rule 4:" $dxs $dys {{z dz} {expr {$z+$dz}}}
|
||||
20
Task/Demings-funnel/Tcl/demings-funnel-2.tcl
Normal file
20
Task/Demings-funnel/Tcl/demings-funnel-2.tcl
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
package require math::constants
|
||||
package require simulation::random
|
||||
|
||||
math::constants::constants degtorad
|
||||
|
||||
set rng(radius) [simulation::random::prng_Normal 0.0 1.0]
|
||||
set rng(angle) [simulation::random::prng_Uniform 0.0 360.0]
|
||||
set dxs [set dys {}]
|
||||
for {set i 0} {$i < 500} {incr i} {
|
||||
set r [$rng(radius)]
|
||||
set theta [expr {[$rng(angle)] * $degtorad}]
|
||||
lappend dxs [expr {$r * cos($theta)}]
|
||||
lappend dys [expr {$r * sin($theta)}]
|
||||
}
|
||||
|
||||
puts "USING RANDOM DATA"
|
||||
experiment "Rule 1:" $dxs $dys {{z dz} {expr {0}}}
|
||||
experiment "Rule 2:" $dxs $dys {{z dz} {expr {-$dz}}}
|
||||
experiment "Rule 3:" $dxs $dys {{z dz} {expr {-($z+$dz)}}}
|
||||
experiment "Rule 4:" $dxs $dys {{z dz} {expr {$z+$dz}}}
|
||||
88
Task/Demings-funnel/V-(Vlang)/demings-funnel.v
Normal file
88
Task/Demings-funnel/V-(Vlang)/demings-funnel.v
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
import math
|
||||
|
||||
type Rule = fn(f64, f64) f64
|
||||
|
||||
const (
|
||||
dxs = [
|
||||
-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.034, -0.126, 0.014,
|
||||
0.709, 0.129, -1.093, -0.483, -1.193, 0.020, -0.051, 0.047,
|
||||
-0.095, 0.695, 0.340, -0.182, 0.287, 0.213, -0.423, -0.021,
|
||||
-0.134, 1.798, 0.021, -1.099, -0.361, 1.636, -1.134, 1.315,
|
||||
0.201, 0.034, 0.097, -0.170, 0.054, -0.553, -0.024, -0.181,
|
||||
-0.700, -0.361, -0.789, 0.279, -0.174, -0.009, -0.323, -0.658,
|
||||
0.348, -0.528, 0.881, 0.021, -0.853, 0.157, 0.648, 1.774,
|
||||
-1.043, 0.051, 0.021, 0.247, -0.310, 0.171, 0.000, 0.106,
|
||||
0.024, -0.386, 0.962, 0.765, -0.125, -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,
|
||||
]
|
||||
|
||||
dys = [
|
||||
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.089, 0.208,
|
||||
0.585, 0.633, -0.444, -0.351, -1.087, 0.199, 0.701, 0.096,
|
||||
-0.025, -0.868, 1.051, 0.157, 0.216, 0.162, 0.249, -0.007,
|
||||
0.009, 0.508, -0.790, 0.723, 0.881, -0.508, 0.393, -0.226,
|
||||
0.710, 0.038, -0.217, 0.831, 0.480, 0.407, 0.447, -0.295,
|
||||
1.126, 0.380, 0.549, -0.445, -0.046, 0.428, -0.074, 0.217,
|
||||
-0.822, 0.491, 1.347, -0.141, 1.230, -0.044, 0.079, 0.219,
|
||||
0.698, 0.275, 0.056, 0.031, 0.421, 0.064, 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,
|
||||
]
|
||||
)
|
||||
|
||||
fn funnel(fa []f64, r Rule) []f64 {
|
||||
mut x := 0.0
|
||||
mut result := []f64{len: fa.len}
|
||||
for i, f in fa {
|
||||
result[i] = x + f
|
||||
x = r(x, f)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
fn mean(fa []f64) f64 {
|
||||
mut sum := 0.0
|
||||
for f in fa {
|
||||
sum += f
|
||||
}
|
||||
return sum / f64(fa.len)
|
||||
}
|
||||
|
||||
fn std_dev(fa []f64) f64 {
|
||||
m := mean(fa)
|
||||
mut sum := 0.0
|
||||
for f in fa {
|
||||
sum += (f - m) * (f - m)
|
||||
}
|
||||
return math.sqrt(sum / f64(fa.len))
|
||||
}
|
||||
|
||||
fn experiment(label string, r Rule) {
|
||||
rxs := funnel(dxs, r)
|
||||
rys := funnel(dys, r)
|
||||
println("$label : x y")
|
||||
println("Mean : ${mean(rxs):7.4f}, ${mean(rys):7.4f}")
|
||||
println("Std Dev : ${std_dev(rxs):7.4f}, ${std_dev(rys):7.4f}")
|
||||
println('')
|
||||
}
|
||||
|
||||
fn main() {
|
||||
experiment("Rule 1", fn(_ f64, _ f64) f64 {
|
||||
return 0.0
|
||||
})
|
||||
experiment("Rule 2", fn(_ f64, dz f64) f64 {
|
||||
return -dz
|
||||
})
|
||||
experiment("Rule 3", fn(z f64, dz f64) f64 {
|
||||
return -(z + dz)
|
||||
})
|
||||
experiment("Rule 4", fn(z f64, dz f64) f64 {
|
||||
return z + dz
|
||||
})
|
||||
}
|
||||
59
Task/Demings-funnel/Wren/demings-funnel.wren
Normal file
59
Task/Demings-funnel/Wren/demings-funnel.wren
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
import "/math" for Nums
|
||||
import "/fmt" for Fmt
|
||||
|
||||
var dxs = [
|
||||
-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.034, -0.126, 0.014,
|
||||
0.709, 0.129, -1.093, -0.483, -1.193, 0.020, -0.051, 0.047,
|
||||
-0.095, 0.695, 0.340, -0.182, 0.287, 0.213, -0.423, -0.021,
|
||||
-0.134, 1.798, 0.021, -1.099, -0.361, 1.636, -1.134, 1.315,
|
||||
0.201, 0.034, 0.097, -0.170, 0.054, -0.553, -0.024, -0.181,
|
||||
-0.700, -0.361, -0.789, 0.279, -0.174, -0.009, -0.323, -0.658,
|
||||
0.348, -0.528, 0.881, 0.021, -0.853, 0.157, 0.648, 1.774,
|
||||
-1.043, 0.051, 0.021, 0.247, -0.310, 0.171, 0.000, 0.106,
|
||||
0.024, -0.386, 0.962, 0.765, -0.125, -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
|
||||
]
|
||||
|
||||
var dys = [
|
||||
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.089, 0.208,
|
||||
0.585, 0.633, -0.444, -0.351, -1.087, 0.199, 0.701, 0.096,
|
||||
-0.025, -0.868, 1.051, 0.157, 0.216, 0.162, 0.249, -0.007,
|
||||
0.009, 0.508, -0.790, 0.723, 0.881, -0.508, 0.393, -0.226,
|
||||
0.710, 0.038, -0.217, 0.831, 0.480, 0.407, 0.447, -0.295,
|
||||
1.126, 0.380, 0.549, -0.445, -0.046, 0.428, -0.074, 0.217,
|
||||
-0.822, 0.491, 1.347, -0.141, 1.230, -0.044, 0.079, 0.219,
|
||||
0.698, 0.275, 0.056, 0.031, 0.421, 0.064, 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
|
||||
]
|
||||
|
||||
var funnel = Fn.new { |fa, r|
|
||||
var x = 0
|
||||
var res = List.filled(fa.count, 0)
|
||||
for (i in 0...fa.count) {
|
||||
var f = fa[i]
|
||||
res[i] = x + f
|
||||
x = r.call(x, f)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
var experiment = Fn.new { |label, r|
|
||||
var rxs = funnel.call(dxs, r)
|
||||
var rys = funnel.call(dys, r)
|
||||
System.print("%(label) : x y")
|
||||
System.print("Mean : %(Fmt.f(7, Nums.mean(rxs), 4)), %(Fmt.f(7, Nums.mean(rys), 4))")
|
||||
System.print("Std Dev : %(Fmt.f(7, Nums.popStdDev(rxs), 4)), %(Fmt.f(7, Nums.popStdDev(rys), 4))")
|
||||
System.print()
|
||||
}
|
||||
|
||||
experiment.call("Rule 1") { |z, dz| 0 }
|
||||
experiment.call("Rule 2") { |z, dz| -dz }
|
||||
experiment.call("Rule 3") { |z, dz| -(z + dz) }
|
||||
experiment.call("Rule 4") { |z, dz| z + dz }
|
||||
88
Task/Demings-funnel/XPL0/demings-funnel.xpl0
Normal file
88
Task/Demings-funnel/XPL0/demings-funnel.xpl0
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
include xpllib; \for Print
|
||||
|
||||
func real Mean(Array, Size);
|
||||
real Array; int Size;
|
||||
real Sum;
|
||||
int I;
|
||||
[Sum:= 0.0;
|
||||
for I:= 0 to Size-1 do
|
||||
Sum:= Sum + Array(I);
|
||||
return Sum / float(Size);
|
||||
];
|
||||
|
||||
func real StdDev(Array, Size);
|
||||
real Array; int Size;
|
||||
real M, Sum;
|
||||
int I;
|
||||
[M:= Mean(Array, Size);
|
||||
Sum:= 0.0;
|
||||
for I:= 0 to Size-1 do
|
||||
Sum:= Sum + (Array(I)-M) * (Array(I)-M);
|
||||
return sqrt(Sum / float(Size));
|
||||
];
|
||||
|
||||
func real Funnel(Array, Size, Rule);
|
||||
real Array; int Size, Rule;
|
||||
real Posn, Result, Fall;
|
||||
int AddrResult, I;
|
||||
def SizeOfReal = 8; \bytes
|
||||
[AddrResult:= addr Result;
|
||||
AddrResult(0):= MAlloc(Size*SizeOfReal);
|
||||
AddrResult(1):= 0; \for safety
|
||||
Posn:= 0.0;
|
||||
for I:= 0 to Size-1 do
|
||||
[Fall:= Array(I);
|
||||
Result(I):= Posn + Fall;
|
||||
case Rule of
|
||||
1: [];
|
||||
2: Posn:= -Fall;
|
||||
3: Posn:= -(Posn+Fall);
|
||||
4: Posn:= Posn+Fall
|
||||
other [];
|
||||
];
|
||||
return Result;
|
||||
];
|
||||
|
||||
func Experiment(Rule);
|
||||
int Rule;
|
||||
real DXs, DYs, RXs, RYs;
|
||||
def Size = 100;
|
||||
[
|
||||
DXs:= [ -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.034, -0.126, 0.014,
|
||||
0.709, 0.129, -1.093, -0.483, -1.193, 0.020, -0.051, 0.047,
|
||||
-0.095, 0.695, 0.340, -0.182, 0.287, 0.213, -0.423, -0.021,
|
||||
-0.134, 1.798, 0.021, -1.099, -0.361, 1.636, -1.134, 1.315,
|
||||
0.201, 0.034, 0.097, -0.170, 0.054, -0.553, -0.024, -0.181,
|
||||
-0.700, -0.361, -0.789, 0.279, -0.174, -0.009, -0.323, -0.658,
|
||||
0.348, -0.528, 0.881, 0.021, -0.853, 0.157, 0.648, 1.774,
|
||||
-1.043, 0.051, 0.021, 0.247, -0.310, 0.171, 0.000, 0.106,
|
||||
0.024, -0.386, 0.962, 0.765, -0.125, -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 ];
|
||||
|
||||
DYs:= [ 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.089, 0.208,
|
||||
0.585, 0.633, -0.444, -0.351, -1.087, 0.199, 0.701, 0.096,
|
||||
-0.025, -0.868, 1.051, 0.157, 0.216, 0.162, 0.249, -0.007,
|
||||
0.009, 0.508, -0.790, 0.723, 0.881, -0.508, 0.393, -0.226,
|
||||
0.710, 0.038, -0.217, 0.831, 0.480, 0.407, 0.447, -0.295,
|
||||
1.126, 0.380, 0.549, -0.445, -0.046, 0.428, -0.074, 0.217,
|
||||
-0.822, 0.491, 1.347, -0.141, 1.230, -0.044, 0.079, 0.219,
|
||||
0.698, 0.275, 0.056, 0.031, 0.421, 0.064, 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 ];
|
||||
|
||||
RXs:= Funnel(DXs, Size, Rule);
|
||||
RYs:= Funnel(DYs, Size, Rule);
|
||||
Print("Rule %d : X Y\n", Rule);
|
||||
Print("Mean : %3.4f, %3.4f\n", Mean(RXs, Size), Mean(RYs, Size));
|
||||
Print("Std Dev : %3.4f, %3.4f\n", StdDev(RXs, Size), StdDev(RYs, Size));
|
||||
CrLf(0);
|
||||
];
|
||||
|
||||
int R;
|
||||
for R:= 1 to 4 do Experiment(R)
|
||||
23
Task/Demings-funnel/Zkl/demings-funnel-1.zkl
Normal file
23
Task/Demings-funnel/Zkl/demings-funnel-1.zkl
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
fcn funnel(dxs, rule){
|
||||
x:=0.0; rxs:=L();
|
||||
foreach dx in (dxs){
|
||||
rxs.append(x + dx);
|
||||
x = rule(x,dx);
|
||||
}
|
||||
rxs
|
||||
}
|
||||
|
||||
fcn mean(xs){ xs.sum(0.0)/xs.len() }
|
||||
|
||||
fcn stddev(xs){
|
||||
m:=mean(xs);
|
||||
(xs.reduce('wrap(sum,x){ sum + (x-m)*(x-m) },0.0)/xs.len()).sqrt();
|
||||
}
|
||||
|
||||
fcn experiment(label,dxs,dys,rule){
|
||||
rxs:=funnel(dxs,rule); rys:=funnel(dys,rule);
|
||||
label.println();
|
||||
"Mean x, y : %7.4f, %7.4f".fmt(mean(rxs), mean(rys)) .println();
|
||||
"Std dev x, y : %7.4f, %7.4f".fmt(stddev(rxs),stddev(rys)).println();
|
||||
println();
|
||||
}
|
||||
32
Task/Demings-funnel/Zkl/demings-funnel-2.zkl
Normal file
32
Task/Demings-funnel/Zkl/demings-funnel-2.zkl
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
dxs:=T( -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.034, -0.126, 0.014,
|
||||
0.709, 0.129, -1.093, -0.483, -1.193, 0.020, -0.051, 0.047,
|
||||
-0.095, 0.695, 0.340, -0.182, 0.287, 0.213, -0.423, -0.021,
|
||||
-0.134, 1.798, 0.021, -1.099, -0.361, 1.636, -1.134, 1.315,
|
||||
0.201, 0.034, 0.097, -0.170, 0.054, -0.553, -0.024, -0.181,
|
||||
-0.700, -0.361, -0.789, 0.279, -0.174, -0.009, -0.323, -0.658,
|
||||
0.348, -0.528, 0.881, 0.021, -0.853, 0.157, 0.648, 1.774,
|
||||
-1.043, 0.051, 0.021, 0.247, -0.310, 0.171, 0.000, 0.106,
|
||||
0.024, -0.386, 0.962, 0.765, -0.125, -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);
|
||||
|
||||
dys:=T( 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.089, 0.208,
|
||||
0.585, 0.633, -0.444, -0.351, -1.087, 0.199, 0.701, 0.096,
|
||||
-0.025, -0.868, 1.051, 0.157, 0.216, 0.162, 0.249, -0.007,
|
||||
0.009, 0.508, -0.790, 0.723, 0.881, -0.508, 0.393, -0.226,
|
||||
0.710, 0.038, -0.217, 0.831, 0.480, 0.407, 0.447, -0.295,
|
||||
1.126, 0.380, 0.549, -0.445, -0.046, 0.428, -0.074, 0.217,
|
||||
-0.822, 0.491, 1.347, -0.141, 1.230, -0.044, 0.079, 0.219,
|
||||
0.698, 0.275, 0.056, 0.031, 0.421, 0.064, 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);
|
||||
|
||||
experiment("Rule 1:", dxs, dys, fcn(z,dz){ 0.0 });
|
||||
experiment("Rule 2:", dxs, dys, fcn(z,dz){ -dz });
|
||||
experiment("Rule 3:", dxs, dys, fcn(z,dz){ -(z+dz) });
|
||||
experiment("Rule 4:", dxs, dys, fcn(z,dz){ z+dz });
|
||||
Loading…
Add table
Add a link
Reference in a new issue