Fuzzy Calculator – Useful Tool for Programming with Fuzzy Algebra Roman Kole´snik1, Piotr Prokopowicz2, and Witold Kosi´ nski1 1
2
Polish-Japanese Institute of Information Technology ul. Koszykowa 86 ,02008 Warszawa, Poland
[email protected],
[email protected] University of Bydgoszcz Institute of Environmental Mechanics and Applied Computer Science ul. Chodkiewicza 30, 85064 Bydgoszcz, Poland
[email protected]
Abstract. Process of implementing operations’algorithms for ordered fuzzy numbers (OFN’s)are presented. First version of the program in the Delphi environment is created that uses algorithms dedicated to trapezoidal-type membership relations (functions). More useful implementation is a Fuzzy Calculator which allows counting with OFN’s of general type membership relations and is equipped with a graphical shell.
1
Introduction
Few years ago the present authors (W.K., P.P.) founded an extended model of fuzzy numbers and algebraic operations on them where real numbers with their operations are a part of the model [10]- [12]. One of the aims was to get results of algebraic operations on real numbers equal to results of the same operations but performed in the standard algebra of reals. The next aim was to have the operations’ algorithms as simple as possible to be able to implement the algorithms in some programmers’ environment. The new model of fuzzy numbers,called ordered fuzzy numbers (OFN’s),already presented in [10],[11],[12],[13], has the following properties: subtracting is a consequent of adding opposite number so A − B = A + (−B) where (−1) · B = −B, result of many operations on fuzzy number must not always be “more fuzzy”, A−A = 0 – crisp zero, so it is neutral element of addition, operations are enough simply to program without very complicated methods. As a consequent the new model has extra properties: it is a linear space and even more, Banach algebra with unity. It should be added at this stage that in the literature a number of different models of fuzzy numbers and their generalization exist ( [2–4, 6–8]). Moreover, the particular case of the known set of the so-called convex fuzzy numbers can be obtained as a particular subset of our space of ordered fuzzy numbers; for the members of this set the arithmetic operations are compatible, to some extent, with the interval arithmetics.
2
Roman Kole´snik, Piotr Prokopowicz, and Witold Kosi´ nski
The idea of the ordered fuzzy numbers is quite original and the present authors have planned to implement it as a new project without using existing popular tools for fuzzy logic (numbers) calculation like MATLab, for example.
2
Ordered Fuzzy Numbers
Definition 1. By an ordered fuzzy number A we mean an ordered pair of function A = (f, g) (1) where elements of the pair are continuous functions f, g : [0, 1] → R.
Fig. 1. a) The example of ordered fuzzy number, b) Ordered fuzzy number presented as fuzzy number in classical meaning, c) Simplified mark denotes the order of inverted functions
We call the corresponding elements: f – an up-part and g – the down-part of the fuzzy number A. The continuity of both parts implies their images are bounded intervals, say U P and DOW N , respectively (Fig. 1a). Let us use sym− bols to mark boundaries for U P = (lA , 1+ A ) and for DOW N = (1A , pA ). In general neither of both functions needs to be invertible, only continuity is required. However, if both functions (parts of ordered fuzzy number) are monotonic then they are invertible and possess corresponding inverse functions defined on R with values in [0, 1]. The inverse functions are defined on the bounded intervals U P and DOW N , respectively. Now, if we add a function on the interval − [1+ A , 1A ] with constant value equal to 1, we may define a kind of membership function (sometimes it is a relation) of a fuzzy sets on real axis (Fig. 1b). Notice that in the above case when f ≤ g and both invertible functions are such that
Fuzzy Calculator - Useful Tool for Programming
3
f is increasing and g is decreasing we get a mathematical object which presents a convex fuzzy numbers in the classical sense [6–8]. We can appoint here an extra feature, named an orientation (marked in graphs by arrow - Fig 1c), to underline the fact that we are dealing with an ordered pair of functions, since in general the pairs (f, g) and (g, f ) represent two different − OFN’s. In consequence the intervals U P ∪ [1+ A , 1A ] ∪ DOW N form the support of the fuzzy number A. Let A = (fA , gA ), B = (fB , gB ) and C = (fC , gC ) are mathematical objects called ordered fuzzy numbers. Definition 2. The sum C = A + B, the product C = A · B and the division C = A/B are defined by fA (y) + fB (y) = fC (y) ∧ gA (y) + gB (y) = gC (y).
(2)
fA (y) · fB (y) = fC (y) ∧ gA (y) · gB (y) = gC (y),
(3)
fA (y)/fB (y) = fC (y) ∧ gA (y)/gB (y) = gC (y),
(4)
where A/B is defined iff zero does not belong to intervals UP and DOWN of B. Notice that the subtraction of B is the same o as the addition of the opposite of B, i.e. the number (−1) · B. Moreover, if for A = (f, g) we define its complementaryA¯ = (−g, −f ) then the sum A + A¯ gives in general a fuzzy zero 0 = (f − g, −(f − g)). It is the complementary of the given fuzzy number which plays the role of the opposite number, in the Zadeh sense in the classical fuzzy number calculus.
3
Fuzzy Calculator
First application was “nowaalgebra” (ang. newalgebra), created with use of Delphi environment for programming. That program has been evolving with the development of new ideas in modelling fuzzy numbers: it has changed from arithmetic operations on selected elements from equivalence classes [5] to all operations on inverted functions, i.e. on ordered fuzzy numbers. The main purpose for that program was the graphical presentation of the operations’ algorithm while dealing with a working model of fuzzy numbers. The main limitations of that first application of the program was its validity for functions with piecewise linear parts (quasi-trapezoidal representations), only. The application was used to present our ideas on some conferences which are listed in Bibliography. It was obvious that one needs a new program, more useful in examining and using ideas of the new look of fuzzy numbers. In consequence “Fuzzy Calculator” (worked name zCalc) has been created with a graphical shell named zWinCalc (the author R.K.). To create the main zCalc program the following components were used: Visual Studio 6.0 - environment for programming in language C++, Bison-Flex generator of language - useful tool to build syntax analyzer.
4
Roman Kole´snik, Piotr Prokopowicz, and Witold Kosi´ nski
The tool zCalc was written as a component of operating system – Windows (9x/XP). To this a console interface which allows to use the main module as a kind of the interpreter of a specifical simply language is added. It has instructions which can declare mathematical objects (cf. Sec.2 ) and basic operations on them. The language gives a possibility to work with scripts which are text files with lists of proper commands. Other important feature is a group of instructions which allow to export results to the file formats with text and graphic (i.e. formats of XML, ps, svg). That files can be read by other applications. One can use an extra group of commands to prepare proper parameters of graphs, and then to adapt some part of the results to individual wishes. The Fuzzy Calculator was created to let an easy use in future open projects all mathematical objects described as ordered fuzzy numbers. The basic functional field of module zCalc are: algebraic operations (sum, subtract, multiplication and division) with ordered fuzzy numbers identified by a set of special (with view to figure of functions) points, algebraic operations with the ordered fuzzy numbers identified and marked as some polynomial functions, exchanging both representations: set of points and polynomials. Author has given the user a possibility of two kinds descriptions of component functions (parts up and down). The first is by giving formula, the other by a list of characteristic points. Functions for use can have forms of polynomials: simply linear functions as well as functions with complicated graphs with many parameters. In the case of piecewise linear functions they can be defined by a list of the characteristic points. Then the list of points is transformed into a piecewise linear functions. In a more general (curved–shape functions) case the list is transformed into a polynomial representation. To make this transform the Lagrange interpolation is used. Independently of the used interpolation (linear or curved), one should also have a possibility to transform any polynomial form to a list of points. Moreover, actual calculations is made on the functional representation of both parts of the ordered fuzzy number. The transformation of polynomial object A = (fA , gA ) is realized by using the following algorithm: 1. determine (graphs of) two simply linear functions, such that first connects two points (lA , 0) and (1+ A , 1) (this is for the part fA ), and the second which connects two points (1− , A 1) and (pA , 0) ( for the part gA ); 2. for each point of graphs of functions fA , gA determine (with 0.01 step) its distance to the linear functions founded in step 1; 3. choose point which is most distanced to the functions from step 1; 4. the last chosen point is added to the list (of characteristic points) if it is true that the distance between the curve (at this point) and the linear function is not smaller that a given threshold (or 0.2, if the threshold was not fixed by the user); 5. repeating steps 1,2,3 and 4. but in steps 1 exchange one of limiting points on the list with that added to the list founded in steps 4. The algorithm ends if all segments, which are created by each pair of the neighbor points, are analyzed and no new point is founded. We can see that the precision of
Fuzzy Calculator - Useful Tool for Programming
5
describing the functions can be controlled by the threshold parameter (in step 2). Although the list of points is simply and gives the description of the function, we can also adapt the precision by an appropriate choice of the threshold parameter. The Fuzzy Calculator has graphical shell – worked name zWinCalc. It is windows’type interface which makes easy and direct calculation with the module zCalc. Programmer which will use the main module as component in further works does not need zWinCalc. So this program will be used generally by people who need to make calculations on fuzzy numbers directly on Fuzzy Calculator and/or will write scripts and watch results as graphs. Application zWinCalc makes easier: editing commands, watching objects which have been already defined, watching and editing properties of defined objects, carrying properties of objects to other tools (in text form), watching figures of objects as graphs (installation of free plug-in Adobe’s SVG is necessary). The module zWinCalc is only a graphical shell and no algorithms of operations on any presentations of the fuzzy numbers are implemented here. Proper module which makes all calculations, definitions and transforms is zCalc. Integration of the program zWinCalc with zCalc gives a chance to use the graphical shell without any changes even a new version of the main module appear. To work only with the console interface (zCalc), no any other program in the system is necessary, but if one plans to use a graphical support in the form of zWinCalc then it is necessary to install the list of the programs: MSXML2 in version 4.0, SVG viewer, MathPlayer and optional GhostView. Figures Fig 2. and Fig 3. present graphs generated by program zCalc and consist of the example results of the algebraic operations on the ordered fuzzy numbers A and B described by the lists of points: A = (2, 3, 3.5, 4) (blue colour) and B = (0.5, 1, 2, 3) (green colour). The actual order (orientation) on the graph is matched by a small rectangular, which has the meaning of the initial point of the list.
4
Conclusions
Thanks to the opened structure of the Fuzzy Calculator it is a very useful tool in future studies of the ordered fuzzy numbers (and fuzzy numbers, as well). Main practical advantage of the Fuzzy Calculator is that the operations can be used by programmers in different programming environments. This allows the use of the algebra of OFN’s in different programs, as a ready module, and then the implementation of all needed operations is possible.We are planning as a next step of our investigation of OFN’s to use the Fuzzy Calculator for a fuzzy controller.
References 1. Dubois D., Prade H., (1978) , Operations on fuzzy numbers, Int. J. System Science, 9, 576-578. 2. Czogala E., Pedrycz W., (1985), Elements and methods of fuzzy set theory (in Polish), (Elementy i metody teorii zbior´ ow rozmytych) PWN, Warszawa.
6
Roman Kole´snik, Piotr Prokopowicz, and Witold Kosi´ nski
Fig. 2. Fig. a) Sum C = A + B, b) Division C = A/B
3. Nguyen H.T., (1978), A note on the extension principle for fuzzy sets, J. Math. Anal. Appl. 64, 369-380. 4. Sanchez E., (1984), Solutions of fuzzy equations with extended operations, Fuzzy Sets and Systems, 12, 237-248. 5. Goetschel R. Jr., Voxman W., (1986), Elementary fuzzy calculus, Fuzzy Sets and Systems, 18, 31-43. 6. Klir G.J., (1997) , Fuzzy arithmetic with requisite constraints, Fuzzy Sets and Systems, 91, 165-175. 7. Drewniak J., (2001), Fuzzy numbers (in Polish), in: Zbiory rozmyte i ich zastosowania, Fuzzy sets and their applications, J. Chojcan, J. L¸eski (eds.), Wydawnictwo ´ askiej, Gliwice, pp. 103-129. Politechniki Sl¸ 8. Wagenknecht M., (2001), On the approximate treatment of fuzzy arithmetics by inclusion, linear regression and information content estimation, in: Zbiory rozmyte i ich zastosowania, Fuzzy sets and their applications, J. Chojcan, J. L¸eski (eds.), ´ askiej, Gliwice, 291-310. Wydawnictwo Politechniki Sl¸ 9. Kosi´ nski W., Piech´ or K., Prokopowicz P., Tyburek K., On algorithmic approach to operations on fuzzy reals, in: Methods of Artificial Intelligence in Mechanics and Mechanical Engineering, Gliwice, October, 2001, T. Burczy´ nski and W. Cholewa (Eds.), PACM, Gliwice, 2001, pp. 95-98. ´ ezak D.: Fuzzy numbers with algebraic opera10. Kosi´ nski W., P. Prokopowicz P., Sl tions: algorithmic approach, in: Intelligent Information Systems 2002, M. Klopotek, S.T. Wierzcho´ n, M. Michalewicz(eds.) Proc.IIS’2002, Sopot, June 3-6, 2002, Poland, Physica Verlag, 2002, pp. 311-320. ´ ezak D.: Drawback of fuzzy arthmetics - new intu11. Kosi´ nski W., Prokopowicz P., Sl tions and propositions, in: Proc. Methods of Aritificial Intelligence, T. Burczy´ nski, W. Cholewa, W. Moczulski(eds), PACM,Gliwice, Poland (2002), pp. 231-237. ´ ezak D.: On algebraic operations on fuzzy 12. Kosi´ nski W., P. Prokopowicz P., Sl numbers,in Intelligent Information Processing and Web Mining, Proc. of the International IIS: IIPWM,03 Conference held in Zakopane, Poland, June 2-5,2003, M. Klopotek, S.T. Wierzcho´ n, K. Trojanowski(eds.), Physica Verlag, 2003, pp. 353-362. ´ ezak D.: Ordered fuzzy number, Bulletin of the 13. Kosi´ nski W., P. Prokopowicz P., Sl Polish Academy of Sciences, Ser. Sci. Math., 51 (3), 2003, 327-338. 14. Kosi´ nski W., Kole´snik R., Prokopowicz P., Frischmuth K.: On Algebra of Ordered Fuzzy Numbers, in: Proc. Warsaw, International Seminar on Soft Computing WISSC 2003, in print.