4 (load(descriptive), float_approx_equal_tolerance : 1e-12, 0);
10 mean(matrix([a, b], [c, d], [e, f]));
11 [(e+c+a)/3,(f+d+b)/3]$
13 (s1 : read_list(file_search ("pidigits.data")), mean(s1));
16 (s2 : read_matrix(file_search ("wind.data")), mean(s2));
17 [9.9485,10.1607,10.8685,15.7166,14.8441]$
26 [17.39586540404041,15.13912778787879,15.63204924242424,
27 32.50152569696971,24.66977392929294]$
33 [4.149928523480858,3.871399812729241,3.933920277534866,
34 5.672434260526957,4.941970881136392]$
37 sqrt(84259)/(30*sqrt(11))$
40 [4.17083509672109,3.89090320978032,3.953738641137555,5.701010936401517,
43 noncentral_moment(s1, 1);
46 noncentral_moment(s2, 1);
47 [9.9485,10.1607,10.8685,15.7166,14.8441]$
49 central_moment(s1, 2);
52 central_moment(s2, 3);
53 [11.29584771375004,16.97988248298583,5.626661952750102,
54 37.5986572057918,25.85981904394192]$
60 [0.4171411291632767,0.3810170374806106,0.3619561372346568,
61 0.3609199356430116,0.3329249251309538]$
67 [0.58,0.5,2.67,5.25,5.17]$
73 [20.25,21.46,20.04,29.63,27.63]$
79 [19.67,20.96,17.37,24.38,22.46]$
81 [quantile(s1, 1/4), quantile (s1, 3/4)];
84 [quantile(s2, 1/4), quantile (s2, 3/4)];
85 [[7.2575,7.477500000000001,7.82,11.28,11.48],
86 [12.6425,13.05,13.8425,20.01,18.13]]$
92 [10.06,9.855,10.73,15.48,14.105]$
98 [5.385,5.572499999999998,6.0225,8.729999999999999,6.649999999999999]$
104 [3.287959999999999,3.075342,3.23907,4.715664000000001,4.028546000000002]$
106 median_deviation(s1);
109 median_deviation(s2);
110 [2.75,2.755,3.08,4.315,3.31]$
112 harmonic_mean([5, 7, 2, 5, 9, 5, 6, 4, 9, 2, 4, 2, 5]);
116 [6.948015590052786,7.391967752360356,9.055658197151745,
117 13.44199028193692,13.01439145898509]$
119 geometric_mean([5, 7, 2, 5, 9, 5, 6, 4, 9, 2, 4, 2, 5]);
123 [8.82476274347979,9.22652604739361,10.0442675714889,14.61274126349021,
127 -9039524486/7099579081$
130 [-0.2715445622195385,0.119998784429451,-0.4275233490482866,
131 -0.6405361979019522,-0.4952382132352935]$
137 [0.1580509020000979,0.2926379232061854,0.09242174416107717,
138 0.2059984348148687,0.2142520248890832]$
140 pearson_skewness(s1);
141 189*sqrt(11)/(10*sqrt(84259))$
143 pearson_skewness(s2);
144 [-0.08019976629211892,0.2357036272952649,0.1050904062491204,
145 0.1245042340592368,0.4464181795804519]$
147 quartile_skewness(s1);
150 quartile_skewness(s2);
151 [-0.0408542246982353,0.1467025572005382,0.0336239103362392,
152 0.03780068728522298,0.2105263157894735]$
155 matrix([17.22190675000003,13.61811305000002,14.37216775000002,
156 19.39623590000002,15.42162414999993],
157 [13.61811305000002,14.98773650999988,13.30448104999995,
158 15.15833837999995,14.97109813],
159 [14.37216775000002,13.30448104999995,15.47572875000003,
160 17.32543690000006,16.18170714999994],
161 [19.39623590000002,15.15833837999995,17.32543690000006,
162 32.17651043999993,20.44684694],
163 [15.42162414999993,14.97109813,16.18170714999994,20.44684694,
167 matrix([17.39586540404044,13.75566974747477,14.51734116161618,
168 19.5921574747475,15.57739813131306],
169 [13.75566974747477,15.13912778787867,13.4388697474747,
170 15.31145290909086,15.12232134343435],
171 [14.51734116161618,13.4388697474747,15.63204924242427,
172 17.50044131313137,16.34515873737368],
173 [19.5921574747475,15.31145290909086,17.50044131313137,
174 32.50152569696963,20.65338074747475],
175 [15.57739813131306,15.12232134343435,16.34515873737368,
176 20.65338074747475,24.66977392929295])$
178 global_variances(s2);
179 [105.338342060606,21.06766841212119,12874.34690469686,113.4651792608501,
180 6.636590811800794,2.576158149609762]$
183 matrix([0.9999999999999999,0.8476338537640531,0.8803514956141143,
184 0.8239623533344873,0.7519506093997077],
185 [0.8476338537640531,1.0,0.8735833741501071,0.6902622161735914,
187 [0.8803514956141142,0.8735833741501071,1.0,0.7764065117828751,
189 [0.8239623533344873,0.6902622161735915,0.7764065117828751,1.0,
191 [0.7519506093997078,0.7825019890410442,0.8323358495832834,
192 0.7293847728156051,0.9999999999999999])$
194 list_correlations(s2);
195 [matrix([0.3848556822758882,-0.138560101587963,-0.1562648597903809,
196 -0.102390587242044,0.03117928520552016],
197 [-0.1385601015879629,0.3410745439686317,-0.1523316288476424,
198 0.03844715039676187,-0.05284247734522295],
199 [-0.1562648597903812,-0.1523316288476423,0.4729580534793429,
200 -0.02481583049369053,-0.1005374388312373],
201 [-0.1023905872420438,0.0384471503967619,-0.02481583049369072,
202 0.1093657733582761,-0.0340329624571618],
203 [0.0311792852055202,-0.05284247734522302,-0.1005374388312372,
204 -0.03403296245716185,0.1483436744385358]),
205 [0.8506325186059345,0.8063355806655949,0.8647424674282196,
206 0.7186707921004887,0.7267464592542312],
207 matrix([-1.0,0.3824411257726334,0.3662697588649121,0.4990802317419231,
208 -0.1304916392931289],
209 [0.3824411257726332,-1.0,0.3792749151468401,
210 -0.1990667787299206,0.2349221680600234],
211 [0.3662697588649129,0.3792749151468399,-0.9999999999999998,
212 0.109113073041974,0.3795613554674849],
213 [0.4990802317419226,-0.1990667787299208,0.1091130730419749,
214 -1.0,0.267192660519117],
215 [-0.1304916392931291,0.2349221680600237,0.3795613554674845,
216 0.2671926605191174,-1.0])]$
218 principal_components(s2);
219 [[87.5689103150044,8.753405888856824,5.514842042315632,
220 1.888527946359889,1.612655868069173],
221 [83.13108845459334,8.30980032305862,5.235360586122282,
222 1.792821027383679,1.530929608842086],
223 matrix([0.4149313791478684,0.03378709673974772,-0.4756919435090896,
224 -0.5810494628723252,-0.5126295731507049],
225 [0.3690402507783501,-0.3656690416147942,-0.4297594804400433,
226 0.7237468707135304,-0.1469445521761402],
227 [0.3959227853488706,-0.2178353948197818,-0.2181101723256928,
228 -0.2749400278061583,0.820139514133606],
229 [0.554792311834466,0.7744297760037389,0.1857057299675782,
230 0.231851193538861,0.06498014065837293],
231 [0.4765415854622357,-0.4668520610438869,0.7120149566109651,
232 -0.09604683228877862,-0.1968933162750588])]$
234 /* DATA MANIPULATION */
236 continuous_freq ([]);
239 continuous_freq (s1, 5);
240 [[0,9/5,18/5,27/5,36/5,9],[16,24,18,17,25]]$
242 continuous_freq (s1, [-2,12,7]);
243 [[-2,0,2,4,6,8,10,12],[8,20,22,17,20,13,0]]$
245 continuous_freq (s1, [-2,12]);
246 [[-2,-3/5,4/5,11/5,18/5,5,32/5,39/5,46/5,53/5,12],[0,8,20,12,18,9,8,25,
249 continuous_freq (random_permutation (makelist (i, i, 0, 100)), 1);
252 continuous_freq (random_permutation (makelist (i, i, 0, 100)), 10);
253 [[0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100], [11, 10, 10, 10, 10, 10, 10, 10, 10, 10]];
255 continuous_freq (makelist (random (100), 100), [0, 100, 1]);
258 continuous_freq (random_permutation (makelist (i, i, 0, 100)), [0, 100, 10]);
259 [[0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100], [11, 10, 10, 10, 10, 10, 10, 10, 10, 10]];
261 continuous_freq (makelist (random (100), 100), {0, 100});
264 continuous_freq (random_permutation (makelist (i, i, 0, 100)), {0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100});
265 [[0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100], [11, 10, 10, 10, 10, 10, 10, 10, 10, 10]];
267 (test_continuous_freq (xx, foo) := block ([output, bins, counts],
268 output : continuous_freq (xx, foo),
269 bins : makelist ([output[1][i], output[1][i + 1]], i, 1, length(output[1]) - 1),
270 counts : count_via_sublist (if listp(xx) then xx else listarray(xx), bins),
271 if counts = output[2]
273 else ['data = xx, 'continuous_freq = output, 'count_via_sublist = counts]),
274 count_via_sublist (xx, bins) :=
275 append ([length (sublist (xx, lambda ([x], first(bins)[1] <= x and x <= first(bins)[2])))],
276 map (lambda ([pq], length (sublist (xx, lambda ([x], pq[1] < x and x <= pq[2])))), rest(bins))),
277 set_random_state (make_random_state (1)),
281 test_continuous_freq (makelist (random (100), 100) * 0.25, 17);
284 test_continuous_freq (makelist (random (100), 100) * 0.25, 100);
287 test_continuous_freq (makelist (random (100), 100) * 0.25, 1);
290 test_continuous_freq (makelist (random (100), 100) * 0.25, [0, 25]);
293 test_continuous_freq (makelist (random (100), 100) * 0.25, [0, 25, 2]);
296 test_continuous_freq (makelist (random (100), 100) * 0.25, [0, 25, 20]);
299 test_continuous_freq (makelist (random (100), 100) * 0.25, [-1000, 1000]);
302 test_continuous_freq (makelist (random (100), 100) * 0.25, [-990, 1010]);
305 test_continuous_freq (makelist (random (10), 100), 10);
308 test_continuous_freq (append (makelist (random (10), 50), 50 + makelist (random (10), 50)), 10);
311 (to_array(l) := fillarray (make_array (any, length(l)), l),
316 continuous_freq (to_array []);
319 continuous_freq (to_array s1, 5);
320 [[0,9/5,18/5,27/5,36/5,9],[16,24,18,17,25]]$
322 continuous_freq (to_array s1, [-2,12,7]);
323 [[-2,0,2,4,6,8,10,12],[8,20,22,17,20,13,0]]$
325 continuous_freq (to_array s1, [-2,12]);
326 [[-2,-3/5,4/5,11/5,18/5,5,32/5,39/5,46/5,53/5,12],[0,8,20,12,18,9,8,25,
329 test_continuous_freq (to_array (makelist (random (100), 100) * 0.25), 17);
332 test_continuous_freq (to_array (makelist (random (100), 100) * 0.25), 100);
335 test_continuous_freq (to_array (makelist (random (100), 100) * 0.25), 1);
338 test_continuous_freq (to_array (makelist (random (100), 100) * 0.25), [0, 25]);
341 test_continuous_freq (to_array (makelist (random (100), 100) * 0.25), [0, 25, 2]);
344 test_continuous_freq (to_array (makelist (random (100), 100) * 0.25), [0, 25, 20]);
347 test_continuous_freq (to_array (makelist (random (100), 100) * 0.25), [-1000, 1000]);
350 test_continuous_freq (to_array (makelist (random (100), 100) * 0.25), [-990, 1010]);
353 test_continuous_freq (to_array makelist (random (10), 100), 10);
356 test_continuous_freq (to_array append (makelist (random (10), 50), 50 + makelist (random (10), 50)), 10);
359 /* SF bug #3685: "continuous_freq causes Lisp error given rational numbers" */
361 continuous_freq (random_permutation ([0, 1/2, 1/2, 1/2, 2/3, 2/3, 3/4, 3/4, 3/4, 3/4, 1, 1, 4]), [0, 5, 10]);
362 [[0, 1/2, 1, 3/2, 2, 5/2, 3, 7/2, 4, 9/2, 5], [4, 8, 0, 0, 0, 0, 0, 1, 0, 0]];
364 continuous_freq (random_permutation (bfloat ([0, 1/2, 1/2, 1/2, 2/3, 2/3, 3/4, 3/4, 3/4, 3/4, 1, 1, 4])), [0b0, 5b0, 10]);
365 [[0b0, 0.5b0, 1b0, 1.5b0, 2b0, 2.5b0, 3b0, 3.5b0, 4b0, 4.5b0, 5b0], [4, 8, 0, 0, 0, 0, 0, 1, 0, 0]];
367 /* additional tests for #3685; verify that continuous_freq continues to work as long as elements are comparable. */
369 continuous_freq (%pi + random_permutation ([0, 1/2, 1/2, 1/2, 2/3, 2/3, 3/4, 3/4, 3/4, 3/4, 1, 1, 4]), [%pi, %pi + 5, 10]);
370 [[%pi, %pi + 1/2, %pi + 1, %pi + 3/2, %pi + 2, %pi + 5/2, %pi + 3, %pi + 7/2, %pi + 4, %pi + 9/2, %pi + 5],
371 [4, 8, 0, 0, 0, 0, 0, 1, 0, 0]];
373 (kill(a), continuous_freq (a + random_permutation ([0, 1/2, 1/2, 1/2, 2/3, 2/3, 3/4, 3/4, 3/4, 3/4, 1, 1, 4]), [a, a + 5, 10]));
374 [[a, a + 1/2, a + 1, a + 3/2, a + 2, a + 5/2, a + 3, a + 7/2, a + 4, a + 9/2, a + 5], [4, 8, 0, 0, 0, 0, 0, 1, 0, 0]];
376 (assume (a > 0), continuous_freq (a * random_permutation ([0, 1/2, 1/2, 1/2, 2/3, 2/3, 3/4, 3/4, 3/4, 3/4, 1, 1, 4]), 8));
377 [[0, a/2, a, 3*a/2, 2*a, 5*a/2, 3*a, 7*a/2, 4*a], [4, 8, 0, 0, 0, 0, 0, 1]];
386 [[0,1,2,3,4,5,6,7,8,9],[8,8,12,12,10,8,9,8,12,13]]$
388 discrete_freq (map (lambda ([x], printf (false, "~r", x)), s1));
389 [["eight", "five", "four", "nine", "one", "seven", "six", "three", "two", "zero"],
390 [12, 8, 10, 13, 8, 8, 9, 12, 12, 8]];
392 discrete_freq (map (lambda ([x], concat ('x, printf (false, "~r", x))), s1));
393 ['[xeight, xfive, xfour, xnine, xone, xseven, xsix, xthree, xtwo, xzero],
394 [12, 8, 10, 13, 8, 8, 9, 12, 12, 8]];
396 (test_discrete_freq (xx) := block ([output, counts],
397 output : discrete_freq (xx),
398 counts : count_via_sublist (if listp(xx) then xx else listarray(xx)),
399 if counts = output[2]
401 else ['data = xx, 'discrete_freq = output, 'count_via_sublist = counts]),
402 count_via_sublist (xx) :=
403 map (lambda ([x1], length (sublist (xx, lambda ([x], x = x1)))), unique (xx)),
404 set_random_state (make_random_state (2)),
408 test_discrete_freq (makelist (random (20), 1));
411 test_discrete_freq (makelist (random (20), 10));
414 test_discrete_freq (makelist (random (20), 100));
417 test_discrete_freq (makelist (random (20), 1000));
420 test_discrete_freq (makelist (random (100), 100) * 0.25);
423 test_discrete_freq (append (makelist (random (20), 50), 50 + makelist (random (20), 50)));
426 discrete_freq (to_array []);
429 discrete_freq (to_array s1);
430 [[0,1,2,3,4,5,6,7,8,9],[8,8,12,12,10,8,9,8,12,13]]$
432 discrete_freq (to_array map (lambda ([x], printf (false, "~r", x)), s1));
433 [["eight", "five", "four", "nine", "one", "seven", "six", "three", "two", "zero"],
434 [12, 8, 10, 13, 8, 8, 9, 12, 12, 8]];
436 discrete_freq (to_array map (lambda ([x], concat ('x, printf (false, "~r", x))), s1));
437 ['[xeight, xfive, xfour, xnine, xone, xseven, xsix, xthree, xtwo, xzero],
438 [12, 8, 10, 13, 8, 8, 9, 12, 12, 8]];
440 test_discrete_freq (to_array makelist (random (20), 1));
443 test_discrete_freq (to_array makelist (random (20), 10));
446 test_discrete_freq (to_array makelist (random (20), 100));
449 test_discrete_freq (to_array makelist (random (20), 1000));
452 test_discrete_freq (to_array (makelist (random (100), 100) * 0.25));
455 test_discrete_freq (to_array append (makelist (random (20), 50), 50 + makelist (random (20), 50)));
458 part(standardize(s1), [1, 10, 20]);
459 [-171/sqrt(84259),-171/sqrt(84259),-71/sqrt(84259)]$
461 subsample (s2, lambda([v], v[1] > 18));
462 matrix([19.38,15.37,15.12,23.09,25.25],[18.29,18.66,19.08,26.08,27.63],
463 [20.25,21.46,19.95,27.71,23.38],[18.79,18.96,14.46,26.38,21.84])$
465 subsample (s2, g, 1, 2, 5), g(x):= first(x) >= 16 and fourth(x) < 25;
466 matrix([19.38,15.37,25.25],[17.33,14.67,19.58],[16.92,13.21,21.21],
467 [17.25,18.46,23.87])$
469 transform_sample(data, [a,b,c], [c, a*b, log(a)]), data: matrix([3,2,7],[3,7,2],[8,2,4],[5,2,4]);
470 matrix([7,6,log(3)],[2,21,log(3)],[4,16,log(8)],[4,10,log(5)])$
472 (reset (float_approx_equal_tolerance), 0);
487 find_runs ([1000, 1000]);
490 find_runs ([1, 1000]);
491 runs ([1, 1], [1, 1000]);
493 find_runs ([1000, 1]);
494 runs ([1, 1], [1000, 1]);
496 find_runs ([2, 2, 2]);
499 find_runs ([2, 2, 2, 2, 2, 2]);
502 (set_random_state (make_random_state (3)),
503 test_find_runs (x) :=
504 block ([r: find_runs (x), y],
505 y: find_runs_inverse (r),
507 else ['data = x, 'find_runs = r, 'find_runs_inverse = y]),
511 test_find_runs (l: makelist (random (m), n)), m = 2, n = 3;
514 test_find_runs (sort (l));
517 test_find_runs (l: makelist (random (m), n)), m = 2, n = 9;
520 test_find_runs (sort (l));
523 test_find_runs (l: makelist (random (m), n)), m = 2, n = 27;
526 test_find_runs (sort (l));
529 test_find_runs (l: makelist (random (m), n)), m = 10, n = 3;
532 test_find_runs (sort (l));
535 test_find_runs (l: makelist (random (m), n)), m = 10, n = 9;
538 test_find_runs (sort (l));
541 test_find_runs (l: makelist (random (m), n)), m = 10, n = 27;
544 test_find_runs (sort (l));
547 test_find_runs (l: makelist (random (m), n)), m = 100, n = 3;
550 test_find_runs (sort (l));
553 test_find_runs (l: makelist (random (m), n)), m = 100, n = 9;
556 test_find_runs (sort (l));
559 test_find_runs (l: makelist (random (m), n)), m = 100, n = 27;
562 test_find_runs (sort (l));
565 (kill (a, b, c, d, e, f, g, h, i, j),
566 test_find_runs_with_symbols (l) :=
567 block ([eqs: [0 = a, 1 = b, 2 = c, 3 = d, 4 = e, 5 = f, 6 = g, 7 = h, 8 = i, 9 = j]],
568 test_find_runs (subst (eqs, l))),
582 runs ([1, 1], [a, b]);
585 runs ([1, 1], [b, a]);
590 test_find_runs_with_symbols (l: makelist (random (m), n)), m = 10, n = 3;
593 test_find_runs_with_symbols (sort (l));
596 test_find_runs_with_symbols (l: makelist (random (m), n)), m = 10, n = 9;
599 test_find_runs_with_symbols (sort (l));
602 test_find_runs_with_symbols (l: makelist (random (m), n)), m = 10, n = 27;
605 test_find_runs_with_symbols (sort (l));
614 find_runs (["foo", "foo"]);
617 find_runs (["foo", "bar"]);
618 runs ([1, 1], ["foo", "bar"]);
620 find_runs (["bar", "foo"]);
621 runs ([1, 1], ["bar", "foo"]);
623 find_runs (["bar", "bar"]);
626 (test_find_runs_with_strings (l) :=
627 block ([eqs: [0 = "foo", 1 = "bar", 2 = "baz", 3 = "quux", 4 = "mumble", 5 = "blurf", 6 = "blart", 7 = "wheeze", 8 = "snort", 9 = "sigh"]],
628 test_find_runs (subst (eqs, l))),
632 test_find_runs_with_strings (l: makelist (random (m), n)), m = 10, n = 3;
635 test_find_runs_with_strings (sort (l));
638 test_find_runs_with_strings (l: makelist (random (m), n)), m = 10, n = 9;
641 test_find_runs_with_strings (sort (l));
644 test_find_runs_with_strings (l: makelist (random (m), n)), m = 10, n = 27;
647 test_find_runs_with_strings (sort (l));