Rocksolid Light

Welcome to Rocksolid Light

mail  files  register  newsreader  groups  login

Message-ID:  

The bogosity meter just pegged.


devel / comp.lang.forth / Re: Forth sourcecode for fuzzy control of ball balancing?

SubjectAuthor
* Re: Forth sourcecode for fuzzy control of ball balancing?Ahmed MELAHI
`* Re: Forth sourcecode for fuzzy control of ball balancing?Ahmed MELAHI
 `* Re: Forth sourcecode for fuzzy control of ball balancing?Marcel Hendrix
  `* Re: Forth sourcecode for fuzzy control of ball balancing?Marcel Hendrix
   `- Re: Forth sourcecode for fuzzy control of ball balancing?Ahmed MELAHI

1
Re: Forth sourcecode for fuzzy control of ball balancing?

<45fc922d-89ff-408b-b267-d215689c6ef8n@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=24585&group=comp.lang.forth#24585

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:6214:50e:b0:655:d3ad:7d15 with SMTP id px14-20020a056214050e00b00655d3ad7d15mr181244qvb.2.1694450176065;
Mon, 11 Sep 2023 09:36:16 -0700 (PDT)
X-Received: by 2002:a17:903:5cf:b0:1c3:b3e0:c50b with SMTP id
kf15-20020a17090305cf00b001c3b3e0c50bmr1132748plb.12.1694450175718; Mon, 11
Sep 2023 09:36:15 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Mon, 11 Sep 2023 09:36:15 -0700 (PDT)
In-Reply-To: <dd70b9b5-005e-4bc3-83bc-42d2b9938f5c@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=154.121.92.131; posting-account=KJSw4AoAAACRkUCek5r_78mFj6sHzH4C
NNTP-Posting-Host: 154.121.92.131
References: <d1ad4013-a903-4cf7-b222-7ecb35f3ebac@googlegroups.com>
<45b07624-7a20-4df0-9b6e-3a34e1b04320@googlegroups.com> <dd70b9b5-005e-4bc3-83bc-42d2b9938f5c@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <45fc922d-89ff-408b-b267-d215689c6ef8n@googlegroups.com>
Subject: Re: Forth sourcecode for fuzzy control of ball balancing?
From: ahmed.melahi@univ-bejaia.dz (Ahmed MELAHI)
Injection-Date: Mon, 11 Sep 2023 16:36:16 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 3718
 by: Ahmed MELAHI - Mon, 11 Sep 2023 16:36 UTC

Le mercredi 2 janvier 2019 à 11:15:48 UTC, minf...@arcor.de a écrit :
> Am Mittwoch, 2. Januar 2019 12:11:10 UTC+1 schrieb minf...@arcor.de:
> > 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.

Re: Forth sourcecode for fuzzy control of ball balancing?

<eb0ea5cf-c23a-4d8c-8fa0-144d04e23a73n@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=24586&group=comp.lang.forth#24586

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:622a:199b:b0:40f:df11:8c07 with SMTP id u27-20020a05622a199b00b0040fdf118c07mr229021qtc.1.1694450439916;
Mon, 11 Sep 2023 09:40:39 -0700 (PDT)
X-Received: by 2002:a17:902:d2cc:b0:1bc:5e50:9347 with SMTP id
n12-20020a170902d2cc00b001bc5e509347mr3648872plc.1.1694450439577; Mon, 11 Sep
2023 09:40:39 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Mon, 11 Sep 2023 09:40:38 -0700 (PDT)
In-Reply-To: <45fc922d-89ff-408b-b267-d215689c6ef8n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=154.121.92.131; posting-account=KJSw4AoAAACRkUCek5r_78mFj6sHzH4C
NNTP-Posting-Host: 154.121.92.131
References: <d1ad4013-a903-4cf7-b222-7ecb35f3ebac@googlegroups.com>
<45b07624-7a20-4df0-9b6e-3a34e1b04320@googlegroups.com> <dd70b9b5-005e-4bc3-83bc-42d2b9938f5c@googlegroups.com>
<45fc922d-89ff-408b-b267-d215689c6ef8n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <eb0ea5cf-c23a-4d8c-8fa0-144d04e23a73n@googlegroups.com>
Subject: Re: Forth sourcecode for fuzzy control of ball balancing?
From: ahmed.melahi@univ-bejaia.dz (Ahmed MELAHI)
Injection-Date: Mon, 11 Sep 2023 16:40:39 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 6338
 by: Ahmed MELAHI - Mon, 11 Sep 2023 16:40 UTC

