Re: Differentiable Forth

Liste des GroupesRevenir à cl forth 
Sujet : Re: Differentiable Forth
De : melahi_ahmed (at) *nospam* yahoo.fr (ahmed)
Groupes : comp.lang.forth
Date : 19. Jul 2024, 10:39:22
Autres entêtes
Organisation : novaBBS
Message-ID : <cf3e51477813a438fe9f5f632a0ce90f@www.novabbs.com>
References : 1 2 3 4 5 6 7
User-Agent : Rocksolid Light
And some other examples for gradient calculation ( 2 variables), with
different implementations (fstack juggling, using fvalues, using
floating point arrays (2 variants))
The code begins here:
cr .( gradient)
: gradient ( f: x y -- df/dx df/dy)
     ' func !
     fover fover ( f: x y x y)
     fswap f>dl_d ( f: x y y x 1)
     frot  f>dl   ( f: x y x 1 y 0)
     func @ execute fnip ( f: x y df/dx)
     frot frot ( f: df/dx x y)
     fswap f>dl ( f: df/dx y x 0)
     frot f>dl_d ( f: df/dx x 0 y 1)
     func @ execute fnip ( f: df/dx df/dy)
;
cr 2e 3e gradient dl_f10() fswap cr f. cr f.
cr cr
cr .( gradient using values)
0e fvalue x
0e fvalue y
: grad ( f: x y -- df/dx df/dy)
    ' dup
    to y to x
    x f>dl_d y f>dl   execute fnip
    x f>dl   y f>dl_d execute fnip
;
(  defined)
cr 2e 3e grad dl_f10() fswap cr f. cr f.
cr cr
cr .( gradient using arrays)
create xy 2 floats allot
xy 2 floats erase
: grad1 ( f: x y -- df/dx df/dy)
    ' dup
    xy float+ f!
    xy f!
    xy f@ f>dl_d xy float+ f@ f>dl   execute fnip
    xy f@ f>dl   xy float+ f@ f>dl_d execute fnip
;
(  defined)
cr 2e 3e grad1 dl_f10() fswap cr f. cr f.
cr cr
cr .( gradient using arrays)
create xy2 2 floats allot
xy2 2 floats erase
: to_xy2  xy2 float+ f! xy2 f! ;
: df/dx xy2 f@ f>dl_d xy2 float+ f@ f>dl   execute fnip ;
: df/dy xy2 f@ f>dl   xy2 float+ f@ f>dl_d execute fnip ;
: grad2 ( f: x y -- df/dx df/dy)
    ' dup
    to_xy2
    df/dx
    df/dy
;
(  defined)
cr 2e 3e grad2 dl_f10() fswap cr f. cr f.
cr cr
cr cr cr
The code ends here
This code is the continuity of the previous code in my last post.
Ahmed

Date Sujet#  Auteur
16 Jul 24 * Differentiable Forth38mhx
16 Jul 24 `* Re: Differentiable Forth37Richard
16 Jul 24  `* Re: Differentiable Forth36mhx
16 Jul 24   +* Re: Differentiable Forth7Richard
17 Jul 24   i`* Re: Differentiable Forth6mhx
17 Jul 24   i +* Re: Differentiable Forth4Paul Rubin
17 Jul 24   i i`* Re: Differentiable Forth3minforth
17 Jul 24   i i `* Re: Differentiable Forth2mhx
17 Jul 24   i i  `- Re: Differentiable Forth1minforth
17 Jul 24   i `- Re: Differentiable Forth1Richard
17 Jul 24   `* Re: Differentiable Forth28ahmed
17 Jul 24    `* Re: Differentiable Forth27ahmed
17 Jul 24     `* Re: Differentiable Forth26ahmed
17 Jul 24      +* Re: Differentiable Forth3mhx
17 Jul 24      i`* Re: Differentiable Forth2ahmed
17 Jul 24      i `- Re: Differentiable Forth1minforth
18 Jul 24      +* Re: Differentiable Forth3ahmed
18 Jul 24      i`* Re: Differentiable Forth2Paul Rubin
19 Jul 24      i `- Re: Differentiable Forth1minforth
19 Jul 24      `* Re: Differentiable Forth19ahmed
19 Jul 24       `* Re: Differentiable Forth18ahmed
19 Jul 24        `* Re: Differentiable Forth17minforth
19 Jul 24         `* Re: Differentiable Forth16ahmed
20 Jul 24          +* Re: Differentiable Forth9minforth
20 Jul 24          i`* Re: Differentiable Forth8mhx
20 Jul 24          i +- Re: Differentiable Forth1minforth
20 Jul 24          i `* Re: Differentiable Forth6Paul Rubin
20 Jul 24          i  `* Re: Differentiable Forth5mhx
21 Jul 24          i   +- Re: Differentiable Forth1dxf
21 Jul 24          i   +* Re: Differentiable Forth2albert
21 Jul 24          i   i`- Re: Differentiable Forth1mhx
22 Jul 24          i   `- Re: Differentiable Forth1minforth
22 Jul 24          `* Re: Differentiable Forth6ahmed
24 Jul 24           `* Re: Differentiable Forth5minforth
25 Jul 24            `* Re: Differentiable Forth4ahmed
25 Jul 24             `* Re: Differentiable Forth3ahmed
26 Jul 24              `* Re: Differentiable Forth2ahmed
26 Jul 24               `- Re: Differentiable Forth1ahmed

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal