]> git.vouivredigital.com Git - vouivre.git/commitdiff
Cleanup
authoradmin <admin@vouivredigital.com>
Tue, 28 Nov 2023 14:00:25 +0000 (23:00 +0900)
committeradmin <admin@vouivredigital.com>
Tue, 28 Nov 2023 14:00:25 +0000 (23:00 +0900)
HACKING
examples/base.scm
examples/example.scm
vouivre/autodiff.scm

diff --git a/HACKING b/HACKING
index b7de064b72313f389ef1cb42ad2d0fd1e154b00a..8bfb27ac5dd60a5e20bae151b9e03633a64d6041 100644 (file)
--- a/HACKING
+++ b/HACKING
@@ -17,9 +17,7 @@ To build the system you will need:
 * Building
 
 #+BEGIN_SRC bash
-  autoreconf -vif
-  ./configure
-  make
+  autoreconf -vif && ./configure && make
 #+END_SRC
 
 * Testing
index 1df102240636e3ef7a4ab7e71d642effb8490044..b1c98a721d7ace41a8c4c2421c8090d616576b61 100644 (file)
 (∷ 1+ (0 . 0))
 (cudefine (1+ x) (guile:1+ x))
 
-(definec (identity x) x)
-(definec (∘ g f) (λc x (g (f x))))
-(definec (⊙ f g) (∘ g f))
-(definec (flip f) (λc y (λc x (f x y))))
-
 (∷ adot (0 . (0 . (0 . 0))))
 (cudefine (adot x y n) (v:adot x y n))
 
 
 (∷ rdiff ((0 . 0) . (0 . 0)))
 (cudefine (rdiff x) (v:rdiff x))
+
+(definec (identity x) x)
+(definec (∘ g f) (λc x (g (f x))))
+(definec (⊙ f g) (∘ g f))
+(definec (flip f) (λc y (λc x (f x y))))
index b817ca6dd64f947453a0bb2a92ed8dc260baef2f..a55b3b2306a2e0ab527d90ece238ade07b69a78a 100644 (file)
@@ -150,8 +150,8 @@ gradient (without overwriting the original parameters)."
   (display (apply (<L> x y) a))
   (newline))
 
-(define (categorize x)
-  "The category of the given sample infered by the model."
+(define (classify x)
+  "The class of the given sample infered by the model."
   (argmax (f x a)))
 
 (define (train nb-epochs steps-per-epochs)
index a6ba7842939909ebffe4cdc1af3c0d72110756f4..9dafdf9b57fba17c0232124d9df52ca494b774d1 100644 (file)
    relu
    sum)
   #:replace
-  ((i:sqrt . sqrt)
-   (i:exp . exp)
-   (i:expt . expt)
-   (i:log . log)
-   (i:sin . sin)
-   (i:cos . cos)
-   (i:tan . tan)
+  ((i:* . *)
    (i:+ . +)
    (i:- . -)
-   (i:* . *)
    (i:/ . /)
-   (i:max . max)
-   (i:min . min)
    (i:abs . abs)
-   (i:identity . identity)
+   (i:array-cell-ref . array-cell-ref)
    (i:array-ref . array-ref)
-   (i:array-cell-ref . array-cell-ref))
-  #:re-export
-  (fold
-   reduce))
+   (i:cos . cos)
+   (i:exp . exp)
+   (i:expt . expt)
+   (i:fold . fold)
+   (i:identity . identity)
+   (i:log . log)
+   (i:max . max)
+   (i:min . min)
+   (i:reduce . reduce)
+   (i:sin . sin)
+   (i:sqrt . sqrt)
+   (i:tan . tan)))
 
 ;;;; array utilities
 
@@ -238,6 +237,8 @@ adding the result to the destination buffer."
     (apply generator xs j i data)))
 
 (define* (fdiff f #:optional (axis 0))
+    "Automatic differentiation in forward accumulation mode w.r.t. the
+function argument at the given index."
   (lambda xs
     (parameterize (((@@ (vouivre autodiff) *differentiation-mode*) 'fwd)
                   ((@@ (vouivre autodiff) *promises*) (cons '() #f)))
@@ -302,6 +303,8 @@ adding the result to the destination buffer."
            a)))))))
 
 (define* (rdiff f #:optional (axis 0))
+    "Automatic differentiation in reverse accumulation mode w.r.t. the
+function argument at the given index."
   (lambda xs
     (parameterize (((@@ (vouivre autodiff) *differentiation-mode*) 'rev)
                   ((@@ (vouivre autodiff) *promises*) (cons '() #f)))
@@ -387,10 +390,23 @@ adding the result to the destination buffer."
 ;;     the head of which is as described above and the remaining elements
 ;;     are procedures of the same arguments but returning values that are
 ;;     then fed as extra data to the generators.
-;;
-;; NOTE: In cases where an argument isn't meant to be differentiable its
-;;       corresponding generator should be `#f'.
 (define (differentiable-wrapper generators proc* arg . more)
+  "Helper for defining differentiable functions.
+
+generators: A list of generating procedures that, take the given arguments
+            along with an absolute input index, an absolute output index,
+            and zero or more data points, to produce a corresponding jacobian
+            element.
+
+proc*:      A list containing the function to be differentiated and zero or
+            more procedures that also take the given arguments to create,
+            in the forward pass, the data points that are latter fed to the
+            generators.
+
+arg . more: The arguments to all these procedures.
+
+NOTE: In cases where an argument isn't meant to be differentiated against, its
+      corresponding generator should be `#f'."
   (define (precompute-data naked-args)
     (if (procedure? proc*)
        '()
@@ -513,6 +529,8 @@ adding the result to the destination buffer."
           'zero generators args)))))))
 
 (define (ewise1 f)
+  "Helper for creating the jacobian generator of one argument functions created
+with the `extend' procedure."
   (lambda (xs i j)
     (let ((x (car xs)))
       (if (number? x)
@@ -523,6 +541,8 @@ adding the result to the destination buffer."
                             j)))))))
 
 (define (ewise2 proc axis)
+  "Helper for creating the jacobian generators of two argument functions created
+with the `extend' procedure."
   (lambda (xs i j)
     (let ((x (car xs))
          (y (cadr xs)))
@@ -863,3 +883,11 @@ rank > 0."
   "Differentiable RealSoftMax using the log-sum-exp trick."
   (let ((c (maximum x)))
     (i:+ c (i:log (sum (i:exp (i:- x c)))))))
+
+(define (i:fold f init lst . more)
+  "Differentiable fold of a differentiable function."
+  (apply fold f init lst more))
+
+(define (i:reduce f default lst)
+  "Differentiable reduce of a differentiable function."
+  (reduce f default lst))