Le lundi 11 septembre 2023 à 16:36:18 UTC, Ahmed MELAHI a écrit :
> Le mercredi 2 janvier 2019 à 11:15:48 UTC, minf...@arcor.de a écrit :
> > Am Mittwoch, 2. Januar 2019 12:11:10 UTC+1 schrieb minf...@arcor.de:
> > > 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

Re: Forth sourcecode for fuzzy control of ball balancing?

<204b9699-37cc-4765-9707-1155374cc84en@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=24587&group=comp.lang.forth#24587

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:6214:a8d:b0:655:afc1:e95e with SMTP id ev13-20020a0562140a8d00b00655afc1e95emr210610qvb.12.1694456024130;
Mon, 11 Sep 2023 11:13:44 -0700 (PDT)
X-Received: by 2002:a05:620a:6911:b0:76d:e9c0:9109 with SMTP id
tz17-20020a05620a691100b0076de9c09109mr176502qkn.7.1694456023971; Mon, 11 Sep
2023 11:13:43 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Mon, 11 Sep 2023 11:13:41 -0700 (PDT)
In-Reply-To: <eb0ea5cf-c23a-4d8c-8fa0-144d04e23a73n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2001:1c05:2f18:6d00:e053:7395:384e:8685;
posting-account=-JQ2RQoAAAB6B5tcBTSdvOqrD1HpT_Rk
NNTP-Posting-Host: 2001:1c05:2f18:6d00:e053:7395:384e:8685
References: <d1ad4013-a903-4cf7-b222-7ecb35f3ebac@googlegroups.com>
<45b07624-7a20-4df0-9b6e-3a34e1b04320@googlegroups.com> <dd70b9b5-005e-4bc3-83bc-42d2b9938f5c@googlegroups.com>
<45fc922d-89ff-408b-b267-d215689c6ef8n@googlegroups.com> <eb0ea5cf-c23a-4d8c-8fa0-144d04e23a73n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <204b9699-37cc-4765-9707-1155374cc84en@googlegroups.com>
Subject: Re: Forth sourcecode for fuzzy control of ball balancing?
From: mhx@iae.nl (Marcel Hendrix)
Injection-Date: Mon, 11 Sep 2023 18:13:44 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2089
 by: Marcel Hendrix - Mon, 11 Sep 2023 18:13 UTC

On Monday, September 11, 2023 at 6:40:41 PM UTC+2, Ahmed MELAHI wrote:
[..]
> timing_1000
>
> gives about 0.9 ms
> note that the fuzzy system is FS

It takes 0.63ms in iForth, that is a bit unexpected...
I wonder what makes it so slow (or so fast for gForth)?

I can understand that you want to give the words the exact
names that you feel are right, but an overloaded IS, AND, OR,
IF, THEN, output ( not used, see zz ), and then tnorm1 and
tcnorm1 instead of and1 and or1 so that you could write
"r( if x is nb1 and y is nb2 then z is nb3 )r", was a bit *too*
cute for me :--)

-marcel

Re: Forth sourcecode for fuzzy control of ball balancing?

<8f4c994f-d47d-4ea7-bbf5-9a3016f3c6d9n@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=24588&group=comp.lang.forth#24588

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:620a:438b:b0:76e:f686:cac6 with SMTP id a11-20020a05620a438b00b0076ef686cac6mr188699qkp.8.1694456419646;
Mon, 11 Sep 2023 11:20:19 -0700 (PDT)
X-Received: by 2002:a05:6a00:1a0c:b0:68b:de2e:74f9 with SMTP id
g12-20020a056a001a0c00b0068bde2e74f9mr4365917pfv.1.1694456419124; Mon, 11 Sep
2023 11:20:19 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Mon, 11 Sep 2023 11:20:18 -0700 (PDT)
In-Reply-To: <204b9699-37cc-4765-9707-1155374cc84en@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2001:1c05:2f18:6d00:e053:7395:384e:8685;
posting-account=-JQ2RQoAAAB6B5tcBTSdvOqrD1HpT_Rk
NNTP-Posting-Host: 2001:1c05:2f18:6d00:e053:7395:384e:8685
References: <d1ad4013-a903-4cf7-b222-7ecb35f3ebac@googlegroups.com>
<45b07624-7a20-4df0-9b6e-3a34e1b04320@googlegroups.com> <dd70b9b5-005e-4bc3-83bc-42d2b9938f5c@googlegroups.com>
<45fc922d-89ff-408b-b267-d215689c6ef8n@googlegroups.com> <eb0ea5cf-c23a-4d8c-8fa0-144d04e23a73n@googlegroups.com>
<204b9699-37cc-4765-9707-1155374cc84en@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <8f4c994f-d47d-4ea7-bbf5-9a3016f3c6d9n@googlegroups.com>
Subject: Re: Forth sourcecode for fuzzy control of ball balancing?
From: mhx@iae.nl (Marcel Hendrix)
Injection-Date: Mon, 11 Sep 2023 18:20:19 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: Marcel Hendrix - Mon, 11 Sep 2023 18:20 UTC

On Monday, September 11, 2023 at 8:13:45 PM UTC+2, Marcel Hendrix wrote:
> On Monday, September 11, 2023 at 6:40:41 PM UTC+2, Ahmed MELAHI wrote:
> [..]

Sorry, I should have started by saying that this is a very interesting piece
of work.

-marcel

Re: Forth sourcecode for fuzzy control of ball balancing?

<46beba7c-2a0c-402f-a87c-5acc9316b958n@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=24589&group=comp.lang.forth#24589

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:620a:1aaa:b0:76f:39c:d0a9 with SMTP id bl42-20020a05620a1aaa00b0076f039cd0a9mr270566qkb.5.1694457775905;
Mon, 11 Sep 2023 11:42:55 -0700 (PDT)
X-Received: by 2002:a17:902:ce85:b0:1c0:760b:b5c3 with SMTP id
f5-20020a170902ce8500b001c0760bb5c3mr4381310plg.13.1694457775684; Mon, 11 Sep
2023 11:42:55 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!feeder1.feed.usenet.farm!feed.usenet.farm!peer02.ams4!peer.am4.highwinds-media.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Mon, 11 Sep 2023 11:42:55 -0700 (PDT)
In-Reply-To: <8f4c994f-d47d-4ea7-bbf5-9a3016f3c6d9n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=154.121.92.131; posting-account=KJSw4AoAAACRkUCek5r_78mFj6sHzH4C
NNTP-Posting-Host: 154.121.92.131
References: <d1ad4013-a903-4cf7-b222-7ecb35f3ebac@googlegroups.com>
<45b07624-7a20-4df0-9b6e-3a34e1b04320@googlegroups.com> <dd70b9b5-005e-4bc3-83bc-42d2b9938f5c@googlegroups.com>
<45fc922d-89ff-408b-b267-d215689c6ef8n@googlegroups.com> <eb0ea5cf-c23a-4d8c-8fa0-144d04e23a73n@googlegroups.com>
<204b9699-37cc-4765-9707-1155374cc84en@googlegroups.com> <8f4c994f-d47d-4ea7-bbf5-9a3016f3c6d9n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <46beba7c-2a0c-402f-a87c-5acc9316b958n@googlegroups.com>
Subject: Re: Forth sourcecode for fuzzy control of ball balancing?
From: ahmed.melahi@univ-bejaia.dz (Ahmed MELAHI)
Injection-Date: Mon, 11 Sep 2023 18:42:55 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2758
 by: Ahmed MELAHI - Mon, 11 Sep 2023 18:42 UTC

Le lundi 11 septembre 2023 à 18:20:21 UTC, Marcel Hendrix a écrit :
> On Monday, September 11, 2023 at 8:13:45 PM UTC+2, Marcel Hendrix wrote:
> > On Monday, September 11, 2023 at 6:40:41 PM UTC+2, Ahmed MELAHI wrote:
> > [..]
> Sorry, I should have started by saying that this is a very interesting piece
> of work.
>
> -marcel
Hi,
Thanks,
I wrote this program a long ago, and when I saw this thread I wanted to share it with you all.
Here we can see that approximately one screen of code can program or create fuzzy systems.
I don't know if Mr. Bernd Paysan is interrested to add it to his one screen collection!!!
Concerning the overloading of the words " and, or, if,..." I've already eluded this by using french words like:
IF <--> SI,
THEN <--> ALORS
AND <--> ET
OR <--> OU
IS <--> EST
etc...

so that a fuzzy rule can be written like this:
r( SI x EST NB ET y EST NB ALORS z est NB)r
for example.
Concerning the speed: in gforth 0.9 ms and in iforth 0.63ms and 0.63 is less than 0.9 so iforth win.

Bye

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor