Skip to content

Commit

Permalink
Merge pull request #135 from PESchoenberg/develop
Browse files Browse the repository at this point in the history
New functions.
  • Loading branch information
PESchoenberg committed Sep 18, 2021
2 parents eca7385 + 671f545 commit 29827ab
Show file tree
Hide file tree
Showing 2 changed files with 177 additions and 9 deletions.
73 changes: 65 additions & 8 deletions grsp3.scm
Original file line number Diff line number Diff line change
Expand Up @@ -81,25 +81,27 @@
;; - [18] Mathispower4u. (2020). LU Decomposition. [online] Available at:
;; https://www.youtube.com/watch?v=UlWcofkUDDU [Accessed 5 Mar. 2020].
;; - [19] En.wikipedia.org. 2021. Genetic algorithm - Wikipedia. [online]
;; Available at: <https://en.wikipedia.org/wiki/Genetic_algorithm>
;; Available at: https://en.wikipedia.org/wiki/Genetic_algorithm
;; [Accessed 13 May 2021].
;; - [20] En.wikipedia.org. 2021. Crossover (genetic algorithm) - Wikipedia.
;; [online] Available at: <https://en.wikipedia.org/wiki/Crossover_(genetic_algorithm)>
;; [online] Available at: https://en.wikipedia.org/wiki/Crossover_(genetic_algorithm)
;; [Accessed 13 May 2021].
;; - [21] En.wikipedia.org. 2021. Mutation (genetic algorithm) - Wikipedia.
;; [online] Available at: <https://en.wikipedia.org/wiki/Mutation_(genetic_algorithm)>
;; [online] Available at: https://en.wikipedia.org/wiki/Mutation_(genetic_algorithm)
;; [Accessed 13 May 2021].
;; - [22] En.wikipedia.org. 2021. Selection (genetic algorithm) - Wikipedia.
;; [online] Available at: <https://en.wikipedia.org/wiki/Selection_(genetic_algorithm)>
;; [online] Available at: https://en.wikipedia.org/wiki/Selection_(genetic_algorithm)
;; [Accessed 13 May 2021].
;; - [23] fitness, A., 2015. Accumulated normalized fitness. [online] Stack
;; Overflow. Available at:
;; <https://stackoverflow.com/questions/27524241/accumulated-normalized-fitness>
;; https://stackoverflow.com/questions/27524241/accumulated-normalized-fitness
;; [Accessed 13 May 2021].
;; - [24] En.wikipedia.org. 2021. Multiset - Wikipedia. [online] Available at:
;; https://en.wikipedia.org/wiki/Multiset [Accessed 17 September 2021].


;; Compilation and REPL examples:
;;(use-modules (grsp grsp0)(grsp grsp1)(grsp grsp2)(grsp grsp3)(grsp grsp4)(grsp grsp5)(grsp grsp6)(grsp grsp7)(grsp grsp8)(grsp grsp9)(grsp grsp10)(grsp grsp11)(grsp grsp12)(grsp grsp13))
;; (use-modules (grsp grsp0)(grsp grsp1)(grsp grsp2)(grsp grsp3)(grsp grsp4)(grsp grsp5)(grsp grsp6)(grsp grsp7)(grsp grsp8)(grsp grsp9)(grsp grsp10)(grsp grsp11)(grsp grsp12)(grsp grsp13))
;;
;; (define X (grsp-matrix-create 1 4 4))
;; (define Y (grsp-matrix-create 2 4 4))
Expand Down Expand Up @@ -211,7 +213,8 @@
grsp-matrix-keyon
grsp-matrix-col-aupdate
grsp-matrix-row-selectc
grsp-matrix-is-empty))
grsp-matrix-is-empty
grsp-matrix-is-multiset))


;;;; grsp-matrix-esi - Extracts shape information from an m x n matrix.
Expand Down Expand Up @@ -5389,7 +5392,7 @@
res1))


;;;; grsp-matrix-fitness-rprnd - Basic fitness function based on pseudo - random
;;;; grsp-matrix-fitness-rprnd - Basic fitness function based on pseudo - random
;; numbers.
;;
;; Keywords:
Expand Down Expand Up @@ -5656,3 +5659,57 @@

res1))


;;;; grsp-matrix-is-multiset - Returns #t if the matrix has reteated elements, #f
;; otherwise.
;;
;; Keywords:
;; - function, algebra, matrix, matrices, vectors.
;;
;; Arguments:
;; - p_a1: matrix.
;;
;; Sources:
;; - [24].
;;
(define (grsp-matrix-is-multiset p_a1)
(let ((res1 0)
(res2 #f)
(lm1 0)
(hm1 0)
(ln1 0)
(hn1 0)
(i1 0)
(j1 0)
(n1 0)
(n2 0)
(b1 #f))

;; Create safety matrices.
(set! res1 (grsp-matrix-cpy p_a1))

;; Extract boundaries.
(set! lm1 (grsp-matrix-esi 1 res1))
(set! hm1 (grsp-matrix-esi 2 res1))
(set! ln1 (grsp-matrix-esi 3 res1))
(set! hn1 (grsp-matrix-esi 4 res1))

;; Cycle the matrix and find the first (set) element that has
;; multiplicity.
(set! i1 lm1)
(while (<= i1 hm1)
(set! j1 ln1)
(while (<= j1 hn1)
(set! n2 (array-ref res1 i1 j1))
(set! n1 (grsp-matrix-total-element res1 n2))
(cond ((> n1 1)
(set! b1 #t)
(set! i1 hm1)
(set! j1 hn1)))
(set! j1 (in j1)))
(set! i1 (in i1)))

;; Cmpose result.
(set! res2 b1)

res2))
113 changes: 112 additions & 1 deletion grsp5.scm
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,9 @@
grsp-triangular-variance
grsp-triangular-median
grsp-triangular-pdf
grsp-triangular-entropy))
grsp-triangular-entropy
grsp-triangular-cdf
grsp-triangular-skewness))


;;;; grsp-feature-scaling - Scales p_n to the interval [p_nmin, p_nmax].
Expand Down Expand Up @@ -3046,6 +3048,9 @@

(set! res1 (/ -3 5))

;; Compose result.
(set! res1 (grsp-opz res1))

res1))


Expand All @@ -3067,6 +3072,9 @@

(set! res1 (/ (+ p_a1 p_b1 p_c1) 3))

;; Compose result.
(set! res1 (grsp-opz res1))

res1))


Expand Down Expand Up @@ -3105,6 +3113,7 @@

;; Compose result.
(set! res1 (/ res2 18))
(set! res1 (grsp-opz res1))

res1))

Expand Down Expand Up @@ -3144,6 +3153,9 @@
(else
(set! res1 (- b1 (sqrt (/ (* d1 (- b1 c1)) 2))))))

;; Compose result.
(set! res1 (grsp-opz res1))

res1))


Expand Down Expand Up @@ -3185,6 +3197,9 @@
(set! res1 (/ 2 d1)))
((and (< c1 x1) (<= x1 b1))
(set! res1 (/ (* 2 (- b1 x1)) (* d1 (- b1 c1))))))

;; Compose result.
(set! res1 (grsp-opz res1))

res1))

Expand Down Expand Up @@ -3213,5 +3228,101 @@
(set! b1 p_b1)
(set! res1 (* 0.5 (log (/ (- b1 a1) 2))))

;; Compose result.
(set! res1 (grsp-opz res1))

res1))


;;;; grsp-triangular-cdf - Cumulative distribution function of a triangular
;; distribution.
;;
;; Keywords:
;; - statistics, probability.
;;
;; Arguments:
;; - p_a1: a.
;; - p_b1: b.
;; - p_c1: c.
;; - p_x1; x.
;;
;; Notes:
;; - See grsp-triangular-mean for argument properties.
;;
;; Sources:
;; - [42].
;;
(define (grsp-triangular-cdf p_a1 p_b1 p_c1 p_x1)
(let ((res1 0)
(a1 0)
(b1 0)
(c1 0)
(d1 0)
(x1 0))

(set! a1 p_a1)
(set! b1 p_b1)
(set! c1 p_c1)
(set! x1 p_x1)
(set! d1 (- b1 a1))

(cond ((and (<= x1 c1) (< a1 x1))
(set! res1 (/ (expt (- x1 a1) 2) (* d1 (- c1 a1)))))
((and (< x1 b1) (< c1 x1))
(set! res1 (- 1 (/ (expt (- b1 x1) 2) (* d1 (- b1 c1))))))
((<= b1 x1)
(set! res1 1)))

;; Compose result.
(set! res1 (grsp-opz res1))

res1))


;;;; grsp-triangular-skewness - Skewness of a triangular distribution.
;;
;; Keywords:
;; - statistics, probability.
;;
;; Arguments:
;; - p_a1: a.
;; - p_b1: b.
;; - p_c1: c.
;;
;; Notes:
;; - See grsp-triangular-mean for argument properties.
;;
;; Sources:
;; - [42].
;;
(define (grsp-triangular-skewness p_a1 p_b1 p_c1)
(let ((res1 0)
(a1 0)
(b1 0)
(c1 0)
(res2 0)
(res3 0))

(set! a1 p_a1)
(set! b1 p_b1)
(set! c1 p_c1)

(set! res2 (* (sqrt 2)
(+ a1 b1 (* -2 c1))
(- (* 2 a1) b1 c1)
(+ a1 (* -2 b1) c1)))

(set! res3 (* 5 (expt (+ (expt a1 2)
(expt b1 2)
(expt c1 2)
(* a1 b1)
(* a1 c1)
(* b1 c1))
(/ 3 2))))

(set! res1 (/ res2 res3))

;; Compose result.
(set! res1 (grsp-opz res1))

res1))

0 comments on commit 29827ab

Please sign in to comment.