Le lundi 11 septembre 2023 à 16:36:18 UTC, Ahmed MELAHI a écrit :
Le mercredi 2 janvier 2019 à 11:15:48 UTC, [email protected] a écrit :
Am Mittwoch, 2. Januar 2019 12:11:10 UTC+1 schrieb [email protected]:
Am Mittwoch, 2. Januar 2019 11:52:30 UTC+1 schrieb Manuel Rodriguez:
Fuzzy control is a grammar driven control technique which allows
to realized sophisticated control systems. In the literature the standard example of a ball on a plate is often mentioned. The idea is to define some linguistic variables for example acceleration, position,
distance-to-trajectory and some rules like moveleft, moveup and stop. Then
a control program is created which is realizing the fuzzy set in reality.
Without any doubt the best programming language for implementing fuzzy control is Forth. It allows to define the fuzzy rules as words and thanks it's interactivity capability it's great for interactive testing
the system. My question is: Are sourcecode examples available in which Forth was used for fuzzy control?
With due respect: this seems a Forth-centric tunnel view.
In reality you need sensors, actuators and a controller eg PLC. Their toolstack
determines what you have in hand. And it is to 99.999% not in Forth.
When you're lucky you can develop and simulate using a fuzzy control toolbox. Eg.
https://www.mathworks.com/products/fuzzy-logic.html
p.s. I forgot:
see page 6ff in
http://www.forth.org/fd/FD-V18N6.pdf
Hi,
Here is a little program that permits to create fuzzy systems.
Save this program as fuzzy.fs and include it in the file where a fuzzy system will be created.
\ Here begins the code
\ Mamdani type fuzzy system with normalized output (in [-1, 1])
vocabulary fuzzy fuzzy definitions
' is alias as
defer tnorm
defer tconorm
defer rules
: and tnorm ;
: or tconorm ;
: if 1e ;
: is f@ ;
: then tnorm ;
: )r tnorm ;
: r( ;
: rt( 0e ;
: )rt or ;
fvariable output
100 value N/2 N/2 negate value -N/2
: s_z*f 0e -N/2 N/2 do i s>f 1e-1 f* output f! rules output f@ f* f+ -1 +loop ;
: s_f 0e -N/2 N/2 do i s>f 1e-1 f* output f! rules f+ -1 +loop ;
: (fuzzy_system) s_z*f s_f f/ ;
\ Here the code finishes.
Hi again,
Here is an example of creating a fuzzy system with 2 inputs and 1 output.
\ here the code begins
s" fuzzy.fs" included
\ example
\ fuzzy system with: 2 inputs x and y
\ 1 output z
fvariable x
fvariable y
' output alias z
fvariable zz \ to save output
\ print x, y and zz
: .xyz cr ." X = " x f@ f. cr ." Y = " y f@ f. cr ." Z = " zz f@ f. ;
\ using prod as tnorm and probabilistic or as tconorm, we can use fmin and fmax for tnorm and tconorm respectively
: tnorm1 f* ;
: tconorm1 fover fover f* f- f+ ; \ (u,v)---> u+v-u*v
' tnorm1 as tnorm
' tconorm1 as tconorm
\ here, we use gaussian membership functions for the three fuzzy variables,
\ we can use other functions: triangular, trapezoidal, ... Just define them
\ membership degree md = mf_gauss(x;m,s) = exp(-((x-m)/s)^2)
: mf_gauss ( f: x m s -- f: md ) frot frot f- fswap f/ fdup f* fnegate fexp ;
\ for input x
: nb1 -1e 0.2e mf_gauss ;
: ze1 0e 0.2e mf_gauss ;
: pb1 1e 0.2e mf_gauss ;
\ for input y
: nb2 -1e 0.2e mf_gauss ;
: ze2 0e 0.2e mf_gauss ;
: pb2 1e 0.2e mf_gauss ;
\ for output z
: nb3 -1e 0.2e mf_gauss ;
: ze3 0e 0.2e mf_gauss ;
: pb3 1e 0.2e mf_gauss ;
\ the fuzzy rules are given as below
: rules1
rt(
r( if x is nb1 and y is nb2 then z is nb3 )r or
r( if x is nb1 and y is ze2 then z is ze3 )r or
r( if x is nb1 and y is pb2 then z is ze3 )r or
r( if x is ze1 and y is ze2 then z is ze3 )r or
r( if x is ze1 and y is nb2 then z is ze3 )r or
r( if x is ze1 and y is pb2 then z is ze3 )r or
r( if x is pb1 and y is nb2 then z is ze3 )r or
r( if x is pb1 and y is ze2 then z is ze3 )r or
r( if x is pb1 and y is pb2 then z is pb3 )r
)rt
;
' rules1 as rules
\ the fuzzy sustem
: FS (fuzzy_system) zz f! ;
\ examples of results
0e x f! 0e y f!
FS .xyz \ print x y and the result which is in zz
cr
-1e x f! -1e y f!
FS .xyz
cr
1e x f! 1e y f!
FS .xyz
cr
\ here the code finishes
the timing using gforth :
\ mean time of execution
: timing_1000 utime 1000 0 do FS loop utime d>f d>f f- 1e-3 f* 1e-3 f* cr ." mean execution time: " f. ." ms. " ;
timing_1000
gives about 0.9 ms
note that the fuzzy system is FS
Bye
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)