Newsgroups: comp.ai.fuzzy
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!news.mathworks.com!newshost.marcam.com!zip.eecs.umich.edu!caen!msunews!harbinger.cc.monash.edu.au!lugb!news
From: RK@gateway.atd.cra.com.au ()
Subject: Re: C++ fuzzy library?
Sender: news@lugb.latrobe.edu.au (News System)
Message-ID: <1995Feb8.011504.2071@lugb.latrobe.edu.au>
In-Reply-To: gl1@ix.netcom.com's message of 6 Feb 1995 11:49:46 GMT
Date: Wed, 8 Feb 1995 01:15:04 GMT
References:  <3h52cq$213@ixnews1.ix.netcom.com>
X-News-Reader: VMS NEWS v1.25
Organization: CRA Advanced Technical Development
Lines: 502

In <3h52cq$213@ixnews1.ix.netcom.com> gl1@ix.netcom.com writes:

> I have not yet found a FAQ. Anyone know of a C++ library for fuzzy 
> logic? Thanks in advance,
> 
> Gene Levinson


--------------------------
Dear Gene,

Here are some references to the  c++ fuzzy class libraries available through
ftp. 
I hope it's useful.

Regards

Richard

---------------------------------------------------------------------------------------
Richard Kowalczyk (Ph.D)
Knowledge-Based Systems
CRA ATD (Perth)
PO Box 347, Cannington, WA 6107
Australia
rk@perth.atd.cra.com.au
----------------------------------------------------------------------------------------
....
	I made a little package of my current files for the fuzzy arithmetic
library and I made it available by anonymous ftp from 
 
	mathct.dipmat.unict.it		(151.97.252.1)
	
into the directory fuzzy with names fznum.zip (msdos zip), fznum.taz
(unix tar and compress) and fznum.tgz (unix tar and gzip).
The package contains also the paper we wrote about this work.
 
	I hope you will find it usefull for your applications. Read the file
readme.txt for the copying an using conditions and let me know any problem
and comment about the package and fuzzy arithmetic in general.
 
	I am very interested into applications of fuzzy arithmetic, so
let me know what you are working on and how fuzzy arithmetic
will help you.
 
Ciao
Salvo
 
 
[-----------------------------------------------------------------------]
|	Salvatore Deodato						|
|	Dipartimento di Matematica					|
|	Viale Andrea Doria, 6						|
|	I-95125 Catania (Italy)						|
|	e-mail: deodato@dipmat.unict.it					|
[-----------------------------------------------------------------------]
 
-----------------------------------------------------------------------------------------------------------------------------
RFC-822-Headers:
Errors-To: fuzzy-owner@vexpert.dbai.tuwien.ac.at
Originator: fuzzy-mail@vexpert.dbai.tuwien.ac.at
Precedence: bulk
X-Listserver-Version: 6.0 -- UNIX ListServer by Anastasios Kotsikonas
X-Comment: Fuzzy Distribution List

-------

I have put on

	eroica.cs.utah.edu:pub/fuzzy.sh

a copy of the fuzzy c++ classes I have been developing.  They attempt
to follow the sorts of FAM-style structures found in Bart Kosko's
Neural Networks and Fuzzy Systems book.

The software compiles and seems to twitch the way I expect when I poke
it.  Beyond that, I won't make much in the way of guarantees, since
this very much is a learning experience for me.

The fuzzy variables use int's, floats, or bytes to represent values.
I'll probably do a mapped membership class so you can use array access
to do associative lookup of membership values, soon.  I might have
gone a little overboard with c++ templates.  Generality, like
abstinence, should be pursued cautiously and with moderation.

The FAM's don't yet adapt.  Once I understand what it will take to
make them adapt, they'll adapt and their structure may change.

Please send me mail if you have comments or suggestions.

	-Doug

p.s.  From the README:


This software is under development.  It is provided for comments and
suggestions.  No claims are made with respect to its completelness or
correctness.  Please send comments to: dbo@cs.utah.edu.

===

This directory contains sources for C++ classes used in defining fuzzy
variables.  Common manipulations of fuzzy variables are performed by the
"degree" and "membership" classes.  Arbitrary nonlinear membership
functions, as well as membership functions based on triangular piewise
membership are supported.

