-
Notifications
You must be signed in to change notification settings - Fork 1
/
grsp5.scm
4808 lines (4189 loc) · 84.1 KB
/
grsp5.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;; =========================================================================
;;
;; grsp5.scm
;;
;; Stats and probabilistic functions.
;;
;; =========================================================================
;;
;; Copyright (C) 2018 - 2024 Pablo Edronkin (pablo.edronkin at yahoo.com)
;;
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU Lesser General Public License as
;; published by the Free Software Foundation, either version 3 of the
;; License, or (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU Lesser General Public License for more details.
;;
;; You should have received a copy of the GNU Lesser General Public
;; License along with this program. If not, see
;; <https://www.gnu.org/licenses/>.
;;
;; =========================================================================
;;;; General notes:
;;
;; - Read sources for limitations on function parameters.
;;
;; Sources:
;;
;; See code of functions used and their respective source files for more
;; credits and references.
;;
;; - [1] En.wikipedia.org. 2020. Probability. [online] Available at:
;; https://en.wikipedia.org/wiki/Probability [Accessed 23 July 2020].
;; - [2] En.wikipedia.org. 2020. Bayes' Theorem [online] Available at:
;; https://en.wikipedia.org/wiki/Bayes%27_theorem [Accessed 23 July 2020].
;; - [3] Statistics How To. 2020. Normalized Data / Normalization -
;; Statistics How To. [online] Available at:
;; https://www.statisticshowto.datasciencecentral.com/normalized/
;; [Accessed 23 July 2020].
;; - [4] En.wikipedia.org. 2020. Poisson Distribution. [online] Available
;; at: https://en.wikipedia.org/wiki/Poisson_distribution
;; [Accessed 23 November 2020].
;; - [5] En.wikipedia.org. 2020. Probability Mass Function. [online]
;; Available at: https://en.wikipedia.org/wiki/Probability_mass_function
;; [Accessed 23 November 2020].
;; - [6] En.wikipedia.org. 2020. Gamma Distribution. [online] Available at:
;; https://en.wikipedia.org/wiki/Gamma_distribution
;; [Accessed 3 December 2020].
;; - [7] En.wikipedia.org. 2020. Erlang Distribution. [online] Available at:
;; https://en.wikipedia.org/wiki/Erlang_distribution
;; [Accessed 11 December 2020].
;; - [8] En.wikipedia.org. 2020. Entropy (Information Theory). [online]
;; Available at:
;; https://en.wikipedia.org/wiki/Entropy_(information_theory)
;; [Accessed 13 December 2020].
;; - [9] En.wikipedia.org. 2020. Information Content. [online] Available at:
;; https://en.wikipedia.org/wiki/Information_content
;; [Accessed 13 December 2020].
;; - [10] En.wikipedia.org. 2020. Standard Deviation. [online] Available at:
;; https://en.wikipedia.org/wiki/Standard_deviation
;; [Accessed 15 December 2020].
;; - [11] En.wikipedia.org. 2020. Normal Distribution. [online] Available
;; at: https://en.wikipedia.org/wiki/Normal_distribution
;; [Accessed 15 December 2020].
;; - [12] En.wikipedia.org. 2020. Bessel's Correction. [online] Available
;; at: https://en.wikipedia.org/wiki/Bessel%27s_correction
;; [Accessed 16 December 2020].
;; - [13] En.wikipedia.org. 2020. Expected Value. [online] Available at:
;; https://en.wikipedia.org/wiki/Expected_value [Accessed 21 December
;; 2020].
;; - [14] En.wikipedia.org. 2020. Variance. [online] Available at:
;; https://en.wikipedia.org/wiki/Variance [Accessed 21 December 2020].
;; - [15] En.wikipedia.org. 2020. Coefficient Of Variation. [online]
;; Available at: https://en.wikipedia.org/wiki/Coefficient_of_variation
;; [Accessed 21 December 2020].
;; - [16] En.wikipedia.org. 2020. Average Absolute Deviation. [online]
;; Available at: https://en.wikipedia.org/wiki/Average_absolute_deviation
;; [Accessed 21 December 2020].
;; - [17] En.wikipedia.org. 2020. Kullback–Leibler Divergence. [online]
;; Available at:
;; https://en.wikipedia.org/wiki/Kullback%E2%80%93Leibler_divergence
;; [Accessed 23 December 2020].
;; - [18] En.wikipedia.org. 2020. Moment-Generating Function. [online]
;; Available at:
;; https://en.wikipedia.org/wiki/Moment-generating_function [Accessed 23
;; December 2020].
;; - [19] En.wikipedia.org. 2020. Fisher Information. [online] Available
;; at: https://en.wikipedia.org/wiki/Fisher_information [Accessed 29
;; December 2020].
;; - [20] En.wikipedia.org. 2020. Skewness. [online] Available at:
;; https://en.wikipedia.org/wiki/Skewness [Accessed 29 December 2020].
;; - [21] En.wikipedia.org. 2020. Nonparametric Skew. [online] Available
;; at: https://en.wikipedia.org/wiki/Nonparametric_skew [Accessed 29
;; December 2020].
;; - [22] En.wikipedia.org. 2020. Moment (Mathematics). [online] Available
;; at: https://en.wikipedia.org/wiki/Moment_(mathematics) [Accessed 29
;; December 2020].
;; - [23] En.wikipedia.org. 2020. Kurtosis. [online] Available at:
;; https://en.wikipedia.org/wiki/Kurtosis [Accessed 29 December 2020].
;; - [24] En.wikipedia.org. 2020. Quartile. [online] Available at:
;; https://en.wikipedia.org/wiki/Quartile [Accessed 29 December 2020].
;; - [25] En.wikipedia.org. 2020. Interquartile Range. [online] Available
;; at: https://en.wikipedia.org/wiki/Interquartile_range
;; [Accessed 29 December 2020].
;; - [26] En.wikipedia.org. 2021. Summary Statistics. [online] Available
;; at: https://en.wikipedia.org/wiki/Summary_statistics [Accessed 1
;; January 2021].
;; - [27] En.wikipedia.org. 2021. Five-Number Summary. [online] Available
;; at: https://en.wikipedia.org/wiki/Five-number_summary [Accessed 1
;; January 2021].
;; - [28] En.wikipedia.org. 2021. Range (Statistics). [online] Available
;; at: https://en.wikipedia.org/wiki/Range_(statistics) [Accessed 1
;; January 2021].
;; - [29] En.wikipedia.org. 2021. Algorithms For Calculating Variance.
;; [online] Available at:
;; https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance
;; [Accessed 3 January 2021].
;; - [30] En.wikipedia.org. 2021. Mode (statistics). [online] Available at:
;; https://en.wikipedia.org/wiki/Mode_(statistics) [Accessed 3 January
;; 2021].
;; - [31] En.wikipedia.org. 2021. Frequency (statistics). [online]
;; Available at: https://en.wikipedia.org/wiki/Frequency_(statistics)
;; [Accessed 3 January 2021].
;; - [32] En.wikipedia.org. 2021. Unimodality. [online] Available at:
;; https://en.wikipedia.org/wiki/Unimodality [Accessed 3 January 2021].
;; - [33] En.wikipedia.org. 2021. Central Tendency. [online] Available at:
;; https://en.wikipedia.org/wiki/Central_tendency [Accessed 23 January
;; 2021].
;; - [34] En.wikipedia.org. 2021. Geometric Mean. [online] Available at:
;; https://en.wikipedia.org/wiki/Geometric_mean [Accessed 23 January
;; 2021].
;; - [35] En.wikipedia.org. 2021. Interquartile mean. [online] Available
;; at: https://en.wikipedia.org/wiki/Interquartile_mean [Accessed 14
;; February 2021].
;; - [36] En.wikipedia.org. 2021. Root mean square. [online] Available at:
;; https://en.wikipedia.org/wiki/Quadratic_mean [Accessed 14 February
;; 2021].
;; - [37] En.wikipedia.org. 2021. Mid-range. [online] Available at:
;; https://en.wikipedia.org/wiki/Mid-range [Accessed 14 February 2021].
;; - [38] En.wikipedia.org. 2021. Weibull distribution. [online] Available
;; at: https://en.wikipedia.org/wiki/Weibull_distribution [Accessed 19
;; February 2021].
;; - [39] Publishing, R., 2021. Weibull Distribution: Characteristics of
;; the Weibull Distribution. [online] Weibull.com. Available at:
;; https://www.weibull.com/hotwire/issue14/relbasics14.htm [Accessed 19
;; February 2021].
;; - [40] En.wikipedia.org. 2021. Chi distribution. [online] Available at:
;; https://en.wikipedia.org/wiki/Chi_distribution [Accessed 19 February
;; 2021].
;; - [41] En.wikipedia.org. 2021. Theil–Sen estimator - Wikipedia. [online]
;; Available at:
;; https://en.wikipedia.org/wiki/Theil%E2%80%93Sen_estimator
;; [Accessed 10 April 2021].
;; - [42] En.wikipedia.org. 2021. Triangular distribution - Wikipedia.
;; [online] Available at:
;; https://en.wikipedia.org/wiki/Triangular_distribution [Accessed 13
;; September 2021].
;; - [43] En.wikipedia.org. 2021. Continuous uniform distribution -
;; Wikipedia. [online] Available at:
;; https://en.wikipedia.org/wiki/Continuous_uniform_distribution
;; [Accessed 3 October 2021].
;; - [44] En.wikipedia.org. 2021. Gumbel distribution - Wikipedia. [online]
;; Available at: https://en.wikipedia.org/wiki/Gumbel_distribution
;; [Accessed 14 October 2021].
;; - [45] Principal component analysis (2023) Wikipedia. Wikimedia
;; Foundation. Available at:
;; https://en.wikipedia.org/wiki/Principal_component_analysis
;; (Accessed: March 13, 2023).
(define-module (grsp grsp5)
#:use-module (grsp grsp0)
#:use-module (grsp grsp1)
#:use-module (grsp grsp2)
#:use-module (grsp grsp3)
#:use-module (grsp grsp4)
#:use-module (grsp grsp7)
#:use-module (grsp grsp11)
#:use-module (ice-9 threads)
#:export (grsp-feature-scaling
grsp-z-score
grsp-binop
grsp-pnot
grsp-pand
grsp-pnand
grsp-por
grsp-pxor
grsp-pcond
grsp-pcomp
grsp-osbv
grsp-obsv
grsp-entropy-dvar
grsp-mean1
grsp-mean1-mth
grsp-mean2
grsp-mean3
grsp-mean-geometric
grsp-mean-geometric-mth
grsp-mean-interquartile
grsp-mean-quadratic
grsp-midrange
grsp-sd1
grsp-sd2
grsp-variance1
grsp-variance2
grsp-surprisal
grsp-median1
grsp-cv
grsp-mad
grsp-bessel-corrector
grsp-np-skew
grsp-pearson-mode-skewness
grsp-pearson-median-skewness
grsp-standardized-3cm
grsp-standardized-4cm
grsp-excess-kurtosis
grsp-sample-skewness
grsp-yule-coefficient
grsp-iqr
grsp-5ns
grsp-range
grsp-covariance1
grsp-frequency-absolute
grsp-mode
grsp-poisson-pmf
grsp-poisson-pmf-mth
grsp-poisson-kurtosis
grsp-poisson-skewness
grsp-poisson-fisher
grsp-gamma-mean1
grsp-gamma-mean2
grsp-gamma-variance1
grsp-gamma-variance2
grsp-gamma-kurtosis
grsp-gamma-skewness
grsp-gamma-mode1
grsp-gamma-mode2
grsp-gamma-pdf1
grsp-gamma-pdf1-mth
grsp-gamma-pdf2
grsp-gamma-pdf2-mth
grsp-gamma-cdf1
grsp-gamma-cdf1-mth
grsp-gamma-cdf2
grsp-gamma-cdf2-mth
grsp-gamma-mgf1
grsp-gamma-mgf2
grsp-erlang-mean
grsp-erlang-variance
grsp-erlang-kurtosis
grsp-erlang-skewness
grsp-erlang-mode
grsp-erlang-pdf
grsp-erlang-cdf
grsp-erlang-mgf
grsp-erlang-scale
grsp-normal-pdf
grsp-normal-pdf-mth
grsp-normal-entropy
grsp-normal-entropy-relative
grsp-normal-entropy-relative-mth
grsp-normal-fisher
grsp-normal-fisher-mth
grsp-weibull-median
grsp-weibull-mean
grsp-weibull-mode
grsp-weibull-cdf
grsp-weibull-pdf
grsp-weibull-entropy
grsp-weibull-entropy-mth
grsp-weibull-variance
grsp-weibull-skewness
grsp-weibull-skewness-mth
grsp-weibull-mgf
grsp-weibull-cf
grsp-theil-sen-estimator
grsp-theil-sen-estimator-mth
grsp-triangular-kurtosis
grsp-triangular-mean
grsp-triangular-variance
grsp-triangular-median
grsp-triangular-pdf
grsp-triangular-entropy
grsp-triangular-cdf
grsp-triangular-skewness
grsp-cuniform-mean
grsp-cuniform-median
grsp-cuniform-support
grsp-cuniform-pdf
grsp-cuniform-cgf
grsp-cuniform-cdf
grsp-cuniform-variance
grsp-cuniform-entropy
grsp-cuniform-kurtosis
grsp-cuniform-skewness
grsp-gumbel-support
grsp-gumbel-kurtosis
grsp-gumbel-median
grsp-gumbel-skewness
grsp-gumbel-pdf
grsp-gumbel-cdf
grsp-gumbel-mean
grsp-gumbel-variance
grsp-gumbel-entropy
grsp-pca))
;;;; grsp-feature-scaling - Scales item with value p_n1 to the interval
;; [p_nmin, p_nmax].
;;
;; Keywords:
;;
;; - statistics, probability, scale, proportion, rescaling, min-max,
;; normalization
;;
;; Parameters:
;;
;; - p_n1: scalar, real.
;; - p_nmin: min value for p_n.
;; - p_max: max value for p_x.
;;
;; Notes:
;;
;; - If p_n1 lies outside the interval [p_nmin, p_nmax] the function will
;; truncate p_n1 to fit it within the interval.
;;
;; Output:
;;
;; - Numeric.
;;
;; Sources:
;;
;; - [3].
;;
(define (grsp-feature-scaling p_n1 p_nmin p_nmax)
(let ((res1 0.0))
(cond ((> p_n1 p_nmax)
(set! p_nmax p_n1))
((< p_n1 p_nmin)
(set! p_nmin p_n1)))
(set! res1 (* 1.0 (/ (- p_n1 p_nmin)
(- p_nmax p_nmin))))
res1))
;;;; grsp-z-score - Calculates the z score for a sample data point.
;;
;; Keywords:
;;
;; - statistics, probability, scoring, sampling
;;
;; Parameters:
;;
;; - p_n1: data point.
;; - p_m1: sample mean.
;; - p_s1: sample standard deviation.
;;
;; Output:
;;
;; - Numeric.
;;
;; Sources:
;;
;; - [3].
;;
(define (grsp-z-score p_n1 p_m1 p_s1)
(let ((res1 0.0))
(set! res1 (* 1.0 (/ (- p_n1 p_m1) p_s1)))
res1))
;;;; grsp-binop - Performs an operation p_s1 on p_n1 and p_n2 and
;; calculates the p_n3 power of that binomial operation.
;;
;; Keywords:
;;
;; - statistics, probability
;;
;; Parameters:
;;
;; - p_s1: string determining the operation.
;;
;; - "#+": sum.
;; - "#-": substraction.
;; - "#*": multiplication.
;; - "#/": division.
;;
;; - p_n1: real.
;; - p_n2: real.
;; - p_n3: real.
;;
;; Output:
;;
;; - Numeric.
;;
;; Sources:
;;
;; - [1].
;;
(define (grsp-binop p_s1 p_n1 p_n2 p_n3)
(let ((res1 0.0))
(cond ((equal? p_s1 "#+")
(set! res1 (expt (+ p_n1 p_n2) p_n3)))
((equal? p_s1 "#-")
(set! res1 (expt (- p_n1 p_n2) p_n3)))
((equal? p_s1 "#*")
(set! res1 (expt (- p_n1 p_n2) p_n3)))
((equal? p_s1 "#/")
(set! res1 (expt (- p_n1 p_n2) p_n3))))
res1))
;;;; grsp-pnot - Calculates the complementary probability of p_n1.
;;
;; Keywords:
;;
;; - statistics, probability, complements
;;
;; Parameters:
;;
;; - p_n1: real representing a probability in [0,1].
;;
;; Output:
;;
;; - Numeric.
;;
;; Sources:
;;
;; - [1].
;;
(define (grsp-pnot p_n1)
(let ((res1 1.0))
(set! res1 (- res1 (grsp-fitin-0-1 p_n1)))
res1))
;;;; grsp-pand - Calculates the probability of p_n1 and p_n2, being
;; independent.
;;
;; Keywords:
;;
;; - statistics, probability, variables, independece
;;
;; Parameters:
;;
;; - p_n1: real repesenting a probability in [0,1].
;; - p_n2: real repesenting a probability in [0,1].
;;
;; Output:
;;
;; - Numeric.
;;
;; Sources:
;;
;; - [1].
;;
(define (grsp-pand p_n1 p_n2)
(let ((res1 1.0))
(set! res1 (* (grsp-fitin-0-1 p_n1)
(grsp-fitin-0-1 p_n2)))
res1))
;;;; grsp-pnand - Calculates the probability of p_n1 and p_n2 happening,
;; being p_n1 and p_n2 not independent.
;;
;; Keywords:
;;
;; - statistics, probability, variables, dependence
;;
;; Parameters:
;;
;; - p_n1: real repesenting a probability in [0,1].
;; - p_n2: real repesenting a probability in [0,1].
;;
;; Output:
;;
;; - Numeric.
;;
;; Sources:
;;
;; - [1].
;;
(define (grsp-pnand p_n1 p_n2)
(let ((res1 1.0)
(n1 0.0)
(n2 0.0))
(set! n1 (grsp-fitin-0-1 p_n1))
(set! n2 (grsp-fitin-0-1 p_n2))
(set! res1 (* (grsp-pand n1 n2) n2))
res1))
;;;; grsp-por - Calculates the probability of p_n1 or p_n2.
;;
;; Keywords:
;;
;; - statistics, probability, variables
;;
;; Parameters:
;;
;; - p_n1: real repesenting a probability in [0,1].
;; - p_n2: real repesenting a probability in [0,1].
;;
;; Output:
;;
;; - Numeric.
;;
;; Sources:
;;
;; - [1].
;;
(define (grsp-por p_n1 p_n2)
(let ((res1 1.0)
(n1 0.0)
(n2 0.0))
(set! n1 (grsp-fitin-0-1 p_n1))
(set! n2 (grsp-fitin-0-1 p_n2))
(set! res1 (- (+ n1 n2) (grsp-pand n1 n2)))
res1))
;;;; grsp-pxor - Calculates the probability of p_n1 or p_n2 happening,
;; beign p_n1 and p_n2 mutually exclusive.
;;
;; Keywords:
;;
;; - statistics, probability, variables, exclusion
;;
;; Parameters:
;;
;; - p_n1: real repesenting a probability in [0,1].
;; - p_n2: real repesenting a probability in [0,1].
;;
;; Output:
;;
;; - Numeric.
;;
;; Sources:
;;
;; - [1].
;;
(define (grsp-pxor p_n1 p_n2)
(let ((res1 0.0)
(n1 0.0)
(n2 0.0))
(set! n1 (grsp-fitin-0-1 p_n1))
(set! n2 (grsp-fitin-0-1 p_n2))
(cond ((<= (+ n1 n2) 1)
(set! res1 (+ n1 n2))))
res1))
;;;; grsp-pcond - Calculates the probability of p_n1 given p_n2.
;;
;; Keywords:
;;
;; - statistics, probability, variables, causality
;;
;; Parameters:
;;
;; - p_n1: real repesenting a probability in [0,1].
;; - p_n2: real repesenting a probability in [0,1].
;;
;; Output:
;;
;; - Numeric.
;;
;; Sources:
;;
;; - [1][2].
;;
(define (grsp-pcond p_n1 p_n2)
(let ((res1 0.0)
(n1 p_n1)
(n2 p_n2))
(set! n1 (grsp-fitin-0-1 p_n1))
(set! n2 (grsp-fitin-0-1 p_n2))
(cond ((> n2 0.0)
(set! res1 (/ (grsp-pand n1 n2) n2))))
res1))
;;;; grsp-pcomp - Given that (expt (abs p_n1) 2) + (expt (abs n2) 2) =
;; 1, and given p_n1 as a parameter, returns (abs n2).
;;
;; Keywords:
;;
;; - statistics, probability, absolute
;;
;; Parameters:
;;
;; - p_n1: real representing a probability in [0,1]
;;
;; Output:
;;
;; - Numeric.
;;
;; Sources:
;;
;; - [1].
;;
(define (grsp-pcomp p_n1)
(let ((res1 0.0))
(set! res1 (sqrt (- 1 (expt (abs p_n1) 2))))
res1))
;;;; grsp-osbv - Calculates expt operation p_s1 between p_n1 and p_n2
;; according to exponent p_e1. Can be used to calculate - for example -
;; the squared difference between two numbers.
;;
;; Keywords:
;;
;; - statistics, probability, exponential
;;
;; Parameters:
;;
;; - p_s1: operation.
;;
;; - "#+": addition.
;; - "#-": substraction.
;; - "#*": multiplication.
;; - "#/": division.
;;
;; - p_e1: exponent (power).
;; - p_n1: real number.
;; - p_n2: real number.
;;
;; Output:
;;
;; - Numeric.
;;
;; Sources:
;;
;; - [1].
;;
(define (grsp-osbv p_s1 p_e1 p_n1 p_n2)
(let ((res1 0.0))
(cond ((equal? p_s1 "#-")
(set! res1 (expt (- p_n1 p_n2) p_e1)))
((equal? p_s1 "#*")
(set! res1 (expt (* p_n1 p_n2) p_e1)))
((equal? p_s1 "#/")
(set! res1 (expt (/ p_n1 p_n2) p_e1)))
(else (set! res1 (expt (+ p_n1 p_n2) p_e1))))
res1))
;;;; grsp-obsv - Calculates expt operation to p_e1 power for p_n1 and p_n2
;; and then perfoms operation p_s1 between those values.
;;
;; Keywords:
;;
;; - statistics, probability, exponential
;;
;; Parameters:
;;
;; - p_s1: operation.
;;
;; - "#+": addition.
;; - "#-": substraction.
;; - "#*": multiplication.
;; - "#/": division.
;;
;; - p_n1: real number.
;; - p_n2: real number.
;;
;; Output:
;;
;; - Numeric.
;;
;; Sources:
;;
;; - [1].
;;
(define (grsp-obsv p_s1 p_e1 p_n1 p_n2)
(let ((res1 0.0)
(n1 (expt p_n1 p_e1))
(n2 (expt p_n2 p_e1)))
(cond ((equal? p_s1 "#-")
(set! res1 (- p_n1 p_n2)))
((equal? p_s1 "#*")
(set! res1 (* p_n1 p_n2)))
((equal? p_s1 "#/")
(set! res1 (/ p_n1 p_n2)))
(else (set! res1 (+ p_n1 p_n2))))
res1))
;;;; grsp-entropy-dvar - Calculates the entropy of a discrete random
;; variable in an m x n matix.
;;
;; Keywords:
;;
;; - statistics, probability, entropic
;;
;; Parameters:
;;
;; - p_g1: logarithm base.
;;
;; - 2: base 2.
;; - 2.71: natural base.
;; - 10: base 10.
;;
;; - p_a1: matrix of outcomes x(1)...(x(nxm) of drv X.
;;
;; Output:
;;
;; - m x n matrix, with entropy values expressed in:
;;
;; - Bits, if p_g1 = 2.
;; - Nats, if p_g1 = 2.71.
;; - Dits, if p_g1 = 10.
;;
;; Sources:
;;
;; - [8].
;;
(define (grsp-entropy-dvar p_g1 p_a1)
(let ((res1 0)
(g2 "#xlognx"))
(cond ((equal? p_g1 10)
(set! g2 "#xlog10x"))
((equal? p_g1 2)
(set! g2 "#xlog2x")))
(set! res1 (grsp-matrix-opio "#+" (grsp-matrix-opfn g2 p_a1) 0))
res1))
;;;; grsp-mean1 - Expected value of a random variable X.
;;
;; Keywords:
;;
;; - statistics, probability, randomness, aleatory
;;
;; Parameters:
;;
;; - p_a1: sample (matrix).
;;
;; Notes:
;;
;; - See grsp-mean1.
;;
;; Output:
;;
;; - Numeric.
;;
;; Sources:
;;
;; - [35].
;;
(define (grsp-mean1 p_a1)
(let ((res1 0))
(set! res1 (grsp-opz (/ (grsp-matrix-opio "#+" p_a1 0)
(grsp-matrix-total-elements p_a1))))
res1))
;;;; grsp-mean1-mth - Mutithreaded version of grsp-mean1.
;;
;; Keywords:
;;
;; - statistics, probability, mean, average, averaging
;;
;; Parameters:
;;
;; - p_a1: sample (matrix).
;;
;; Output:
;;
;; - Numeric.
;;
;; Sources:
;;
;; - [35].
;;
(define (grsp-mean1-mth p_a1)
(letpar ((res1 0.0)
(n1 (grsp-matrix-opio "#+" p_a1 0))
(d1 (grsp-matrix-total-elements p_a1)))
(set! res1 (/ n1 d1))
res1))
;;;; grsp-mean2 - Expected value of a non-negative, random variable X
;; and the probability P for each outcome of X.
;;
;; Keywords:
;;
;; - statistics, probability, randomness, aleatory
;;
;; Parameters:
;;
;; - p_a1: matrix, instances of X.
;; - p_a2: matrix, probabilities corresponding to each instance of X in
;; p_a1.
;;
;; Notes:
;;
;; - p_a1 and p_a2 should be of the same shape and dimensions.
;;
;; Output:
;;
;; - Numeric.
;;
;; Sources:
;;
;; - [13][35].
;;
(define (grsp-mean2 p_a1 p_a2)
(let ((res1 0)
(res2 0))
;; Multiply each instance of x by its probability.
(set! res2 (grsp-matrix-opew "#*" p_a1 p_a2))
;; Compose results.
(set! res1 (grsp-matrix-opio "#+" res2 0))
res1))
;;;; grsp-mean3 - Expected value of elements of list p_l1.
;;
;; Keywords:
;;
;; - statistics, probability, randomness, aleatory
;;
;; Parameters:
;;
;; - p_l1: sample (ist).
;;
;; Notes:
;;
;; - See grsp-mean1.
;;
;; Output:
;;
;; - Numeric.
;;
;; Sources:
;;
;; - [35].
;;
(define (grsp-mean3 p_l1)
(let ((res1 0))
(set! res1 (grsp-opz (/ (grsp-lal-opio "#+" p_l1) (length p_l1))))
res1))
;;;; grsp-mean-geometric - Geometric mean of elements of p_a1.
;;
;; Keywords:
;;
;; - statistics, probability, mean, average
;;
;; Parameters:
;;
;; - p_a1: sample (matrix).
;;
;; Output:
;;
;; - Numeric.
;;
;; Sources:
;;
;; - [35].
;;
(define (grsp-mean-geometric p_a1)
(let ((res1 0)
(n1 0)
(n2 0))
(set! res1 (expt (grsp-matrix-opio "#*" p_a1 0)
(/ 1 (grsp-matrix-total-elements p_a1))))
res1))
;;;; grsp-mean-geometric-mth - Multithreaded verson of grsp-mean-geometric.
;;
;; Keywords:
;;
;; - statistics, probability, mean, average
;;
;; Parameters:
;;
;; - p_a1: sample (matrix).
;;
;; Output:
;;
;; - Numeric.
;;
;; Sources:
;;
;; - [35].
;;
(define (grsp-mean-geometric-mth p_a1)
(letpar ((res1 0.0)
(n1 (grsp-matrix-opio "#*" p_a1 0))
(d1 (/ 1 (grsp-matrix-total-elements p_a1))))
(set! res1 (expt n1 d1))
res1))
;;;; grsp-mean-interquartile - Interquartile mean of elements of p_a1.
;;
;; Keywords:
;;
;; - statistics, probability, mean, average
;;
;; Parameters:
;;
;; - p_a1: sample (matrix).
;;
;; Output:
;;
;; - Numeric.
;;
;; Sources:
;;
;; - [33][35].
;;
(define (grsp-mean-interquartile p_a1)
(let ((res1 0)
(res2 0)
(res3 0))
;; Safe copy.
(set! res3 (grsp-matrix-cpy p_a1))
;; Find quartiles.
(set! res2 (grsp-5ns res3))
;; Trim sample to interquartile range.
(set! res3 (grsp-matrix-trim "#<" res3 (array-ref res2 0 1)))
(set! res3 (grsp-matrix-trim "#>" res3 (array-ref res2 0 3)))
;; Compose results.
(set! res1 (grsp-mean1 res3))
res1))
;;;; grsp-mean-quadratic - Quadratic mean of elements of p_a1. Requires
;; that all elements of p_a1 should be >= 0.
;;
;; Keywords:
;;
;; - statistics, probability, mean, average
;;
;; Parameters:
;;
;; - p_a1: sample (matrix).
;;
;; Output: