Wed Jun 26 13:51:09 UTC 2019
this
keyword referring to the current class object. This supports more for the object style. You can write like this:term TEMPERATURE(100, 200, 5) { fuzzy low = 100; fuzzy medium = 150; fuzzy high = 200; }; term SPEED(0, 100, 5) { TEMPERATURE temp; fuzzy low = 0; fuzzy medium = 50; fuzzy high = 100; void SetRules(int temp_input) { temp = temp_input; ZeroFuzz(this); rule temp.low => low; rule temp.medium => medium; rule temp.high => high; } int Defuzz() { return Defuzz(this); } }; SPEED speed; speed.SetRules(165); print speed.Defuzz();
Sun Jun 23 07:05:40 UTC 2019
=>
first, then inference. Previously, fuzzy logic operations were performed on the target fuzzy set on the right of the inference symbol =>
so the results were not close to the desired rules.term WIND(0, 100, 11) { fuzzy gale = 100; fuzzy strong = 60; fuzzy moderate = 40; fuzzy breeze = 20; fuzzy calm = 0; };
EXTREMELY
is equivalent to VERY VERY VERY
.SEEMED
is equivalent to LITTLE LITTLE LITTLE
.BIT
. This operation is often used to get a bit of information of a fuzzy set to union another fuzzy set. The result is a union fuzzy set.wind.calm := (1/0, 0.4/10, 0.04/20, 0.0006/30, 0.000002/40, 0/50)
wind.breeze := (0.04/0, 0.4/10, 1/20, 0.4/30, 0.04/40, 0/50)
LITTLE LITTLE wind.calm
is(1/0, 0.8/10, 0.45/20, 0.16/30, 0.04/40, 0/50)
BIT wind.breeze
is(0.02/0, 0.2/10, 0.5/20, 0.2/30, 0.02/40, 0/50)
LITTLE LITTLE wind.calm OR BIT wind.breeze
will be(1/0, 0.8/10, 0.5/20, 0.2/30, 0.04/40, 0/50)
Classify(fuzzy)
fuzzy
.Defuzz(fuzzy, bContinuous = false)
true
, fuzzy set fuzzy
is treated as a continuous fuzzy set with membership function whose graph is linear lines connecting the vertices of the elements of the fuzzy set.Sun Jun 16 00:28:29 UTC 2019
put wind := (0/0, 0.5/10, 1/i, 0.5/30, 0/40, 0/50, 0/60, 0/70, 0/80, 0/90, 0/100);
PutReading (wind, i);
PutReading (fuzzy, val, grade, rate, clear)
PutReading (wind, 42, 1, 0.5, true);
(0/0, 0/10, 0/20, 0.5/30, 1/40, 0.5/50, 0/60, 0/70, 0/80, 0/90, 0/100)
PutReading (wind, 105, 0.5, 0, false);
(0/0, 0/10, 0/20, 0.5/30, 1/40, 0.5/50, 0/60, 0/70, 0/80, 0/90, 0.5/100)
Number val = PutReading (wind, 105, 0.5, 0, false);
print val;
100
term WIND(11) {};
WIND wind;
print wind.size;
Fri Jun 14 07:25:13 UTC 2019
This version adds a way to pass information from the outside into a Fuzzy program via the command line argument, and return the result from the program via the exit code as an expression.
Suppose you have val1, val2, val3 values that want to read into a program named myfuzzy.c, run the following command:
fuzzy -r "val1 val2 val3" myfuzzy.c
Inside the myfuzzy.c program you can handle the pre-declared global variables system_reading_count and system_reading_array. system_reading_count is a variable of type int containing the number of values in the command line argument. system_reading_array is an array of type String containing values in the command line argument. So you can write like this:
int count = system_reading_count;
for (int i = 0; i < count; i ++)
print system_reading_array[i];
Program exit codes can be used as results returned from the program. Assume that the program file myfuzzy.c has the following content:
int score = 2;
exit (score);
Running Python will result:
Tip: For a portable binary version you compile as below at the src directory:
g++ -Wno-return-type -o fuzzy *.cc
Sun Sep 2 16:39:37 UTC 2018
Configuring and building:
./configure --prefix=/usr
make
Now, as the root user:
make install
GitHub: https://github.com/phamtyn/fuzzy
Mon Nov 14 00:26:23 UTC 2016
Fuzzy 1.3 released!
Fixed scope for user-defined type in the function (body) which be member of an array element
Tue Nov 8 10:06:03 UTC 2016
Fuzzy 1.2 released!
Fixed and extended overloading functions
Sat Nov 5 15:25:38 UTC 2016
Fuzzy 1.1 released!
Fixed statement return in loop and switch statements
Thu Nov 3 15:37:49 UTC 2016
FUZZY Programming Language
Fuzzy 1.0 released!
SYNOPSIS
fuzzy PROGRAM-FILE
fuzzy -h
DESCRIPTION
Fuzzy is an implementation of the FUZZY programming language. Fuzzy is designed to process linguistic variables and fuzzy sets with vague concepts such as HIGH, LOW, MEDIUM, VERY HIGH, NOT VERY LOW. Fuzzy reads the FUZZY program source from the file PROGRAM-FILE.
OPTIONS
-h Display the help and exit
TUTORIALS
Hello World program
FUZZY programs have no main function. The source codes of a simplest program may like this
print "Hello World";
Basic types
Basic types are int, Number, String, bool and fuzzy. Most of them can be assigned to another, for instance
int i = 100;
i += 50;
String text = i;
speed.high = i + 50; // speed.high is a fuzzy set
Control Statements
Control Statements while, for, if, else, break, continue, return are similar to C/C++. Statement switch can be used for String type
switch(text) // text is a String variable
{
case "abc":
// do something
break;
case "def":
// do something
break;
}
Override functions
Similar to C++, Fuzzy can be used to override functions and operators. operator= can be used with return type is void. Member variables can be initialized inside a struct
struct OBJECT
{
int m_i = 50;
String m_string = "abc";
Number m_array[10]; //an array of Number
void operator = (OBJECT t)
{
m_i = t.m_i;
m_string = t.m_string;
for(int i = 0; i < 10; i++)
m_array[i] = t.m_array[i];
}
OBJECT operator - ()
{
OBJECT obj;
obj.m_i = -m_i;
return obj;
}
};
fuzzy set and fuzzy term
Discrete fuzzy sets must be declared inside a discrete fuzzy term. The following example shows a fuzzy term with three fuzzy sets. Each one has five elements, each element is a pair grade/value
term TEMPERATURE(5)
{
fuzzy discrete low(1/100, 0.5/125, 0.25/150, 0.1/175, 0/200);
fuzzy discrete medium(0.25/100, 0.5/125, 1/150, 0.5/175, 0.25/200);
fuzzy discrete high(0/100, 0/125, 0.25/150, 0.75/175, 1/200);
};
Put data into a fuzzy term
Keyword put be used to set values and membership values for fuzzy terms
TEMPERATURE temperature;
put temperature := (0/100, 0/125, 0.5/150, 0.25/175, 0/200);
Apply fuzzy rules
rule temperature.medium AND pressure.medium OR weather.bad OR traffic.bad => speed.low;
rule VERY temperature.high AND pressure.low OR NOT VERY temperature.high AND pressure.medium AND NOT VERY traffic.bad => speed.high;
rule temperature.low AND pressure.high AND REALLY weather.normal OR traffic.normal => speed.medium;
rule (temperature.medium OR pressure.low) AND weather.good OR pressure.low AND traffic.good => speed.high;
rule REALLY temperature.medium AND LITTLE pressure.high AND VERY VERY weather.good => speed.high;
Print fuzzy sets and fuzzy terms
The following statement prints defuzzification value of a fuzzy term
print speed;
if you want to print its fuzzy data, you can use statement prints
prints speed;
Defuzzification
Defuzzification method be used is centroid method, function Defuzz returns defuzzification value of a fuzzy term
Number val = Defuzz(pressure);
Reset fuzzy sets and fuzzy terms
Function ZeroFuzz be used to reset all data of a fuzzy set or fuzzy term to zero
ZeroFuzz(temperature);
Transfer fuzzy data to array
There is a built-in struct named FuzzyPair. To transfer fuzzy data to array, you declare an array of FuzzyPair whose size is sufficient to store data, then use function FuzzyToArray like this
FuzzyPair array[8];
FuzzyToArray(speed, array);
The struct FuzzyPair has two members, they are m_grade and m_value
for(int i = 0; i < 8; i++)
print array[i].m_grade, " ", array[i].m_value;
Continuous fuzzy
This type of fuzzy be applied for fuzzy sets which have a declared domain and a center value. The membership function be used is Gaussian function
term TEMPERATURE(100, 200)
{
fuzzy low = 100;
fuzzy medium = 150;
fuzzy high = 200;
};
Print to file
Token > be used to redirect output to file for print and prints
print speed > "filename.txt";
Token >> be used to redirect for print and prints, append output to the file
prints speed >> "filename.txt";
Execute a shell command
Execute a shell command with keyword system
String command_text = "sudo makeca -f";
system command_text;
Math functions
Built-in functions of math are sin, cos, tan, atan, ln, log10, exp, pow, sqrt, floor, round, abs, min, and max
Include file
Include file is similar to C/C++
#include "filename.h"
Comment
Comment is similar to C/C++, used with token // or pair /* and */
Contact: tuyen@omarine.org