To define a fuzzy variable, invoke the "fuzzy" template with the
desired type:

fuzzy<int> height;

Triangular membership functions are defined using the "tri_member"
template.  x values may be any permissible value for the template
type.  The triangular membership constructor takes 3 x coordinates,
followed by the height (typically 1.0) to describe the membership
shape.

tri_member<int> TALL (48, 72, 96, 1);
tri_member<int> SHORT (48, 56, 96, 1);

Trapezoidal membership functions (including trapezoids which are
missing one of their triangular sides) may be defined using the
"trap_member" template.  The trapezoidal membership function takes 4 x
coordinates and a height to describe the membership shape.  The x
coordinates are as follows:

         x2   x3
         ******
	********
       **********
      *************
     ****************
     x1		    x4

For example:

trap_member<float> HIGH_TEMP (92.0, 103.0, 106.333, 106.33, 1.0);

defines the partial trapezoid (with height 1.0):

        103   106.66
         ******
	*******
       ********
      *********
     **********
    93	      106.66



Now, simple membership tests may be performed using the "is" operation
and boolean functions.  e.g.,

	height.is (TALL)
	!height.is (TALL) && temperature.is (HIGH_TEMP)

The result of these operations is a "degree" which is a scaled integer
whose values range [0,255] and represents real values [0,1] (degrees
of membership in the class).

Collections of membership functions may be grouped in fuzzy
associative memories (FAM's).  A fam is an NxN matrix of membership
functions.  Each dimension represents an input function to be applied
to an input variable.  The intersection represents the logical (fuzzy)
AND of the two resulting output sets.  The degree to which the AND
succeeds determines the degree to which the output membership function
applies to the output variable.

To define a FAM, one must first define the related membership
functions:

trap_member<int> NM (-128, -128, -64, -32, 1, "NM");
tri_member<int> NS (-64, -32,  0,  1, "NS");
tri_member<int> Z  (-32,   0,  32, 1, "Z");
tri_member<int> PS (  0,  32,  64, 1, "PS");
trap_member<int> PM ( 32,  64, 127, 127, 1, "PM");

The fam is defined with, a) its dimension, b) a row
representing the input membership functions (containing the addresses
of the relevant membership functions), and c) NxN rows of the
resulting output functions.


fam<int> pendemo(5,
	 &NM,	&NS,	&Z,	&PS,	&PM,

	 NULL,	NULL,	&PM,	NULL,	NULL,
	 NULL,	NULL,	&PS,	&NS,	NULL,
	 &PM,	&PS,	&Z,	&NS,	&NM,
	 NULL,	&PS,	&NS,	NULL,	NULL,
	 NULL,	NULL,	&NM,	NULL,	NULL
);


To apply a fam to two input variables and produce a third, the "apply"
method is used:

	fuzzy<int> theta (20, "theta");
	fuzzy<int> dTheta (-10, "dTheta");
	fuzzy<int> result (0, "result");


	pendemo.apply (theta, dTheta, result);

===

Early work on 3D fam surfaces is shown.  It compiles but hasn't been
tested.  FAM's don't yet learn/adapt.  They will soon, I hope.

Again, this software is in a preliminary form.  Please use with care.

	Douglas Orr
	Center for Software Science
	University of Utah
	dbo@cs.utah.edu

-------------------------------------------------------------------------------------------------------------------------
RFC-822-Headers:
Errors-To: fuzzy-owner@vexpert.dbai.tuwien.ac.at
Originator: fuzzy-mail@vexpert.dbai.tuwien.ac.at
Precedence: bulk
X-Listserver-Version: 6.0 -- UNIX ListServer by Anastasios Kotsikonas
X-Comment: Fuzzy Distribution List

-------
     Here's my English-language documentation for the Japanese
fuzzy reasoning library.  

					John Nagle
					(visiting scholar, Stanford robotics)


HOW TO GET THE LIBRARY

The "General Purpose Fuzzy Reasoning Library" is available via anonymous FTP
from 

	Server: utsun.s.u-tokyo.ac.jp	 [133.11.11.11]
	
	File:	fj/fj.sources/v25/2577.Z
	
	This yields the "General-Purpose Fuzzy Inference Library Ver. 
3.0 (1/1)".  Use "uncompress" to decompress it, then "uudecode" to
convert it from text to a binary file, then "uncompress" again, and
finally "tar" to unpack the resulting file.

The program is in C, with English comments, but the documentation is in 
Japanese.

----- 
THE ORIGINAL "README" FILE, translated to English.

(Translation by Michiaki Nakayama at the Stanford Computer Systems Laboratory)

General Purpose Fuzzy Reasoning Library Ver.3.0

     (c) 1991 Kohichi Numata
	 
	If you use "rule read-in" functions of the general purpose fuzzy 
reasoning library, it reads fuzzy reasoning information from a certain format 
file (rule file) and returns that to a structure. Therefore, only editing the 
rule file enables you try and error.
	Reasoning functions of this library return the reasoned value of the 
output variables when you input an array of every input variable and a 
structure, which was mentioned before, as parameters. So, it makes fuzzy 
reasoning operation blackbox-like. 		
	This library includes some sped-up operations in which inner 
operations are done with integers. I intended to write it according to ANSI 
standard; most compilers might be able to compile this library.
	Programming of fuzzy reasoning is quite troublesome, if you would do 
it from the beginning. I would be happy if this library reduces your effort. 
This has nothing to do with those people who has nothing to do with fuzzy 
reasoning, but I'd like to recommend to touch it before it disappears(??).
		
		
		University of Electric and communications   	Kohichi Numata
		numata@qr.cas.uec.ac.jp	 
		
-----
Documentation for the program obtained by analyzing the code.
(by John Nagle, Stanford CSL)

SUMMARY

     This is a simple implementation of standard fuzzy inference, implemented
as a C function library. It reads fuzzy rules from a text file, and initializes
a data structure based on that file, after which a function can be called 
with a set of values from which a single output value, inferred according 
to the rules, will be generated.  No "adaptive" or "learning" capability is 
provided.
The implementation is straightforward, and does not use known optimizations of
the algorithm.  The code is well-written and easy to follow, with comments and
variable names in English, even though the original documentation is in
Japanese.

FORMAT OF THE RULE FILE

The rule file is divided into three sections.

The first section defines the variables. There can be up to MAX_N_IN_VAR (a
constant in "infer3.h") input variables, and there is exactly one output 
variable, which must be the last variable defined.

For each variable, there is a line of the form

	varname	lowbound highbound
	
which defines the range of the input or output variable.  For input variables,
this range is used only by the integer version of the package, which scales
input variables into the range 0..255 based on these bounds.  For output
variables, this value will be used in conjunction with the "NEP" value set
below to divide the output range into N equal parts.  So variable ranges should
be as narrow as possible to cover the expected values of the variables.  Overly
large ranges will reduce output resolution.
 	
The range line is followed by a block of fuzzy value name definitions of the
form

	valuename	a b c d
	
The trapezoid defined by a,b,c,d determines the translation from the input
numeric value to the fuzzy value named "valuename".
The values a,b,c,d define a trapezoid, in the usual fuzzy rule sense, as shown
below.

       o         ________
       u        /        \
       t       /          \
           ___/            \___
       in     A  B       C  D


Each block of fuzzy value name definitions is terminated by a blank line. 
There 
must be at least one fuzzy value name line; it may be be preceded by blank
lines.

The second section of the file defines the rules, and begins with a line of the
form

	SW	varname varname varname ...
	
	for which the "varname" names must be the ones defined above, in the
same order.
This line forms the header for the rule table to follow.

Rules are of the form

	ON	var1valuename var2valuename var3valuename...

or 
    OFF var1valuename var2valuename var3valuename...

and a blank line ends the rule section.  Only lines beginning with "ON" are
actually used.  A "valuename" of "IG" indicates that the input for that
column is to be ignored.

The third and last section is one line of the form

	NEP	nnn
	
which defines the "number of equal parts" used for the brute-force integration
to find the centroid of the output fuzzy result.  The range specified for the
output variable is divided into this number of equal parts. Thus, the specified
output range and the number of equal parts sets an upper limit on the precision
of the output.


AN ANNOTATED SAMPLE RULE FILE

A sample rule file is provided with the program, and it is reproduced here
with comments.  Unfortunately, comments in rule files are not supported by the
program, so this text with comments is not a valid rule file in this form. 

SL		-100	1400					Defines input
variable SL, range -100..1400
										
Optional blank line
S		-1e38	-1e38	600	800			Fuzzy value S
for variable SL
L		600	800	1e38	1e38			Fuzzy value L
for variable SL
										
Required blank line ends variable block

D		-800	800						Defines
input variable D, range -800..800

N1		-1e38	-1e38	-800	400		Fuzzy value N1
P1		-400	800	1e38	1e38		Fuzzy value P1
										
Required blank line

BL		-3	3							
Defines the output variable BL, range -3..3

N2		-3	-1	-1	1					
Fuzzy value N2
P2		-1	1	1	3					
Fuzzy value P2
Z2		-2	0	0	2					
Fuzzy value Z2
										
Required blank line

SW		SL	D		BL					
Rule header line
										
Optional blank line
ON		S	N1		Z2					
Rule: S and N1 implies Z2
ON		L	P1		Z2					
Rule: L and P1 implies Z2
ON		L	N1		N2					
Rule: L and N1 implies N2
ON		S	P1		P2					
Rule: S and P1 implies P2.
										
Required blank line.

NEP		256								
Number of equal parts for integration.

----
CALLING THE FUNCTIONS

Usage is very simple. There are two sets of functions, one which does all 
calculations in floating point and one which does the time-consuming
calculations
in integer arithmetic.  The latter functions begin with "u", but take the
same arguments and return the same results as the floating point forms.

ReadRule reads in a rule file, as defined above.  It initializes and
fills in the FUZZ_INFO structure. ReadRule returns one of the following values

	RR_OK					0		Rules read
successfully
	RR_OVER_MAX				(-1)	Table sizes in infer3.h
overflowed.
	RR_SHORT_FILE			(-2)	EOF before rule file complete
	RR_SHORT_LINE			(-3)	End of line before rule line
complete
	RR_UNDEFINED_KEYWORD	(-4)	Unknown keyword where keyword required
	RR_UNDEFINED_SYMBOL		(-5)	Undefined variable name where
required


Infer does one fuzzy inference.  It takes an array of floating point values,
one for each input variable, and returns a single floating-point result.

uReadRule and uInfer operate similarly, but use mostly integer computations.

/*
	Exported functions  -- floating point version
*/
extern int ReadRule(FILE *fp, FUZZ_INFO *fzf);
extern float Infer(const float InVar[], const FUZZ_INFO *fzf);
/*
	Exported functions  --  integer version
*/
extern int uReadRule(FILE *fp, uFUZZ_INFO *fzf);
extern float uInfer(const float InVar[], const uFUZZ_INFO *fzf);

PERFORMANCE

	Performance is not especially fast, primarily because of the
brute-force
approach to finding the centroid of the summed result.  The algorithm is a
naive implementation of the classic fuzzy logic inference technique.

----------------------------------------------------------------------------------------------------------------------------

RFC-822-Headers:
Comments: Warning -- original Sender: tag was          
fuzzy-mail@VEXPERT.DBAI.TUWIEN.AC.AT
X-To: nafips-l@gsuvm1.bitnet

-------
Hi,
I'll put the source code on our anonymous ftp ( borneo.gmd.de) in the
directory pub/misc, file fuzzy_class.tar.Z, on Monday 6.09. If you have
problems reaching the server try it one day later again ( the server
will be shutdown over the weekend  due to major repairs and I hope it
comes up on Monday).

For those, who have asked about controlling problems solved with the
modules: an example  was presented in San Francisco ( IEEE-FUZZ93)
" Adaptive Fuzzy Controller Improves Comfort", pp. 515-517.
 Best regards,
--
-----------------------------------------------------------------
      Liliane E. Peters             e-mail: peters@gmd.de
          GMD-SET
        P.O.Box 1316                   phone:  (+49) 2241 14 2332
D-53731 St. Augustin 1, Germany        fax:    (+49) 2241 14 2342
-----------------------------------------------------------------





